what's wrong with my yii code?

ManageModule is a module. Why is a php file?




PHP Error

include(ManageModule.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory 


G:\www\yii\yii\YiiBase.php(421)


409                 {

410                     foreach(self::$_includePaths as $path)

411                     {

412                         $classFile=$path.DIRECTORY_SEPARATOR.$className.'.php';

413                         if(is_file($classFile))

414                         {

415                             include($classFile);

416                             break;

417                         }

418                     }

419                 }

420                 else

421                     include($className.'.php');

422             }

423             else  // class name with namespace in PHP 5.3

424             {

425                 $namespace=str_replace('\\','.',ltrim($className,'\\'));

426                 if(($path=self::getPathOfAlias($namespace))!==false)

427                     include($path.'.php');

428                 else

429                     return false;

430             }

431             return class_exists($className,false) || interface_exists($className,false);

432         }

433         return true;

Stack Trace

#0  +

–

 G:\www\yii\yii\YiiBase.php(421): YiiBase::autoload() 

416                             break;

417                         }

418                     }

419                 }

420                 else

421                     include($className.'.php');

422             }

423             else  // class name with namespace in PHP 5.3

424             {

425                 $namespace=str_replace('\\','.',ltrim($className,'\\'));

426                 if(($path=self::getPathOfAlias($namespace))!==false)

 

#1   unknown(0): YiiBase::autoload("ManageModule")  

#2   unknown(0): spl_autoload_call("ManageModule")  

#3  +

–

 G:\www\yii\yii\i18n\CPhpMessageSource.php(99): ReflectionClass->__construct("ManageModule") 

094         {

095             if(($pos=strpos($category,'.'))!==false)

096             {

097                 $moduleClass=substr($category,0,$pos);

098                 $moduleCategory=substr($category,$pos+1);

099                 $class=new ReflectionClass($moduleClass);

100                 $this->_files[$category][$language]=dirname($class->getFileName()).DIRECTORY_SEPARATOR.'messages'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.$moduleCategory.'.php';

101             }

102             else

103                 $this->_files[$category][$language]=$this->basePath.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.$category.'.php';

104         }

 

#4  +

–

 G:\www\yii\yii\i18n\CPhpMessageSource.php(116): CPhpMessageSource->getMessageFile("ManageModule.user", "zh_cn") 

111      * @param string $language the target language

112      * @return array the loaded messages

113      */

114     protected function loadMessages($category,$language)

115     {

116         $messageFile=$this->getMessageFile($category,$language);

117 

118         if($this->cachingDuration>0 && $this->cacheID!==false && ($cache=Yii::app()->getComponent($this->cacheID))!==null)

119         {

120             $key=self::CACHE_KEY_PREFIX . $messageFile;

121             if(($data=$cache->get($key))!==false)

 

#5  +

–

 G:\www\yii\yii\i18n\CMessageSource.php(102): CPhpMessageSource->loadMessages("ManageModule.user", "zh_cn") 

097      */

098     protected function translateMessage($category,$message,$language)

099     {

100         $key=$language.'.'.$category;

101         if(!isset($this->_messages[$key]))

102             $this->_messages[$key]=$this->loadMessages($category,$language);

103         if(isset($this->_messages[$key][$message]) && $this->_messages[$key][$message]!=='')

104             return $this->_messages[$key][$message];

105         else if($this->hasEventHandler('onMissingTranslation'))

106         {

107             $event=new CMissingTranslationEvent($this,$category,$message,$language);

 

#6  +

–

 G:\www\yii\yii\i18n\CMessageSource.php(84): CMessageSource->translateMessage("ManageModule.user", "Email", "zh_cn") 

79     public function translate($category,$message,$language=null)

80     {

81         if($language===null)

82             $language=Yii::app()->getLanguage();

83         if($this->forceTranslation || $language!==$this->getLanguage())

84             return $this->translateMessage($category,$message,$language);

85         else

86             return $message;

87     }

88 

89     /**

 

#7  +

–

 G:\www\yii\yii\YiiBase.php(578): CMessageSource->translate("ManageModule.user", "Email", null) 

573         if(self::$_app!==null)

574         {

575             if($source===null)

576                 $source=($category==='yii'||$category==='zii')?'coreMessages':'messages';

577             if(($source=self::$_app->getComponent($source))!==null)

578                 $message=$source->translate($category,$message,$language);

579         }

580         if($params===array())

581             return $message;

582         if(!is_array($params))

583             $params=array($params);

 

#8  +

– G:\www\lee\protected\models\LoginForm.php(40): YiiBase::t("ManageModule.user", "Email", 2) 

35      * Declares attribute labels.

36      */

37     public function attributeLabels()

38     {

39         return array(

40             'Email'=>Yii::t('ManageModule.user', 'Email',2),

41             'Password'=>Yii::t('ManageModule.user', 'Password',2),

42         );

43     }

44 

45     /**

 

#9  +

–

 G:\www\yii\yii\base\CModel.php(330): LoginForm->attributeLabels() 

325      * @see generateAttributeLabel

326      * @see attributeLabels

327      */

328     public function getAttributeLabel($attribute)

329     {

330         $labels=$this->attributeLabels();

331         if(isset($labels[$attribute]))

332             return $labels[$attribute];

333         else

334             return $this->generateAttributeLabel($attribute);

335     }

 

#10  +

–

 G:\www\yii\yii\validators\CValidator.php(240): CModel->getAttributeLabel("Email") 

235      * @param string $message the error message

236      * @param array $params values for the placeholders in the error message

237      */

238     protected function addError($object,$attribute,$message,$params=array())

239     {

240         $params['{attribute}']=$object->getAttributeLabel($attribute);

241         $object->addError($attribute,strtr($message,$params));

242     }

243 

244     /**

245      * Checks if the given value is empty.

 

#11  +

–

 G:\www\yii\yii\validators\CRequiredValidator.php(59): CValidator->addError(LoginForm, "Email", "{attribute} 不可为空白.") 

54             }

55         }

56         else if($this->isEmpty($value,true))

57         {

58             $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} cannot be blank.');

59             $this->addError($object,$attribute,$message);

60         }

61     }

62 

63     /**

64      * Returns the JavaScript needed for performing client-side validation.

 

#12  +

–

 G:\www\yii\yii\validators\CValidator.php(192): CRequiredValidator->validateAttribute(LoginForm, "Email") 

187         else

188             $attributes=$this->attributes;

189         foreach($attributes as $attribute)

190         {

191             if(!$this->skipOnError || !$object->hasErrors($attribute))

192                 $this->validateAttribute($object,$attribute);

193         }

194     }

195 

196     /**

197      * Returns the JavaScript needed for performing client-side validation.

 

#13  +

–

 G:\www\yii\yii\base\CModel.php(152): CValidator->validate(LoginForm, null) 

147         if($clearErrors)

148             $this->clearErrors();

149         if($this->beforeValidate())

150         {

151             foreach($this->getValidators() as $validator)

152                 $validator->validate($this,$attributes);

153             $this->afterValidate();

154             return !$this->hasErrors();

155         }

156         else

157             return false;

 

#14  +

– G:\www\lee\protected\modules\User\controllers\DefaultController.php(97): CModel->validate() 

092               {

093                 echo CActiveForm::validate($model);

094                 Yii::app()->end();

095                }

096     

097             if($model->validate())

098             {

099                $this->redirect($this->createUrl('Default/Main'));

100                 return;

101                 }

102         }

 

#15  +

–

 G:\www\yii\yii\web\actions\CInlineAction.php(50): DefaultController->actionLogin() 

45         $controller=$this->getController();

46         $method=new ReflectionMethod($controller, $methodName);

47         if($method->getNumberOfParameters()>0)

48             return $this->runWithParamsInternal($controller, $method, $params);

49         else

50             return $controller->$methodName();

51     }

52 

53 }

 

#16  +

–

 G:\www\yii\yii\web\CController.php(300): CInlineAction->runWithParams(array("r" => "User/default/Login")) 

295     {

296         $priorAction=$this->_action;

297         $this->_action=$action;

298         if($this->beforeAction($action))

299         {

300             if($action->runWithParams($this->getActionParams())===false)

301                 $this->invalidActionParams($action);

302             else

303                 $this->afterAction($action);

304         }

305         $this->_action=$priorAction;

 

#17  +

–

 G:\www\yii\yii\web\CController.php(278): CController->runAction(CInlineAction) 

273      * @see runAction

274      */

275     public function runActionWithFilters($action,$filters)

276     {

277         if(empty($filters))

278             $this->runAction($action);

279         else

280         {

281             $priorAction=$this->_action;

282             $this->_action=$action;

283             CFilterChain::create($this,$action,$filters)->run();

 

#18  +

–

 G:\www\yii\yii\web\CController.php(257): CController->runActionWithFilters(CInlineAction, array()) 

252         {

253             if(($parent=$this->getModule())===null)

254                 $parent=Yii::app();

255             if($parent->beforeControllerAction($this,$action))

256             {

257                 $this->runActionWithFilters($action,$this->filters());

258                 $parent->afterControllerAction($this,$action);

259             }

260         }

261         else

262             $this->missingAction($actionID);

 

#19  +

–

 G:\www\yii\yii\web\CWebApplication.php(277): CController->run("Login") 

272         {

273             list($controller,$actionID)=$ca;

274             $oldController=$this->_controller;

275             $this->_controller=$controller;

276             $controller->init();

277             $controller->run($actionID);

278             $this->_controller=$oldController;

279         }

280         else

281             throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',

282                 array('{route}'=>$route===''?$this->defaultController:$route)));

 

#20  +

–

 G:\www\yii\yii\web\CWebApplication.php(136): CWebApplication->runController("User/default/Login") 

131             foreach(array_splice($this->catchAllRequest,1) as $name=>$value)

132                 $_GET[$name]=$value;

133         }

134         else

135             $route=$this->getUrlManager()->parseUrl($this->getRequest());

136         $this->runController($route);

137     }

138 

139     /**

140      * Registers the core application components.

141      * This method overrides the parent implementation by registering additional core components.

 

#21  +

– G:\www\yii\yii\base\CApplication.php(158): CWebApplication->processRequest() 

153      */

154     public function run()

155     {

156         if($this->hasEventHandler('onBeginRequest'))

157             $this->onBeginRequest(new CEvent($this));

158         $this->processRequest();

159         if($this->hasEventHandler('onEndRequest'))

160             $this->onEndRequest(new CEvent($this));

161     }

162 

163     /**

 

#22  +

– G:\www\lee\index.php(13): CApplication->run() 

08 defined('YII_DEBUG') or define('YII_DEBUG',true);

09 // specify how many levels of call stack should be shown in each log message

10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

11 

12 require_once($yii);

13 Yii::createWebApplication($config)->run();

 


2011-08-14 10:21:40 Apache/2.2.17 (Win32) PHP/5.3.5 Yii Framework/1.1.8 



how to solve it? :o

:-[

The error message says ManageModule.php cannot be found.

You can include the directory in question in your configuration file, or you can explicitly include the script in LoginForm.php. (Perhaps it may instead be possible to add the complete path alias to each Yii::t() call in the attributeLabels array, preferrably through a variable to save typing ;) .) (Edit2: Turns out it’s not supported in CPhpMessageSource::getMessageFile() )

Edit: Since parameter 1 of Yii::t() is “message category” and according to the source code, it will have CPhpMessageSource look for a file with that name in the protected/messages/<requested_language> directory. It’s perfectly alright to specify a module in the category parameter. I should have known since it’s documented in the I18N section of the guide :-[ .

/Tommy

Did you add it to your config? Can we see that?

This is my config, I has alreay set modules in the main.php!




return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'web site',

	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

 		'application.modules.Image.components.*',

        'application.modules.Image.models.Image',

	),


	'modules'=>array(

		// uncomment the following to enable the Gii tool

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'11111',

		 	// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

		),

		 

		'Manage',

		'User',

		'Image'=>array(

                'createOnDemand'=>true, // requires apache mod_rewrite enabled

                'install'=>false, // allows you to run the installer

        ),

		

	),



I feel the error is in the model:





	public function attributeLabels()

	{

		return array(

			'Id' => 'ID',

			'UName' => Yii::t('ManageModule.user', 'Uname',1),

			'Email' => Yii::t('ManageModule.user', 'EmailAddress'),

			'Password' => Yii::t('ManageModule.user', 'PassWord',1),

			'Score' => Yii::t('ManageModule.user', 'Score',1),

			'UserType' => Yii::t('ManageModule.user', 'UserType',1),

			'UserGroup' => Yii::t('ManageModule.user', 'UserGroup',1),

			'State' => Yii::t('ManageModule.user', 'State',1),

		);

	}




the translate is error~~~~ ::)

thanks for your reply and how to solve it ?

:unsure:

:-[

Beware, I’ve never used Yii I18N this way and I don’t know the semantics of the module config you use.

From the I18N section of the guide.

Specifically this

So if the component of your module is application.modules.Image.models.Image corresponding to protected/modules/Image/models/Image.php (which doesn’t seems to make sense since that directory should contain models only on second thought: why not), according to the quoted text, you should put the translation category file user.php in subdirectory protected/modules/Image/models/messages/<your_language>/

But my guess is that you have mixed up models and translation files here.


Edit:

Had a look at the error message again.

and

What about ManageModule? It’s not mentioned in the import section of your config. Please change the paths I suggested above accordingly (Image was a wrong assumption, I forgot to reread the error message before answering).

/Tommy