CakePHP致命错误调用非对象上的成员函数schema()
发布时间:2020-12-13 18:18:08 所属栏目:PHP教程 来源:网络整理
导读:我找到一个解决方案有点麻烦.. Error: Call to a member function schema() on a non-objectFile: /Cake/Model/Model.phpLine: 3627 在我的数据库中有表格文章,主题标签和关联articles_hashtags与foreignkeys article_id和hashtag_id ..所以我想知道每篇文章
我找到一个解决方案有点麻烦..
Error: Call to a member function schema() on a non-object File: /Cake/Model/Model.php Line: 3627 在我的数据库中有表格文章,主题标签和关联articles_hashtags与foreignkeys article_id和hashtag_id ..所以我想知道每篇文章有哪些主题标签.. 我的文章模型 class Article extends AppModel { public $hasAndBelongsToMany = array( 'Hashtag' => array( 'className' => 'Hashtag','joinTable' => 'articles_hashtags','foreignKey' => 'article_id','associationForeignKey' => 'hashtag_id','unique' => true,'conditions' => '','fields' => '','order' => '','limit' => '','offset' => '','finderQuery' => '','with' => '' ) ); } 文章管理员 class ArticleController extends AppController { var $name = 'Article'; public $helpers = array("Html","Form"); public function index() { $this->set("posts",$this->Article->find("all")); } } 谢谢你的帮助!! 另外:
我有同样的问题,所以可以将$hasAndBelongsToMany剥离到最小键.
问题是你在$hasAndBelongsToMany数组上使用’with’键.删除它或将其设置为’articles_hashtags’: class Article extends AppModel { public $hasAndBelongsToMany = array( 'Hashtag' => array( 'className' => 'Hashtag','with' => 'articles_hashtags' ) ); } 库模型代码试图访问’with’键的值,该键为空,因此是非对象错误. From CakePHP docs,关于$hasAndBelongsToMany数组:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |