Social Icons


Tuesday, April 30, 2013

Cgridview auto refresh Yii

My database is constantly changing because creating the new tickets from incoming mails.So want to show all these without refresh the current gridview so i create a new extension and posted under the Yii extension's location.

You can find the extension from here

Friday, April 26, 2013

Yii run Faster in localhost

Hi all,
I found this little trick to run faster your yiisite's debug in localhost.
It works well in my mysql-based app (Win 8, XAMPP 1.8.1, hosts file ok):

'connectionString' => 'mysql:host=localhost;dbname=university', //SLOW (average execution time: 1.13s)

'connectionString' => 'mysql:host=;dbname=university', //FAST (average execution time: 0.07s)

Thursday, April 25, 2013

How to upload a file using a model Yii

The Model 

First declare an attribute to store the file name in the model class (either a form model or an active record model). Also declare a file validation rule for this attribute to ensure a file is uploaded with specific extension name.
class Item extends CActiveRecord
    public $image;
    // ... other attributes
    public function rules()
        return array(
            array('image', 'file', 'types'=>'jpg, gif, png'),

The Controller 

Then, in the controller class define an action method to render the form and collect user-submitted data.
class ItemController extends CController
    public function actionCreate()
        $model=new Item;
                // redirect to success page
        $this->render('create', array('model'=>$model));

The View 

Finally, create the action view and generate a file upload field.
$form = $this->beginWidget(
        'id' => 'upload-form',
        'enableAjaxValidation' => false,
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
// ...
echo $form->labelEx($model, 'image');
echo $form->fileField($model, 'image');
echo $form->error($model, 'image');
// ...