Thanks chinaski. One more question is: once I set a class variable value in
init() method, can I change the value in a method such as indexAction() and
use it in another method such as listAction()? For example:
class ForumController extends Zend_Controller_Action
{
protected $_forumid;
public function init() {
$this->_forumid = 6;
}
public function indexAction() {
$this->_forumid = 7;
}
public function lookAction() {
echo $this->_forumid; //suppose to be 7
}
...
Thanks
chinaski wrote:
>
>
>
> xing93111 wrote:
>>
>> Hi,
>>
>> I try to define class variables in a controller class. For example:
>>
>> class ForumController extends Zend_Controller_Action
>> {
>> protected $_forumid;
>>
>> public function indexAction() {
>> ...
>> $_forumid = $somevalue;
>> }
>> ...
>>
>> }
>>
>> However, it seems does not work. I cannot use $_forumid in other
>> functions in the same controller class. Any one can help
>>
>> Thank you very much
>>
>> Bill
>>
>
> Couple of things going on here:
> 1) to set a class var you need to use the $this-> syntax, i.e.
> $this->_forumid = $somevalue;
> 2) in other action calls the indexAction() function does not run. You need
> to do your class initializations in the init() function, i.e.
>
> public function init()
> {
> $this->_forumid = 'somevalue';
> }
>
> The init function is called automatically in the controller constructor.
>
>
--
View this message in context:
http://www.nabble.com/Can-controller-class-have-class-variables--tp16723533p16730797.html
Sent from the Zend Framework mailing list archive at Nabble.com.