我正在嘗試使用這條路線
/**
*@Route("/random/string/{length<\d>?5}", name="string")
*/
public function getString(Request $request, $length)
{
$string = "";
for ($i=0; $i < $lenght; $i ) {
$string .= chr(random_int(65, 90)); // adds a random char to the string
}
str_shuffle( $string );
return new Response("Random string : $string");
}
我已經匯入了這個
use Symfony\Component\Routing\Annotation\Route;
我跑了
composer require annotations
當我運行除錯路由器或嘗試遵循此路線時,我收到錯誤訊息:
[嚴重] 未捕獲的錯誤:語法錯誤,意外識別符號“”,需要“函式”或“常量”
uj5u.com熱心網友回復:
這是正確的格式。如果仍然無法正常作業,那么我認為語法錯誤出現在您的類檔案中的 import 陳述句中。
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/random/string/{length<\d >?5}", name="string")
*/
public function getString(int $length, Request $request)
{
$string = "";
for ($i=0; $i < $lenght; $i ) {
$string .= chr(random_int(65, 90)); // adds a random char to the string
}
str_shuffle( $string );
return new Response("Random string :". $string);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/488266.html
