Saturday, October 18, 2014

Create custom class and function in yii

first open 'folder/protected/components' and create CustomClass.php add this code inside CustomClass.php , after this no more tweaking is needed. CustomClass will automatically be loaded in our system.
class CustomClass 
{
 function test() { 
  echo 'The class work';
 } 
}

to call our custom function we can simply use this code
<div>
 hello,  <?php CustomClass::test(); ?>
</div>

Seperating our custom function is a good idea if we are planning to use several function rather than combining it with other php files.

No comments:

Post a Comment