我試着從我的控制器中調用一個函數並將$ todolist返回給我的控制器。但是,我得到這個錯誤,當我離開控制器內的這個功能,它工作正常,但我不希望它在控制器中。
這是我的控制器
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Entity\Todo;
use AppBundle\Model\TodoModel;
class TodoController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function ShowList()
{
$todolist = TodoModel::getTodolist();
$html = $this->container->get('templating')->render(
'todolist/todolist.html.twig',
array('todolist' => $todolist)
);
return new response($html);
}
}
這是我的模型
namespace AppBundle\Model;
use AppBundle\Entity\Todo;
class TodoModel
{
public function getTodolist()
{
$repository = $this->getDoctrine()
->getRepository('AppBundle:Todo');
$todolist = $repository->findAll();
return $todolist;
}
}