我有一个项目Yii。我从我的控制器调用模型来在表格中显示数据
$model = new NewAccForm();
$post = Post::model()->find($model);
var_dump($post);
我在错误上运行代码:
PHP warning include(Post.php) [<a href='function.include'>function.include</a>]: failed to open stream:
没有这样的文件或目录
E:\wamp\www\yii\framework\YiiBase.php(427) 415 { 416 include($classFile); 417 if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php') 418 throw new CException(Yii::t('yii','Class name "{class}" does not match class
file“{file}”。',array( 419'{class}'=&gt; $ className,
420 '{file}'=>$classFile, 421 ))); 422 break; 423 } 424 } 425 } 426 else 427 include($className.'.php'); 428 } 429 else // class name with namespace in PHP 5.3 430 { 431 $namespace=str_replace('\\','.',ltrim($className,'\\')); 432 if(($path=self::getPathOfAlias($namespace))!==false) 433 include($path.'.php'); 434 else 435 return false; 436 } 437 return class_exists($className,false) ||
interface_exists($的className,FALSE);
438 } 439 return true; Stack Trace #0 + E:\wamp\www\yii\framework\YiiBase.php(427): YiiBase::autoload() #1 unknown(0): YiiBase::autoload("Post") #2 – E:\wamp\www\yii\amica\protected\controllers\front\ReportController.php(10):
spl_autoload_call( “POST”) 05'1'=&gt;'Mới', 06'2'=&gt; 'ĐãXóa' 07); 08 public function actionIndex(){ 09 $ model = new ReportForm(); 10 $ post = Post :: model() - &gt; find($ model); 11 var_dump($ post); 12 echo“
Thôngbáolỗichobanquảntrị
”; 13} 14 15 public function actionCreate(){ #3
+ E:\ wamp \ www \ yii \ framework \ web \ actions \ CInlineAction.php(49):ReportController-&gt; actionIndex() #4
+ E:\ wamp \ www \ yii \ framework \ web \ CController.php(308):CInlineAction-&gt; runWithParams(array(“r”=&gt;“report”)) #5
+ E:\ wamp \ www \ yii \ framework \ web \ CController.php(286):CController-&gt; runAction(CInlineAction) #6
+ E:\ wamp \ www \ yii \ framework \ web \ CController.php(265):CController-&gt; runActionWithFilters(CInlineAction,array()) #7
+ E:\ wamp \ www \ yii \ framework \ web \ CWebApplication.php(282):CController-&gt; run(“”) #8
+ E:\ wamp \ www \ yii \ framework \ web \ CWebApplication.php(141):CWebApplication-&gt; runController(“report”) #9
+ E:\ wamp \ www \ yii \ framework \ base \ CApplication.php(180):CWebApplication-&gt; processRequest() #10
- E:\ wamp \ www \ yii \ amica \ protected \ components \ WebApplicationEndBehavior.php(24): CApplication-&gt;运行() 19 //附加changeModulePaths事件处理程序 20 //并提高它。 21 $ this-&gt; onModuleCreate = array($ this,'changeModulePaths'); 22 $ this-&gt; onModuleCreate(new CEvent($ this-&gt; owner)); 23 24 $ this-&gt; owner-&gt; run(); //运行应用程序 25} 26 27 //在CWebApplication时应该引发此事件 正在初始化28 //或CWebModule实例。 29公共函数onModuleCreate($ event){ #11
unknown(0):WebApplicationEndBehavior-&gt; runEnd(“front”) #12
+ E:\ wamp \ www \ yii \ framework \ base \ CComponent.php(261):call_user_func_array(array(WebApplicationEndBehavior,“runEnd”), 阵列( “前”)) #13
- E:\ wamp \ www \ yii \ amica \ index.php(13):CComponent-&gt; __ call(“runEnd”,array(“front”)) 08定义('YII_DEBUG')或定义('YII_DEBUG',真); 09 //指定每条日志消息中应显示多少级别的调用堆栈 10定义('YII_TRACE_LEVEL')或定义('YII_TRACE_LEVEL',3); 11 12 require_once($ yii); 13 Yii :: createWebApplication($ config) - &gt; runEnd('front'); #14
+ E:\ wamp \ www \ yii \ amica \ index.php(13):CWebApplication-&gt; runEnd(“front”)
为什么会出现这样的问题?以及如何解决它?感谢。
答案 0 :(得分:2)
发布::模型()
帖子模型应该在路径protected/models/Post.php
或您的模型Post use命名空间中,应该设置别名Yii::setPathOfAlias($alias,$path)
答案 1 :(得分:0)
检查文件名中的模型名称的拼写和models / Post.php中的类名,因为它区分大小写,第一个字符必须是大写字母。