ZF2ベンダーライブラリにソートベースモジュールを作成しました。これまでのところ、すべてが私が望むように機能しています。私には問題があります。ベースモジュールのコントローラーを拡張することはできますが、ベースサービスにアクセスできません。データベースレイヤーとしてDoctrine2を使用しています。
ServiceLocatorを実装した後、致命的なエラーが発生します。ベースサービスファイル内の非オブジェクトでメンバー関数get()を呼び出します。私のBaseServiceファイルは次のように表示されます。
namespace MyResource\Service;
use Doctrine\ORM\Mapping as ORM;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class BaseService implements ServiceLocatorAwareInterface
{
/**
* Entity manager instance
*
* @var Doctrine\ORM\EntityManager
*/
protected $_em;
protected $_serviceLocator;
public function __construct()
{
$this->getEntityManager();
}
/**
* Returns an instance of the Doctrine entity manager loaded from the service
* locator
*
* @return Doctrine\ORM\EntityManager
*/
public function getEntityManager()
{
if (null === $this->_em) {
$this->_em = $this->getServiceLocator()
->get('doctrine.entitymanager.orm_default');
}
return $this->_em;
}
/**
* Set serviceManager instance
*
* @param ServiceLocatorInterface $serviceLocator
* @return void
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}
/**
* Retrieve serviceManager instance
*
* @return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
}
誰か助けてもらえますか?
ありがとう