小编use*_*960的帖子

尝试在类(Symfony)上调​​用方法"getDoctrine"

我正在尝试使用symfony/doctrine创建一个小应用程序来读取表中的记录.我的步骤:

  1. 创建控制器(GS\OrderBunndle\Controller\CustomerCuntroller.php),路由.测试网址 - 它正在运行;
  2. 使用列和getter/setter为customer表(GS\OrderBundle\Entity\Customer.php)创建实体;

3)创建了GS\OrderBundle\Entity\CustomerRepository.php(我不知道为什么我还需要它,它是自动生成的).源代码:

namespace GS\OrderBundle\Entity;

use Doctrine\ORM\EntityRepository;

class CustomerRepository extends EntityRepository
{
}
Run Code Online (Sandbox Code Playgroud)

4)修改了CustomerController.php:

<?php

namespace GS\OrderBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use GS\OrderBundle\Entity\Customer;
use Doctrine\ORM\EntityManager; 

class CustomerController 
{

    public function indexAction($id)
    {
            $customer = $this->getDoctrine()->getRepository('GSOrderBundle:Customer')->find($id);
               return new Response(
            '<html><body>Number: '.$id.'</body></html>'
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

尝试在类"GS\OrderBundle\Controller\CustomerController"上调用方法"getDoctrine".

500内部服务器错误 - UndefinedMethodException

堆栈跟踪

在第13行的src/GS/OrderBundle/Controller/CustomerController.php中 - 公共函数indexAction($ id){$ customer = $ this-> getDoctrine() - > getRepository('GSOrderBundle:Customer') - > find($ id ); 返回新的响应('Number:'.$ id.''); 日志 -

1错误信息 - 匹配的路线"customer"(参数:"_ control":"GS\OrderBundle\Controller\CustomerController :: indexAction","id":"1784","_ lute":"customer")DEBUG - 通知事件" …

php mysql doctrine symfony doctrine-orm

4
推荐指数
1
解决办法
1万
查看次数

如何从网络访问symfony项目

我已经用xampp安装了symfony.我可以在本地访问它,但是当我尝试从同一网络上的另一台计算机连接到它时,我得到404.我可以访问xampp apache,可以访问mysql.如何配置symfony?

xampp symfony

1
推荐指数
1
解决办法
2520
查看次数

标签 统计

symfony ×2

doctrine ×1

doctrine-orm ×1

mysql ×1

php ×1

xampp ×1