我正在尝试活动记录。我相信这是一个很棒的 ORM,但是我无法让它运行。
有些方法有效,但其他方法无效 例如
<?php
$user=new user();
foreach(user::find('all') AS $row) {
echo "$row->username <br>"; //this works fine.
}
但是,当提供选项或使用 validates_uniqueness_of 时,会引发异常:
foreach (user::find('all','order'=>"created DESC ,'limit'=>10")) {
echo "$row->username <br>";
这导致
Fatal error: Uncaught exception 'ActiveRecord\RecordNotFound'
...带有消息...
Couldn't find all user with IDs (all,created DESC ,'limit'=>10) (found 0, but was looking for 2)
我正在使用 php 5.3.4 并使用夜间构建(2013 年 5 月 8 日)请告知如何解决此问题。
/*------------------------edit : full code----------------*/
$path_to_AR = "AR/";
include $path_to_AR . "activerecord.php";
ActiveRecord\Config::initialize(function($cfg) {
$cfg->set_model_directory('model');
$cfg->set_connections(
array(
'development' => 'mysql://root:asdf@localhost/test_ar',
'test' => 'mysql://username:password@localhost/test_database_name',
'production' => 'mysql://username:password@localhost/production_database_name'
)
);
});
$user = new user(); //class user extends ActiveRecord\Model {}
foreach (user::find(array('all','conditions'=>"username LIKE '%ohn%'")) AS $row) {
echo "Username:$row->username<br>";
}