Basic use of Kohana framework ORM Class, Kohana framework orm_php Tutorial

Source: Internet
Author: User
Tags map class kohana

Basic use of the Kohana framework ORM Class, Kohana framework Orm


1. First, you need to create a model class, in the case of the user,application/classes/model/user.php路径下创建user.php,并且一个表对应一个模型,且表名必须在类名后加“S”,即表名应该为users,在这个文件中,需要继承ORM类:

 
  extends orm{    ... }?>

Create an ORM instance on the controller (the access method must be prefixed with "Action_", The inherited class "Controller_admin" is for the convenience of the control of the permissions):

 
  PHPclassextends  controller_admin{    publicfunction  action_ Test ()    {        $user = orm::factory (' user ');
Insert
$user->name = ' Tina ';
$user->age = ' 22 ';
$user->save ();
Query the record, get the result is an object
$result = orm::factory (' user ')->where (' id ', ' = ', 1)->find ();
Update, where the second parameter is the Primary_key of the table users, equivalent to Orm::factory (' user ')->where (' id ', ' = ', 1)->find ();
$user _update = orm::factory (' user ', 1);
The loaded method determines whether the load
if ($user _update->loaded ()) {
$user _update->name = ' Jack ';
$user _update->save ();
}
Delete
orm::factory (' user ', 1)->delete (); }}? >


What is the ORM framework and what is the specific usage

ORM-that is object/relation Mapping
For detailed instructions see: baike.baidu.com/view/197951.htm

Presumably, this type of framework is designed to map class objects and relationships, creating a middle tier between application and database Io, and simply manipulating objects directly in the program (adding and removing objects from the database) rather than worrying about the columns of the tables in the database, relationships, whatever.

As an example:
Used to be a person at home to eat, need to buy rice to buy their own food, and then do their own, finished also have to clean up, feel good trouble, but also have to do, no way ah, bitter single-
This is equivalent to the traditional operating relationship (not using ORM);
And finally one day, found to eat in a restaurant is very convenient, do not worry about buying vegetables ah what, also do not worry about eating finish also have to pack a lot of what, order good food, eat good pay to leave on the line-what cook cooking things have someone else to do, specific people how to do, do not have tube--
This restaurant is the equivalent of an ORM mapping framework, for you to deal with those tedious and boring things, only the most important part--eat--let you do
And ordering is the equivalent of you do ORM mapping configuration, you tell the restaurant you want to eat something, the restaurant will be according to your needs to prepare for the dishes, ready to send you up!

How to configure PHP Kohana framework after download?

Not found modpath\\database\\classes\\kohana\\db.php [+] * @param Please specify how you call database or ORM in the process, or the method you are calling.

http://www.bkjia.com/PHPjc/877841.html www.bkjia.com true http://www.bkjia.com/PHPjc/877841.html techarticle the basic use of the Kohana framework ORM class, the Kohana framework ORM 1. You first need to create a model class, take the user as an example, create a user.php under the application/classes/model/user.php path, and a ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.