app / config / routing.yml的内容:
horse_route:
path: /horse
defaults: { _controller: AppBundle:Horse:show }
app:
resource: "@AppBundle/Controller/"
type: annotation
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);
}
}
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.');
}
}
当我在浏览器中键入localhost:8000 / walrus / red时,收到错误消息
Unable to generate a URL for the named route "/horse" as such route does not exist.
似乎我没有在主路由文件中正确声明路由,或者我在错误的地方声明了它.任何帮助赞赏.
解决方法:
您的路线名为horse_route,因此您需要使用
return $this->redirectToRoute('horse_route', array(), 301);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。