Error on Portlet after Upgrading to 1.0.8

Dear All,

Today as Yii 1.0.8 released, I upgraded mine from Yii 1.0.7. And errors show:


FlashMessage does not have a method named "run".

What is weird, it was fine before I upgraded. So I decided to make sure, and degrade it again to Yii 1.0.7, and it runs OK again without errors or exceptions. But when I upgrade to 1.0.8 again, it throws error again.

FlashMessage is a portlet of which displays application messages and determine correct css style to users, for example:

FlashMessage extends Portlet which extends CWidget. Here is the code to Portlet.php:


<?php

abstract class Portlet extends CWidget

{

    public $title     = '';

    public $showTitle = true;

    public $published = true;


    public function init() {

        

    }


    public function run()

    {

       if ($this->published)

       {

           $this->renderContent();

           // render the portlet ending frame

       }

    }


    /**

     * Child Classes from Portlet must override this method to render its content

     * @method  renderContent

     * @abstract

     */

    abstract protected function renderContent();


}

And the FlashMessage.php is as simple as below:


<?php

class FlashMessage extends Portlet

{

    public $message = '';

    public $type = 'success'; //success || error || warning || info


    public function init()

    {

        parent::init();

    }


    /**

     *

     * Child Classes from Portlet must override this method to render its content

     * @method  renderContent

     */

    protected function renderContent()

    {

       if(Yii::app()->user->hasFlash('success'))

       {

           $this->message = Yii::app()->user->getFlash('success');

           $this->type = 'success';

       }

       else if (Yii::app()->user->hasFlash('error'))

       {

           $this->message = Yii::app()->user->getFlash('error');

           $this->type = 'error';

       }

       else if (Yii::app()->user->hasFlash('info'))

       {

           $this->message = Yii::app()->user->getFlash('info');

           $this->type = 'info';

       }

       else if (Yii::app()->user->hasFlash('warning'))

       {

           $this->message = Yii::app()->user->getFlash('warning');

           $this->type = 'warning';

       }


       $this->render('_flashMessage');

    }

}



And finaly, the view of the FlashMessage:


<?php if (isset($this->message) && $this->message != "") { ?>

<div class="message <?php echo $this->type; ?>">

   <?php echo $this->message; ?>

</div>

<?php } ?>

I don’t know but maybe it has something to do on the way I imported the models and components ? In the config/main.php is all the imports happen in my application:


<?php

// autoloading model and component classes	

	'import'=>array(

		'application.models.*',

		'application.components.*',

        'application.ext.*',

        'application.helpers.*',

        'application.vendors.*'

	)

So, please help on this issue, because I really do not know what has happened ? Why it displays error when I run my application on Yii version 1.0.8 ?

For now, I have degraded again to Yii 1.0.7 as my application runs Stable on the version.

Thank you in advanced!

Do a global search for "FlashMessage". This must be because you have multiple FlashMessage classes. In 1.0.8, the precedence of imported path aliases is reversed (i.e., path imported later has precedence over existing paths).

Hi qiang!

Sorry, but I don’t think I have understood on what you said about multiple FlashMessage classes that I have ? I only have 1 class of FlashMessage which is stored in the components folder of my application.

And yes, I also did a global search which I found only 1 FlashMessage.php class, and many on the other views where it is being used, such as:


<?php

   $this->widget('FlashMessage');

What about ‘Portlet’ class? Did you find multiple?

Oh man, you’re right! So, in components folder there is this Portlet.php, and then in my models folder also there is Portlet.php, so I have renamed models/Portlet.php to models/PortletModel.php. And it worked!

Thank you very much, qiang! Problem Solved.