0

I have a project Yii. I call model from my controller to display data in a table

$model = new NewAccForm();
$post = Post::model()->find($model);
var_dump($post);

I run the code on an error:

 PHP warning

include(Post.php) [<a href='function.include'>function.include</a>]: failed to open stream:

No such file or directory

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}'=>$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'=>'Mới', 06 '2' => 'Đã Xóa' 07 ); 08 public function actionIndex() { 09 $model = new ReportForm(); 10 $post = Post::model()->find($model); 11 var_dump($post); 12 echo "

Thông báo lỗi cho ban quản trị

"; 13 } 14 15 public function actionCreate() { #3
+ E:\wamp\www\yii\framework\web\actions\CInlineAction.php(49): ReportController->actionIndex() #4
+ E:\wamp\www\yii\framework\web\CController.php(308): CInlineAction->runWithParams(array("r" => "report")) #5
+ E:\wamp\www\yii\framework\web\CController.php(286): CController->runAction(CInlineAction) #6
+ E:\wamp\www\yii\framework\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array()) #7
+ E:\wamp\www\yii\framework\web\CWebApplication.php(282): CController->run("") #8
+ E:\wamp\www\yii\framework\web\CWebApplication.php(141): CWebApplication->runController("report") #9
+ E:\wamp\www\yii\framework\base\CApplication.php(180): CWebApplication->processRequest() #10
– E:\wamp\www\yii\amica\protected\components\WebApplicationEndBehavior.php(24): CApplication->run() 19 // Attach the changeModulePaths event handler 20 // and raise it. 21 $this->onModuleCreate = array($this, 'changeModulePaths'); 22 $this->onModuleCreate(new CEvent($this->owner)); 23 24 $this->owner->run(); // Run application. 25 } 26 27 // This event should be raised when CWebApplication 28 // or CWebModule instances are being initialized. 29 public function onModuleCreate($event) { #11
unknown(0): WebApplicationEndBehavior->runEnd("front") #12
+ E:\wamp\www\yii\framework\base\CComponent.php(261): call_user_func_array(array(WebApplicationEndBehavior, "runEnd"), array("front")) #13
– E:\wamp\www\yii\amica\index.php(13): CComponent->__call("runEnd", array("front")) 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)->runEnd('front'); #14
+ E:\wamp\www\yii\amica\index.php(13): CWebApplication->runEnd("front")

why is there such a problem? and how to fix it? Thanks.

2 Answers 2

1

Post::model()

Post model should be in path protected/models/Post.php or your model Post use namespace, than you should will set alias of Yii::setPathOfAlias($alias,$path)

Sign up to request clarification or add additional context in comments.

Comments

0

Check the spelling of the model name in the file name and the class name inside models/Post.php because it's case sensitive, the first character must be capital letter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.