以下是相关文件的内容:
内容app/config/routing.yml:
horse_route:
path: /horse
defaults: { _controller: AppBundle:Horse:show }
app:
resource: "@AppBundle/Controller/"
type: annotation
Run Code Online (Sandbox Code Playgroud)
内容src/AppBundle/Controller/WalrusController.php:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class WalrusController extends Controller
{
/**
* @Route("/walrus/red")
*/
public function walrusRedirect()
{
return $this->redirectToRoute('/horse', array(), 301);
}
}
Run Code Online (Sandbox Code Playgroud)
内容src/AppBundle/Controller/HorseController.php:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class HorseController extends Controller
{
public function showAction()
{
return new Response('This is a horse.');
}
}
Run Code Online (Sandbox Code Playgroud)
当我localhost:8000/walrus/red在浏览器中输入时,我收到错误消息
Unable to generate a URL for the named route "/horse" as such route does not exist.
Run Code Online (Sandbox Code Playgroud)
似乎我没有在主路由文件中正确声明路由,或者我在错误的地方声明了它。任何帮助表示赞赏。
您的路线已被调用,horse_route因此您需要使用
return $this->redirectToRoute('horse_route', array(), 301);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7416 次 |
| 最近记录: |