posted by BornToDrink on April 10, 2012
Encoding problems with strftime can be solved with one additional string to setlocale() second parameter - .UTF8


setlocale(LC_ALL, 'bg_BG.UTF8');
echo(strftime("%d %B %Y"));


posted by BornToDrink on April 5, 2012
I found that if I use custom "select", it's not respected and calculation of the pages is not correct in some cases.
If we have:


$criteria->select = 'SUM(some_column), ..'


This will affect the rows number and since the "select" is not used to calculate totalItemCount, pages and items number will mismatch.

The solution is to overwrite totalItemCount:


public function search()
{
    $criteria=new CDbCriteria;
    $criteria->select = 'SUM(col)';

    $dataProvider = new CActiveDataProvider($this, array('criteria'=>$criteria));
    $dataProvider->setTotalItemCount(count($this->findAll($criteria)));
    return $dataProvider;
}


Yii Forum topic

posted by BornToDrink on March 31, 2012
Since AR public properties are fetched from DB each time while using the model, this can cause additional workload for the web server which is actually not needed for production mode.
Database schema can be cached like in the following example:

Yii database config:

'db'=>array(
    ...
    'schemaCachingDuration'=>86400, // time in seconds
    ...
),


Enable Yii cache:


'cache'=>array(
    'class' => 'CFileCache',
),

posted by BornToDrink on March 28, 2012
To use layouts directly from module directory, you need to change two settings:
1. In controller, declare the layout with only one slash:

public $layout = '/layouts/column1';

2. In layout (column1, column2 etc), main view should be called again with single slash:

beginContent('/layouts/main'); ?>