Monday, December 10, 2012

Make Different Cells css row or cells column in CGridView Yii

CGridview is one of the most powerful tools that you can do with generating table in Yii framework.But sometimes you want to include your own data into Columns properti as parameter to check data with the columns data that came from external sources.

The way you can do is creating the new gridview with the external data addition in the end. You can extend grid view with your own data and then place this code to the Components in yiiframework.


Yii::import('zii.widgets.grid.CGridView');
class GridViewWithVariable extends CGridView {
    public $params;
}
And then name it as GridViewWithVariable.php in components. And then you can create the new  array in your GridView like this

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'params'=>$params,
    'columns'=>array(
        'title',         
        'category.name',  
        'content:html',   
        array(            
            'name'=>'val',
            'value'=>'in_array(val,$this->grid->params)',//you can access your variable like this
        ),
        array(            
            'name'=>'authorName',
            'value'=>'$data->author->username',
        ),
        array(            
            'class'=>'CButtonColumn',
        ),
    ),
));

If you want to create different css in row you can create your custom Css like this. This is the gridview that created from CSqlDataProvider so you have to access your data via array like $data["DirekturID"].

$this->widget('GridViewWithVariable', array(
    'dataProvider' => $dataProvider,
    'params' => $arrNotResponsibleDirektur,
    'columns' => array(
        array(
            'name' => 'Direktur',
            'value' => '$data["Direktur"]',
            'cssClassExpression' => 'in_array($data["DirekturID"],$this->grid->params)?"normal":"merah"',
            'htmlOptions'=>array('width'=>'300px'),

        
        ),
        array(
            'name' => 'Yes',
            'type' => 'raw',
            'value' => '$data["ResponID"]=="1"?"✓":""',
            'cssClassExpression' => '"yes"',
            'htmlOptions'=>array('width'=>'40px'),
        
        ),
        array(
            'name' => 'No',
            'type' => 'raw',
            'value' => '$data["ResponID"]=="2"?"✓":""',
            'cssClassExpression' => '"no"',
            'htmlOptions'=>array('width'=>'40px'),
        
        ),
        array(
            'name' => 'Partially True',
            'type' => 'raw',
            'value' => '$data["ResponID"]=="3"?"✓":""',
            'cssClassExpression' => '"partially-true"',
            'htmlOptions'=>array('width'=>'40px'),

        
        ),
        array(
            'name' => 'Not applicable',
            'type' => 'raw',
            'value' => '$data["ResponID"]=="4"?"✓":""',
            'cssClassExpression' => '"not-applicable"',
            'htmlOptions'=>array('width'=>'40px'),

        
        ),
        array(
            'name' => 'Jawaban',
            
            'value' => '$data["Jawaban"]',

        ),
    )
));
And you can see the result here : You can use also "rowCssClassExpression" to use with different css color in CGridView row

Friday, July 27, 2012

Make underconstruction page in yiiframework

When you building a website you should have to think sometime when you are maintaining your website you should have to make your website off from the public.

And now to make that you can make a simple way to create under construction page

Here codes you can use in config main /protected/config/main.php. This trick does when you create empty file called underconstruction.txt in your root website.


return array(
  'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
  'name'=>'Your Site',
  'sourceLanguage'    =>'en_US',
  'language'          =>'en_US',
                'catchAllRequest' => (file_exists(dirname(__FILE__).'/../../underconstruction.txt')) ? 
die('<div style="text-align:center;line-height:300px;font-size:100px;>Under 
Construction</div>'): null,

That's code check all request to your yii site whether the file underconstruction.txt is exist or not in your root web directory. If it exist and then your website is under construction and view the message you have supply

Select random data from table in yiiframework

To random data some times we need it using logic of programming using variable but now I want to give you another short way to select random data from spesific table
Here some codes that you can try

$models=User::model()->findAll(array(
 'select'=>'*, rand() as rand',
 'limit'=>24,
 'order'=>'rand',
 )
);

From above code we can see that we fetch the table user using criteria. This codes give you a way to select all data with random position of order.

You can try that..

Friday, June 15, 2012

Make RadioButton List in Yii framework

Radio Button in yii framework is simple using radioButtonList function in CActiveForm. But how can we make a proper view to the design and get nice visual in yii.

This is how we can make a radiobutton list in yii with horizontal view. In the default the view will be vertical alignment.

And in your view just use this code like this :

<?php echo $form->radioButtonList($model,'GENDER',array('2'=>'Females','1'=>'Males'),array(
                'separator'=>'&nbsp;',
                 'labelOptions'=>array(
                           'style'=>'display: inline; margin-right: 10px; font-weight: normal;')
    )?>
That's all and you can make a better view of using radioButtonList in yiiframework.

Wednesday, May 30, 2012

Tiny Mce Errors in the server yiiframework

Maybe some of you that using tiny mce ever have an error when using tiny mce in the server like this in the firebugs:

"NetworkError: 500 Internal Server Error - http://example.com/assets/96646869/tiny_mce/tiny_mce_gzip.php?js=true&diskcache=true&core=true&suffix=&themes=advanced&plugins=safari%2Cpagebreak%2Cstyle%2Clayer%2Ctable%2Csave%2Cadvhr%2Cadvimage%2Cadvlink%2Cemotions%2Cspellchecker%2Cinlinepopups%2Cinsertdatetime%2Cpreview%2Cmedia%2Csearchreplace%2Cprint%2Ccontextmenu%2Cpaste%2Cdirectionality%2Cfullscreen%2Cnoneditable%2Cvisualchars%2Cnonbreaking%2Cxhtmlxtras%2Ctemplate&languages=en" 

Don't worry, this is the perrmission issue from your folder in the server. To solve the problems is simple
Add the permission folder recursively to 755.

For the example the folder begin from asset/96646869/tiny_mce

Change the all folder permissions to  755...

Good Luck

Sending email in yiiframework using yii-mail extensions

Sending email in a website is one of the main function to have interaction with the users and one of main features of the website.

For yii users maybe ever had error when sending the emails in the localhost with some kinds of warning.

The error maybe like this :

mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() 

It has caused because in the localhost there is no mail server so you can even send email. To solve this issue you must install mail server in your local computer such as hMailServer.

Or if you want to use the mail server from your provider you can use the SMTP configuration email from the provider.

Wednesday, April 18, 2012

Make ajax validation true in your captcha in yiiframework

Maybe you want to use your captcha in your yiiframwork to use in ajaxvalidation to be true. By default the setting may use you as ajaxvalidation false. But when you want to make it available to be in ajax validation true a little bit tricky you have to look.
Let's take alook the solution I get when digging the yii forum..

Thanks to the members there.


In the default form page in your yiiframework you should look like this :


<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
 'id'=>'user-form',
 'enableAjaxValidation'=>false,
        'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>