我是 symfony 框架的初学者,我想运行我的函数
在 BlogController 中创建
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class BlogController extends Controller
{
/**
* @Route("/blog")
*/
public function showAction()
{
echo "hello friend";
}
}
?>
C:\xampp\htdocs\mysymfony\src\AppBundle\Controller
mysymfony 是项目名称。
这是我的routing.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
当我点击 URL 时:-
<强> http://localhost/mysymfony/blog
我收到此错误
**
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
**
我不知道如何构造 URL 来运行 BLOG 功能。请解决此问题
最佳答案
这很可能是因为您在根目录中运行您的网址。
使用您的 Controller ,您需要运行http://localhost/mysymfony/web/app_dev.php/blog
作为开发环境或http://localhost/mysymfony/web/app.php/blog
用于生产环境。
或者将您的 Apache 配置为直接运行到 web/
。您可以找到该指南 here .
关于php - 如何运行 symfony 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38157514/