title: mvc best practice view/controller/model in php and yii
body: <p>This is a best practice question and not a specific issue.
  I'm fairly new to the MVC approach and Yii, and have developed on an app for a while now. I keep seeing talks on best practice and what to put in which file (controller, model, view, helper etc.) however i have not yet found anything specific in terms of examples.</p>
  
  <p>I currently have calls like: <code>Model::function()</code> in my view files as well as checks like <code>$var = app()-&gt;request-&gt;getParam(value, false);</code></p>
  
  <p>I have calls in my controller file like Model::function() and Model::model()->scope1()->scope2()->findAll() I also think my controller files are getting a bit thick, but not sure how and where to put some of the bloat, i have been reading about the DRY and i think i'm not exactly DRY'ing my code so to speak.
  Could you give me a more clearer picture about what goes where, and suggestions or reasons why :)
  Appreciate any advice, thanks in advance.</p>
  
  <p>here's an example call in a viewfile</p>
  
  <pre><code>&lt;?php
  $this-&gt;pageTitle = 'Edit Action';
  $this-&gt;subTitle = '&lt;i&gt;for&lt;/i&gt; &lt;b&gt;' . Vendors::getName($_GET['vendor']) . '&lt;/b&gt;';
  ?&gt;
  
  &lt;div class="wrapper"&gt;
  &lt;?php echo $this-&gt;renderPartial('_form', array('model' =&gt; $model)); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The getName is my function in the model, is this a good way to call a function in a view?</p>
  
  <p>Another example view file:</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
      &lt;?php 
  
      if($this-&gt;action-&gt;id != 'create') {
          $this-&gt;pageTitle = "New Media Contact";
           echo $this-&gt;renderPartial('_form', array('model'=&gt;$model));
      } else {
          $this-&gt;pageTitle = "New Vendor";
           echo $this-&gt;renderPartial('_form', array('model'=&gt;$model));
      }
      ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>$model is set in the controller with type...
  Same question... could this be done.. cleaner..? better in terms of MVC and reusability/DRY?</p>
  
  <p><strong>EDIT</strong>
  After reading some of the responses here, esp. @Simone I refactored my code, and wanted to share what it looks like now...</p>
  
  <pre><code>public function actionCreate() {
      $model = new Vendors;
  
      // Get and Set request params
      $model-&gt;type = app()-&gt;request-&gt;getParam('type', Vendors::VENDOR_TYPE);
      $vendorsForm = app()-&gt;request-&gt;getPost('Vendors', false);
      // Uncomment the following line if AJAX validation is needed
      $this-&gt;performAjaxValidation($model);
      if ($vendorsForm) {
          $model-&gt;attributes = $vendorsForm;
          if ($model-&gt;save())
              $this-&gt;redirect(array('/crm/vendors', array('type' =&gt; $model-&gt;type)));
      }
      $model-&gt;categories = Categories::getAllParents($model-&gt;type);
      $this-&gt;pageTitle = 'New ' . Lookup::item('VendorType', $model-&gt;type);
      $this-&gt;render('create', array(
          'model' =&gt; $model,
      ));
  }
  </code></pre>
  
  <p>and the view create.php</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
  &lt;?php echo $this-&gt;renderPartial('_form', array('model'=&gt;$model));?&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thanks for all respnses</p>