根据ZF2 的回复:将事件附加到另一个控制器的操作并获取服务定位器,我将一个事件附加到控制器的操作,如下所示
$loader = $sl->get('ControllerLoader');
$loginController = $loader->get('B\Controller\LoginController');
$sharedEventManager->attach('A\Controller\LoginController',
'checkme.post',
array($loginController, 'loginAction'),
100);
当事件触发时,它进入“B”控制器的 loginAction。当我尝试调用 B\LoginController 的其他方法时,在 loginAction 内部,出现错误
致命错误:在 C:\wampp\www\Zend2\module\B\src\B\Controller\LoginController.php 的对象上下文中使用 $this 第 60 行的块引用
控制器代码:
<?php
namespace B\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Soap\Client;
class LoginController extends AbstractActionController {
public function loginAction($e) {
$user_id = $e->getParam('user_id');
$config = $e->getParam('config');
if($user_id){
$client = $this->getSoapClient($config);
$params = $this->enrolmentRequestParams($user_id);
$response = $client->getEnrolment($params);
$course_enrolment = $response->enrolment_list->value->course_enrolment_list->course_enrolment;
$this->processEnrolmentData($course_enrolment);
}
}
public function getSoapClient($config){
$options = array(
'soap_version'=> $config['webservice_config']['soap_version'],
'location' => $config['webservice_config']['location']
);
$wsdl = $config['webservice_config']['wsdl'];
$client = new \Zend\Soap\Client($wsdl, $options);
return $client;
}
public function processEnrolmentData($course_enrolment){
foreach($course_enrolment as $ce){
// some code here
}
}
public function enrolmentLookUp($e){
//some code here
}
public function enrolmentRequestParams($sid){
//some code here
}
public function emptyObject($theObject){
$tmp = (array) $theObject;
if(empty($tmp)) {
return true;
}else{
return false;
}
}
public function validVal($uos){
if(!empty($uos) && !is_null($uos) && isset($uos)){
return true;
}else{
return false;
}
}
public function getSemesterNo($value){
return preg_replace("/[^0-9]/","",$value);
}
}
?>
请在这方面提供帮助。