Reputation: 95
i am new in yii framework. currently i am using yii 1.1. now i want to create custom components and we can say than create global function which is use anywhere in the application. According to this url 'http://www.yiiframework.com/wiki/727/updated-how-to-create-call-custom-global-function-in-whole-application/'
i am follow all steps according to above url but i have occur a error Alias "ext.components.MyClass" is invalid. Make sure it points to an existing PHP file and the file is readable.
MyClass.php in the components folder
class MyClass extends CApplicationComponent {
public function get_my_info() {
$value = '1';
return $value;
}
}
Declare in the config folder
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'myClass' => array(
'class' => 'ext.components.MyClass',
),
And use in the view file
<?php
$myInfo = Yii::app()->myClass->get_my_info();
echo $myInfo;
?>
Upvotes: 3
Views: 2094
Reputation: 4283
Have you put the file in correct component directory?. As per your alias the path should be /protected/extensions/components/MyClass.php
Upvotes: 3