Sunday, March 9, 2014

yii-create-cutom-application-component


In this tutoial , i will show you how to create a simple custom Application Component.

First of all create a file named simple with following codes and put the file in the path

protected/components/Simple.php


class Simple  extends CApplicationComponent
{

    public function init()
    {
echo 'Simple Initiated
';
    }

    public function message()
    {
      return 'Message from Simple';
    }
   
   
}


?>

do the following changes int the main.php under config folder

'components'=>array(
........
            'simple'=>array('class'=>'Simple'),
.........

),


Now its time to call method in the created component.

steps are,

echo Yii::app()->simple->message();


output is

Simple Initiated
Message from Simple

No comments:

Post a Comment