我是面向对象编程的新手。我需要访问子类中抽象父类中生成的$ key变量的内容。如何在postAction()方法中获取$ key变量的内容?
abstract class ApiControllerAbstract extends Zend_Rest_Controller {
public function init() {
$cryptoHelper = new Application_Model_CryptoHelper;
$pass = '';
$salt = '';
$passwordIterations = 100;
$keySize = 32;
$iv = "";
$key = $cryptoHelper->getKey($pass, $salt, $passwordIterations, $keySize);
}
}
class Api_SubscribersuploadController extends ApiControllerAbstract {
public function postAction() {
// I need to access contents of key variable from here.
echo parent::$this->key;
}
}
我尝试使用echo parent::$this->key;
但它没有显示任何内容。
答案 0 :(得分:1)
abstract class ApiControllerAbstract extends Zend_Rest_Controller {
public function init() {
$cryptoHelper = new Application_Model_CryptoHelper;
$pass = '';
$salt = '';
$passwordIterations = 100;
$keySize = 32;
$iv = "";
$key = $cryptoHelper->getKey($pass, $salt, $passwordIterations, $keySize);
return $key;
}
}
class Api_SubscribersuploadController extends ApiControllerAbstract {
public function postAction() {
// I need to access contents of key variable from here.
$this->init();
}
}