2011-04-14 92 views
0

我想使用来自http://www.redbeanphp.com的预打包单文件Redbean 1.3 ORM。当我试图得到一个结果,这样..预包装Redbean只提取一个(最后一个)行

require_once ('redbean/rb.php'); 
require_once ('config.php'); 

R::setup('mysql:host='.MYSQL_HOST.';dbname=mydb', MYSQL_USER, MYSQL_PASS); 
$test = R::find('function', ' ID < 10 '); 
foreach ($test as $val) echo $val->Class.'<br>'; 

输出如下:

Notice: Undefined index: id in rb.php on line 3686 

Notice: Undefined index: id in rb.php on line 3686 

Notice: Undefined index: id in rb.php on line 3686 
value.of.class.field.from.function.table // << prints only the 9th value 

正如你可以看到我只得到即使有条目的最后一行的结果ID 1到xxx。当我将where子句设置为ID < 9时,我只打印出第8行。

任何想法,为什么?或者任何无配置的红豆的替代品?

回答

2

RedBeanPHP的ID区分大小写,您需要使用'id'而不是ID。或者你必须使用一个Bean格式化,以确保RedBeanPHP知道你要使用的ID作为主键:

http://www.redbeanphp.com/#/Custom_Keys

0

您可以将您的表的主键,重命名为“ID”,然后红豆可以识别它。如果你不希望改变您的模式一样,那么你必须格式化bean并返回相应的自定义ID:

class MyTableFormatter implements RedBean_IBeanFormatter{ 
    public function formatBeanTable($table) { 
      return $table; 
    } 
    public function formatBeanID($table) { 
      if ($table=="user") return "user_id"; 
      return "id"; 
    } 
} 

R::$writer->tableFormatter = new MyTableFormatter; 
$user = R::find("user"); 

代码编号:https://groups.google.com/forum/#!topic/redbeanorm/weIEM8p71eQ