我在使用服務管理器時遇到錯誤消息。 如何通過像constuct不同的方法解決這個....已棄用:ServiceLocatorAwareInterface已棄用,將在3.0版中與ServiceLocatorAwareInitializer一起被刪除
Deprecated: You are retrieving the service locator from within the class Users\Controller\LoginController. Please be aware that ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along with the ServiceLocatorAwareInitializer. You will need to update your class to accept all dependencies at creation, either via constructor arguments or setters, and use a factory to perform the injections. in C:\wamp64\www\ZendSkeletonApplication-master\vendor\zendframework\zend-mvc\src\Controller\AbstractController.php on line 258
下面的代碼我在module.php添加
public function getServiceConfig() {
return array(
'abstract_factories' => array(),
'aliases' => array(),
'factories' => array(
// FORMS
'LoginForm' => function ($sm) {
$form = new \Users\Form\LoginForm();
$form->setInputFilter($sm->get('LoginFilter'));
return $form;
},
)
)
}
和登錄控制器,索引操作調用我下面的代碼
$form = $this->getServiceLocator()->get('LoginForm');
$viewModel = new ViewModel(array('form' => $form));
return $viewModel;
任何幫助,高度讚賞。
當前我正在使用Zend框架2.5.1版本 在Zend框架2.3版本中它工作正常。
更新
我現在用下面的代碼在我的控制器
// Add this property:
private $table;
// Add this constructor:
public function __construct(LoginForm $table) {
$this->table = $table;
}
和module.php
// FORMS
Model\AlbumTable::class => function ($sm) {
$form = new \Users\Form\LoginForm();
$form->setInputFilter($sm->get('LoginFilter'));
return Model\AlbumTable;
},
但我仍然得到下面的錯誤我
Catchable fatal error: Argument 1 passed to Users\Controller\LoginController::__construct() must be an instance of Users\Form\LoginForm, none given, called in C:\wamp64\www\ZendSkeletonApplication-master\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php on line 252 and defined in C:\wamp64\www\ZendSkeletonApplication-master\module\Users\src\Users\Controller\LoginController.php on line 22
是什麼問題?你想知道什麼廢棄的手段?你想知道如何停止出現的錯誤信息?你想知道要使用什麼嗎? – RiggsFolly
我在使用服務管理器時遇到以上錯誤消息。我怎樣才能解決這個通過不同的方法,如構造.... –
請按照消息中的說明。並看看這個http://stackoverflow.com/questions/36061210/deprecated-retrieve-service-locator-in-functional-system-zf2一個10秒的谷歌找到了我。如果這是你所需要的,刪除這個問題,因爲它顯然是重複的 – RiggsFolly