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'),
)); ?>
 

Set default page in Clistview or CGridview in the last page yiiframework

By default default page of Clistview or Cgridview only set to the front of clistview or in the first page as default page. But when you want to use the last page as your default page to be viewed to user you have to modified the pagination in the data provider. You can use this to show when you are using the clistview or component that has the pagination object like others. Maybe you can use this as default discussion thread.

Let's take a look the code that you should have to write down.

if(Yii::app()->request->isAjaxRequest){
 $dataProvider=new CActiveDataProvider('KomentarThread',array(
   'criteria'=>array(
     'condition'=>'ID_THREAD=:id_thread',
     'params'=>array(':id_thread'=>$model->ID_THREAD)
   )
 ));
 $p=$dataProvider->pagination;
 $p->setItemCount($dataProvider->getTotalItemCount());
 $p->currentPage=$p->pageCount-1;
 $this->renderPartial('/komentarThread/_comments_all',array(
   'all_komentar'=>$dataProvider)
   ,false,true);
 Yii::app()->end();
}

The part of $p variable is to set your currentPage to the last page.

So enjoy your modification of your data provider...