我正在尝试使用symfony/doctrine创建一个小应用程序来读取表中的记录.我的步骤:
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 - 通知事件" …
我已经用xampp安装了symfony.我可以在本地访问它,但是当我尝试从同一网络上的另一台计算机连接到它时,我得到404.我可以访问xampp apache,可以访问mysql.如何配置symfony?