I'm trying to use an external action class with no luck.
Class file MyAction.php:
class MyAction extends CAction
{
public function run()
{
...
}
}
SiteController.php:
public function actions()
{
return array(
'myaction'=>array('class'=>'application.controllers.site.MyAction'),
);
}
Source:
srv/www/htdocs/Yii/framework/YiiBase.php(270)
00258: * Class autoload loader.
00259: * This method is provided to be invoked within an __autoload() magic method.
00260: * @param string class name
00261: */
00262: public static function autoload($className)
00263: {
00264: // use include_once so that the error PHP file may appear
00265: if(isset(self::$_coreClasses[$className]))
00266: include_once(YII_PATH.self::$_coreClasses[$className]);
00267: else if(isset(self::$_classes[$className]))
00268: include_once(self::$_classes[$className]);
00269: else
00270: include_once($className.'.php');
00271: }
00272:
If I place a copy of the file in the top directory (public) it seems like both files are found and dumped to the browser!? Same behavior with latest rev. (r318).
Could you please double check your action class? According to the call stack, it seems the class file doesn't contain the needed class (maybe the file name is not exactly the same as the class name?)
I had to add an explicit import element to config. Now I get this:
class MyAction extends CAction { public function run() { Yii::trace('MyAction'); } } Fatal error: Class 'MyAction' not found in /srv/www/htdocs/Yii/framework/collections/CConfiguration.php(138) : eval()'d code on line 1
Doc suggestion (IIRC): explain how to import specific files (eg. no .php extension).
Yes, currently openSUSE 11 with PHP 5.2.6. Yii 1.0 framework.
The directories are all lowercase. MyAction.php is located in protected/controllers/site subdir. I've also tried all lowercase for filename and class name. It seems like the file is found (all content is present in the error message).
I'm not so familiar with PHP especially not ver 4/5, but it seems to me like something goes wrong in the eval() call. According to my PHP doc spl_autoload looks for a filename in lowercase. So I tried to have both MyAction.php and myaction.php present beside each other in the /site subdir, but still the same.
Glad you found the problem. I use C/C++ during worktime. It is powerful, but it also often traps you into minor details. Using script languages (not necessarily PHP) can free you from those things and concentrate on algorithms.