2011-04-14 35 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