How can i pass variable to observer from controller? Or is there a way to wait that execute observer before execute method in controller?


try this code



Use this code in controller file

$event_data_array  =  array('cid' => '123');
Mage::dispatchEvent('my_custom_event', $event_data_array);

use this code in observer file

class Namespace_Modulename_Model_Observer
  public function my_custom_method($observer) {
    $event = $observer->getEvent();

    // getter method to fetch varien object passed from the dispatcher
    $varien_object = $event->getVarienObj();


You can also refer below links to get the idea how them works




  • why $varien_object->setCid('456') ? where is the variable passed? – Altravista Oct 11 '18 at 13:58
  • if you want update variable(cid) value then you can update in observer file. – Balwant Singh Oct 11 '18 at 14:06
  • but i want to get value from controller not update it. i try with this code $cid = $varien_object->getCid(); but get error – Altravista Oct 11 '18 at 14:11
  • can you add your error here? – Balwant Singh Oct 11 '18 at 14:11
  • Call to a member function getCid() on a non-object – Altravista Oct 11 '18 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.