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..