I am trying to access block class method from controller and set some value to block class property. The method is being accessed but when I try to print the property in .phtml
file it is NULL.
Here is my code:
app/code/local/Amactech/Events/controllers/IndexController.php
<?php
class Amactech_Events_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$block=$this->getLayout()->createBlock('events/events');
$block->setFeedback("wrwqerqwer fasdfasdf vxzcvzxcv");
$this->loadLayout();
return $this->renderLayout();
}
}
?>
app/code/local/Amactech/Events/Block/Event.php
<?php
class Amactech_Events_Block_Events extends Mage_Core_Block_Template{
public $_feedback;
public function setFeedback($feedback){
echo $feedback;
$this->_feedback = $feedback;
}
public function getFeedback(){
echo "get feedback"; /*This line is being printing which means I am getting in this method*/
return $this->_feedback;
}
}
?>
app/design/frontend/base/default/template/events/events.phtml
<?php
echo $this->getFeedback();
?>
So I am accessing block setFeedback()
method and setting $_feedback
value. I print something string inside setFeedback()
and getFeedback()
methods to check whether I am getting into these methods. The printing string is shown which means I am getting into the methods but when I assign some value to property and try to print the property is shows NULL.