php - 如何运行 symfony 项目

标签 php symfony

我是 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/

相关文章:

php - 是否有将字符串转换为小写的 MySQL 命令?

php - 如何在 PHP 中获取服务器的当前上传速率?

php - 使用 PHP 创建数据库/用户/权限,但用于 Plesk 上的域

mysql - 只为一个 Bundle 创建的 Doctrine Schema

php - 创建资源 : [message] fopen(): Unable to find the wrapper "https" on Ubuntu using Symfony 时出错

php - 是否有任何 Celeryd 或 Celery (for Django/Python) type altenative for Symfony 2 framework

android - 谷歌/apiclient : Signature Verification Failed

php - 单击后如何停用按钮

php - SQL 代码执行 : Trending topics equals a twitter

php - Symfony2 - 学说 :schema:update fails with entity outside of a bundle ( decoupled )