Kohana::ORM学习

ORM::将数据表对象化。

最常用的四个字段:

_db_group

_belongs_to:和_has_many组合,可以实现表联接查询。(->with('modelalias'))

_has_many

_table_name

插入:

$posts=ORM::factory('Posts');
$posts->user_id=4;
$posts->label_id=1;
$posts->title="asdfas";
$posts->content="dasb";
$posts->save();
echo "haha";

查找:

1,最简单的查找:

        $posts=ORM::factory('Posts');
        echo $posts->where('id','=','1')->find()->title;

进阶部分:

   find_all() 返回的是一个Database_MySQLi_Result对象,该对象可以被遍历。

   find()返回的是一个Model_Posts对象,该对象不能被遍历。

原文地址:https://www.cnblogs.com/canbefree/p/3678917.html