How send data from database to layouts

I need show data from database in the column2. How can do it?

I must write function in model or I can send from controler?

  1. you create an attribute in Controller.php.

public $myattribute;

  1. you can use the init() method of Controller.php to retrieve data from database.

public function init()

{

    $this->myattribute = Model::model()->findByPk(1);

}

  1. you can access this attribute from column2 in this way:



var_dump($this->myattribute);

Thank You.

Can I write this function in model and use it in column or I should use controler?




public static function column(){

    	$model = self::model()->findByPk(1);

    	$data = array($model->myattribute1, $model->myattribute2);

    	return $data;

}



I don’t understand what is init().

Can you explain me when and where I can use function init()?

protected > components > Controller.php


class Controller extends CController

{

   public $myattribute;


   public function init()

   {

       $this->myattribute = Model::model()->findByPk(1);

   }

}

Thank You!

I added in class Controller and now it works.

You should really start with some of the tutorials like the Blog. This will help you will Yii.