"PHP message: PHP Fatal error: Uncaught TypeError: Argument 2 passed to Mage::dispatchEvent() must be of the type array, object given, called in TestimonialController.php on line 26"

I am facing above error, i have upgraded my php version to 7.1 with magento 9.1.0

here is my function

/*TestimonialController.php starts*/
public function editAction()
    $this->_title($this->__("Edit Item"));
    $id = $this->getRequest()->getParam("id");
    $model = Mage::getModel("testimonials/testimonial")->load($id);
    Mage::dispatchEvent('testimonial_save_before', $model);//Line No.->26

    if ($model->getId()) {
        Mage::register("testimonial_data", $model);
        $this->_addBreadcrumb(Mage::helper("adminhtml")->__('Testimonial Manager"), Mage::helper("adminhtml")->__("Testimonial Manager"));
        $this->_addBreadcrumb(Mage::helper("adminhtml")->__("Testimonial Description"), Mage::helper("adminhtml")->__("Testimonial Description"));
    else {
        Mage::getSingleton("adminhtml/session")->addError(Mage::helper("testimonials")->__("Item does not exist."));
/*TestimonialController.php starts*/ 

/*Observer.php starts*/

class Ravi_Testimonials_Model_Observer extends Mage_Core_Model_Abstract

const COUPON_ACTIVE = 'testimonial/couponcode/activecoupon';   
public function testimonialSaveBefore($observer){

    //echo $observer->getEvent()->getData()->getId();

    //echo $observer->getEvent()->getData()->getStatus();

    $tId = $observer->getEvent()->getData()->getId(); //line 33


public function testimonialSaveAfter($observer){

$testimonialId = Mage::getSingleton('core/session')->getTid();
$status = Mage::getSingleton('core/session')->getSt();

if($status == 0 && $observer->getStatus() == 0){



if($status == 0 && $observer->getStatus() == 1){



if($status == 1 && $observer->getStatus() == 0){

//If status goes from disable to enable, notify customer via email. Write codd for send emails.
if(Mage::getStoreConfig(self::COUPON_ACTIVE) == 1){



/*Observer.php ends*/

This line

Mage::dispatchEvent('testimonial_save_before', $model);

Should be

Mage::dispatchEvent('testimonial_save_before', array('testimonial' => $model));

And you need to modify the observer also.
Make the method testimonialSaveBefore look like this:

public function testimonialSaveBefore($observer)
    $testimonial = $observer->getEvent()->getTestimonial();
    $tId = $testimonial->getId(); 

But, the way you have your code right now, the testimonial id will always be null, because there is no id allocated to the testimonial before it is saved in the database.

  • I have tried that but, now getting following error. "PHP message: PHP Fatal error: Uncaught Error: Call to a member function getId() on array in Observer.php" – Suyog Dec 7 '16 at 13:53
  • Then add the observer code to your question – Marius Dec 7 '16 at 13:54
  • please check, i have added – Suyog Dec 7 '16 at 14:03
  • It's showing issue with line 33. – Suyog Dec 7 '16 at 14:06
  • 1
    I've updated my answer with my last try. – Marius Dec 7 '16 at 14:25

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.