0
我在設置doctrine以從以下服務文件運行時遇到了一些問題。調用成員函數has()null 500 with Symfony and Doctrine
<?php
// src/AppBundle/Services/SuperusersService.php
namespace AppBundle\Services;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\ORM\EntityManager;
class SuperusersService extends Controller
{
public function sayHello()
{
$em = $this->getDoctrine()->getManager();
// Query here
}
}
當我運行上面的時候,我得到以下錯誤信息。
調用一個成員函數()對空500內部服務器錯誤 - FatalThrowableError
我打電話從下面的控制文件的文件。
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class LoginController extends Controller
{
/**
* @Route("/login")
*/
public function indexAction(Request $request)
{
if(!empty($_POST)){
////
// If for submitted attempt to log the user in.
////
$superusersService = $this->get('app.superusers.services');
$superusersService->sayHello();
}
$name = "Login";
return $this->render('login/login.html.php',
array());
}
}
服務文件
# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/service_container.html
parameters:
# parameter_name: value
services:
# service_name:
# class: AppBundle\Directory\ClassName
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
app.superusers.services:
class: AppBundle\Services\SuperusersService
現在我周圍採取了看看其他的問題,但作爲然而我無法解決以上。我認爲這將與文件的設置有關,但我不確定是什麼。