title: How to use Yii trait in controller
body: <p>In my controllers a lot of code, about 1000 lines 
  Advise how you can make more convenient, for example to make a piece of code in trait</p>
  
  <blockquote>
    <p>components/ProductTrait.php</p>
  </blockquote>
  
  <pre><code>trait ProductTrait{
  
  protected function getProductProvider(Product $model){
      $dataProductProvider = new CActiveDataProvider('Product', array(
              'criteria' =&gt; array(
                      'limit' =&gt; $pageLimit,
                      'condition' =&gt; 't.creatorId = :creatorId AND t.categoryId =:categoryId',
                      'order' =&gt; 't.created DESC',
                      'params' =&gt; array(
                              ':creatorId' =&gt; $model-&gt;creatorId,
                              ':categoryId' =&gt; $model-&gt;categoryId,
                      ),
              ),
              'pagination' =&gt; false,
              'sort' =&gt; false,
      ));
      return $dataProductProvider;
   }
  
  
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>class DealerController extends Controller{
  use ProductTrait;
  public function actionView($id){
      $model = $this-&gt;loadModel($id);
      if ($model === null) {
          throw new CHttpException(404, 'The requested page does not exist.');
      }
      $renderParams['productProvider'] = $this-&gt;getProductProvider($model);
   }  
  
  }
  </code></pre>