【问题标题】:Call to undefined method ActiveRecord\Config::initialise() composer调用未定义的方法 ActiveRecord\Config::initialise() composer
【发布时间】:2014-03-05 12:17:44
【问题描述】:

大家好,我正在学习 Composer 教程,我已经安装了 ActiveRecord,并且正在尝试创建一个数据库模型。每当我加载页面时,都会收到此错误:调用未定义的方法 ActiveRecord\Config::initialise()

这是我在 index.php 中的设置文件

require_once "vendor/php-activerecord/php-activerecord/ActiveRecord.php";

ActiveRecord\Config::initialise(function($cfg) {

    //setting up a model (which is the representation of a table) 
    $cfg->set_model_directory('models');
    $cfg->set_connections(array(
        'development' => 'mysql://root:tutsplus@localhost/blog'
    ));
});

$posts = Post::all();   
print_r($posts);

?>

这里是我声明 Post 的地方

class Post extends ActiveRecord\Model{}

我真的找不到这不起作用的原因,我实际上这样做是为了看看手动创建一个新的 Post 实例是否可以解决初始化问题,但它没有,它有完全相同的错误:

$post_class = new Post;
$posts = $post_class->all();    
print_r($posts);

我真的被这个难住了,我通常设法在这里找到解决我的问题的东西,但这只是不行。我可以看到的教程代码实际上没有区别,我已经检查了很多次。任何帮助将不胜感激。

(编辑:顶部重复的 php-activerecord 文件夹不是代码问题,该文件夹实际上是重复的,我还没有开始移动内容)

【问题讨论】:

    标签: php class activerecord composer-php


    【解决方案1】:

    第一点:在使用 Composer 时,您应该只包含“vendor/autoload.php”,不要包含其他内容。 Composer 会为您完成其余的自动加载工作。

    第二点:它被称为 initialize,带有 Z,而不是 S。您可能只是拼错了该方法名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-10
      • 2015-08-11
      • 2017-12-17
      • 1970-01-01
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多