CController::renderPartial()

I have a widget that displays user information in components/views. It used to work, but I am upgrading my php and it now throws the error "Non-static method should not be called statically."




       <div id="schedule-div" class="holder">

        <!-- Table -->

        <?php 

            if(!empty($this->registrations))

            {

                // Schedule Table

                echo "<div id='user-schedule' class='agenda-table'>";

                    echo CController::renderPartial(

                        '_agendaTable', 

                        array(

                            'agendaRegistrations'=>$this->agendaRegistrations, 

                            'activityId'=>$this->activityId,

                        )

                    );

                echo "</div>"; // END "user-schedule"

            }

            else echo "<p>You have not registered for any activities</p>";

        ?>

    </div>



I have tried modifying the code as follows:




...

$connection = new CController(Yii::app()->controller->id);

echo $connection->renderPartial(...

...



But then I get an error saying that ‘CController cannot find the requested view “_agendaTable”.’

My understanding of when and why to use static v. non-static functions is vague. Thanks in advance for your assistance.

If you look at the documentation for CController, you will find that CController::renderPartial is not a static method, so that error makes sense.

Now for you modified code, there’s nothing wrong with it but normally, it would search for a view file under the views folder for the controller id passed to CController, which in this case your controller view folder might not have a file called _agendaTable.

If your widget extends from CWidget, I think it has its own render function which would search for view files under "widget/views/NameOfViewFile.php".




<div id="schedule-div" class="holder">

    <!-- Table -->

    <?php 

        if(!empty($this->registrations))

        {

            // Schedule Table

            echo "<div id='user-schedule' class='agenda-table'>";

                $this->render(

                    'agendaTable', 

                    array(

                        'agendaRegistrations'=>$this->agendaRegistrations, 

                        'activityId'=>$this->activityId,

                    )

                );

            echo "</div>"; // END "user-schedule"

        }

        else echo "<p>You have not registered for any activities</p>";

    ?>

</div>



Hi friend,

  Please show your model, may be the above mentioned error was in your model. <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/rolleyes.gif' class='bbc_emoticon' alt='::)' />

try it




Yii::app()->controller->renderPartial(.......)



In the end I combined two answers to get a working solution:




echo Yii::app()->controller->renderPartial(

    'application.components.views._agendaTable', 

         ...

     );



I was able to call renderPartial without error with one line of code instead of two using Yii::app()->controller->renderPartial().

And I had to add the path to _agendaTable. It is in the same directory with the original file, but it needed the additional path information to find the file.

Thank you everyone for your help. Yii forum to the rescue!