Fatal error: Cannot redeclare class NewsModel

放肆的年华 提交于 2019-12-06 08:17:04
Nunser

Well, the class should be "News", without the model part.

class News extends AppModel { }

The docs show examples everywhere. There may be confusion because the "News" Controller is called NewsController and the News Component, NewsComponent, but from the answer I got here, it's to avoid name collision (which gives you a do'h moment after you read it).

For future development, I find it easier just to bake the models/controllers/views and then delete what I don't need and change what I need changed.

try using var $useTable = 'news'; in your model.. Hopefully your problem will solve.

Model should be singular to better fit cake convetions

<?php
App::uses('AppModel', 'Model');
class New extends AppModel {

}
?>

$news = $this->New->find('all');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!