Check Access Permission To An Action (Ex Download Button )

hi all , maybe it will be a easy question , i m really new in programming …

i would like to know how if it is better to use the controller without put the if clauses inside the view .

is preferable to use controller instead putting directly in view ?

at the moment i do like this


if (Yii::app()->user->isGuest) {

                    ?>

                    <div class="dashIcon span-3">

                        <a href="/user/registration/"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/images/big_icons/icon-key.png" alt="Page" /></a>

                        <div class="dashIconText"><a href="/user/registration/"><?php echo Yii::t('homepage', 'Registration'); ?></a></div>

                    </div>

                    <?php

                } else {

                    ?>

                    <div class="dashIcon span-3">

                        <a href="/user/profile/"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/images/big_icons/icon-person2.png" alt="Products" /></a>

                        <div class="dashIconText"><a href="/user/profile/"><?php echo Yii::t('homepage', 'Your Profile'); ?></a></div>

                    </div>

                    <?php

                }

It’s perfectly fine to use like this for a small block of code. There are many alternatives though. Take a look at http://www.yiiframework.com/doc/api/1.1/CMenu - maybe this will get handy.

thank you Bizley

i would like to do something like that with Visible parameter


                             if ( $model->tblusersid === Yii::app()->user->Id || $maildocente->mail === $user->email || Yii::app()->user->checkAccess('Site.admin', Yii::app()->user->id) ) {


//print a button 

 $this->widget('bootstrap.widgets.TbButton', array(

                                    'label' => 'Download',

                                     'url' => array('tesi/download', 'name'=>$model->tesifile),

                                    'type' => 'danger', // null, 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'

                                    'htmlOptions'=>array('id'=>'pdfbutton'),


                                 ));

}

else {

/print another butto

}