在我的应用程序中,有自定义配置,我想将它们放入模型中。
我读到了一种方法,但它不能执行:
namespace Core\Model;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\TableGateway\Feature\FeatureSet;
use Zend\Db\TableGateway\Feature\GlobalAdapterFeature;
use Zend\Db\Sql\Delete,
Zend\Db\Sql\Insert,
Zend\Db\Sql\Update,
Zend\Db\Sql\Select;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class BaseModel extends AbstractTableGateway implements ServiceLocatorAwareInterface
{
protected $serviceLocator;
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) {
$this->serviceLocator = $serviceLocator;
}
public function getServiceLocator() {
return $this->serviceLocator;
}
public function __construct()
{
$this->featureSet = new FeatureSet();
$this->featureSet->addFeature(new GlobalAdapterFeature());
$this->initialize();
}
}
在我规定的模型中
$config = $this->getServiceLocator()->get('config');
或者
$config = $this->getServiceLocator();
但结果=NULL
谁能告诉我我做错了什么?