CakePHP致命错误调用非对象上的成员函数schema()

前端之家收集整理的这篇文章主要介绍了CakePHP致命错误调用非对象上的成员函数schema()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我找到一个解决方案有点麻烦..
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"));

    } 
}

谢谢你的帮助!!

另外:
如果我将生成sql select查询从调试器sql日志放入我的sql数据库中,我得到了正确的结果..所以我猜控制器出了问题?!

我有同样的问题,所以可以将$hasAndBelongsToMany剥离到最小键.

问题是你在$hasAndBelongsToMany数组上使用’with’键.删除它或将其设置为’articles_hashtags’:

class Article extends AppModel {
  public $hasAndBelongsToMany = array(
    'Hashtag' =>
        array(
            'className' => 'Hashtag','with' => 'articles_hashtags'
        )  
      ); 
   }

库模型代码试图访问’with’键的值,该键为空,因此是非对象错误.

From CakePHP docs,关于$hasAndBelongsToMany数组:

  • with: Defines the name of the model for the join table. By default CakePHP will auto-create a model for you. Using the example above it would be called IngredientsRecipe. By using this key you can override this default name. The join table model can be used just like any “regular” model to access the join table directly. By creating a model class with such name and filename,you can add any custom behavior to the join table searches,such as adding more information/columns to it.
原文链接:https://www.f2er.com/php/135306.html

猜你在找的PHP相关文章