【发布时间】: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