Difference between #3 and #2 of Yii HMVC

unchanged
Title
Yii HMVC
unchanged
Category
How-tos
changed
Tags
Initial writeupHMVC, reusable requests, action, view,
controller, AJAX
changed
Content
Introduction
------------------
Right now we can use widgets + action provider
like in this tutorial:
[How to use a Widget as an Action
Provider](http://www.yiiframework.com/wiki/146/how-to-use-a-widget-as-an-action-provider
"Action Provider")

what i am going to introduce is a coding style that will result into a single
page generated from different requests like in the example below
this makes the specific request reusable instead of just an action being
accessible to the controller in which the widgets are created

HMVC coding style
------------------
~~~
[php]
<div class="row-fluid">
    <div class="span6">
        <?php Yii::app()->runController('hmvc/default/customerList');
?>
    </div>
    <div class="span6">
        <?php
Yii::app()->runController('hmvc/default/quotationlist');?>
    </div>
</div>

~~~

i created an hmvc module which has this controller

Reusable HMVC controller
------------------
i created an hmvc module which has this controller
~~~
[php]


class DefaultController extends Controller {

    //standard cgridview code but uses renderpartial

    public function actionCustomerList(){
        $model = new Customer('search');
        $model->unsetAttributes();
        if(isset($_GET['Customer']))
            $model->attributes = $_GET['Customer'];
        $this->renderPartial('customer', array('model' => $model));
    }

    public function actionQuotationList() {
        $model = new Quotation('search');
        $model->unsetAttributes();
        if(isset($_GET['Quotation']))
            $model->attributes = $_GET['Quotation'];
        $this->renderPartial('quotation', array('model' => $model));
    }
    
    public function actionAnother(){
        echo "THIS IS FROM ANOTHER ACTION!";
    }


}
~~~
notice that i only used render partials or echo

hmvc viewsHMVCviews
---------

**customer.php**

~~~
[php]
        $this->widget('zii.widgets.grid.CGridView', array(
            'dataProvider' => $model->search(),
            'id'=>'customer-grid',
            'filter' => $model,
            'columns' => array('name'),
        ));
~~~


**item_detail.php**
~~~
[php]
$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'item-detail-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        'id',
        'status'=>array(
            'name'=>'status',
            'filter'=>ItemDetail::itemAlias('status'),
            'value'=>'$this->filter[$data->status]',
        ),
    ),
   
));
~~~

By doing this we do not have make a reusable actions with CAction but instead we
can use these requests all throughout the system..
just put in mind that the 'ids' being used should still be unique across the
rendered final page.
we also do not have to bother our controllers that are going to use our widgets,
direct call from views are enough