title: Yii - how to retrieve model data into a layout page?
body: <p>I wish to list some Categories name on my layout main.php page.
  Since the layout doesn't have any associated controller or model, I wish to create a static method like this on Category model:</p>
  
  <pre><code>public static function getHeaderModels()
  {
     // get all models here
     return $models;
  }
  </code></pre>
  
  <p>and then in the main layout</p>
  
  <pre><code>&lt;?php
  $models = Category::getHeaderModels();
  foreach($models as $model)
  {
     // ....
  }
  ?&gt;
  </code></pre>
  
  <p>My question is a very basic one:
  <strong>How can I retrieve those category names from the model ?</strong></p>
  
  <p>Here is the full model:</p>
  
  <pre><code>class Category extends CActiveRecord {
  
  
      public static function model($className=__CLASS__) {
          return parent::model($className);
      }
  
      public function tableName() {
          return 'category';
      }
  
      public function rules() {
          return array(
              array('parent_id', 'numerical', 'integerOnly' =&gt; true),
              array('name', 'length', 'max' =&gt; 255),
              array('id, parent_id, name', 'safe', 'on' =&gt; 'search'),
          );
      }
  
      public function relations() {
          return array(
              'users' =&gt; array(self::MANY_MANY, 'User', 'categories(category_id, user_id)'),
          );
      }
  
      public function scopes()
      {
          return array(
              'toplevel'=&gt;array(
                  'condition' =&gt; 'parent_id IS NULL'
              ),
          );
      }
  
      public function attributeLabels() {
          $id = Yii::t('trans', 'ID');
          $parentId = Yii::t('trans', 'Parent');
          $name = Yii::t('trans', 'Name');
  
          return array(
              'id' =&gt; $id,
              'parent_id' =&gt; $parentId,
              'name' =&gt; $name,
          );
      }
  
      public function search() {
          $criteria = new CDbCriteria;
          $criteria-&gt;compare('id', $this-&gt;id);
          $criteria-&gt;compare('parent_id', $this-&gt;parent_id);
          $criteria-&gt;compare('name', $this-&gt;name, true);
  
          return new CActiveDataProvider(get_class($this), array(
                  'criteria' =&gt; $criteria,
              ));
      }
  
  
          public static function getHeaderModels() {
  
              //what sintax should I use to retrieve the models here ?
  
              return $models;
  
          }
  </code></pre>