Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Thursday, July 5, 2012

Getting action/controller/module name in Yii

Some times we need to know the current controller/module/action name in our application, Yii provides the default methods to accomplish the tasks.

To get a controller name
Yii::app()->controller->id //or
Yii::app()->getController()->getId()
$this->id  here $this refers to current controller 

To get method/action name
Yii::app()->controller->action->id
You can get action name in controller
$this->action->id

To get module name
Yii::app()->controller->module->id
$this->module->id

Monday, August 8, 2011

Deleting files in server without any error using php

To delete files in server and avoid "denied access to file" error to unlink file.

To delete file, you must to change file's owernship .

An example:

<?php
chown($TempDirectory."/".$FileName,666);
unlink($TempDirectory."/".$FileName);
?>

Enable GZIP in YII Application

Just add the following lines to protected/config/main.php,

add the below 2 lines after   'preload' => array('log'),

'onBeginRequest' => create_function('$event', 'return ob_start("ob_gzhandler");'),
'onEndRequest' => create_function('$event', 'return ob_end_flush();'),