Can't use function return value in write context

what’s the problem with my code?

error:

layouts/header.php


<?

foreach($lesson as Lesson::getAllLessons()):

    echo CHtml::link($lesson,"?r=lesson&type=".$lesson,array("title"=>$lessons)) . "<br />";

endforeach;

?>

lesson model:


<?php


class Lesson extends CActiveRecord

{

    public static function model($class=__CLASS__)

    {

        return parent::model($class);

    }

    

    public static function isLessonInList($name)

    {

        return in_array($name, self::$lessons);

    }

    

    public function tableName()

    {

        return "lessons";

    }

    

    public static function getAllLessons()

    {

        return self::model()->findAll();

    }

}


?>



how can i fix the fatal error?

hello,

I think there is a problem with your foreach… try this:


<?

foreach(Lesson::getAllLessons() as $lesson):

    echo CHtml::link($lesson,"?r=lesson&type=".$lesson,array("title"=>$lessons)) . "<br />";

endforeach;

?>

but it’s also a good practice to check if getAllLessons() are not empty with an if statement.

hope it helps,

–iM

NOTE: renamed post title to something meaningful and moved to proper sub-forum (General Discussion instead of Tips, Snippets and Tutorials)