小编MiS*_*Str的帖子

找不到ZF2 getServiceLocator()?

我不能为我的生活让$ this-> getServiceLocator()在我的控制器中工作.我已经阅读并尝试了一切.我猜我错过了什么?这是一些代码.

namespace Login\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\Session\Container as SessionContainer;
use Zend\Session\SessionManager;
use Zend\View\Model\ViewModel;
use Zend\Mvc\Controller;

use Login\Model\UserInfo;

class LoginController extends AbstractActionController
{
    private $db;

    public function __construct()
    {
        $sm = $this->getServiceLocator();

        $this->db = $sm->get('db');
    }
    ...
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

Fatal error: Call to a member function get() on a non-object in /product/WishList/module/Login/src/Login/Controller/LoginController.php on line 21 
Run Code Online (Sandbox Code Playgroud)

php zend-framework2

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

标签 统计

php ×1

zend-framework2 ×1