Basic use of the 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. The basic usage of the Kohana framework ORM class. the kohana framework orm1. first needs to create a model class. take the user as an example, in applicationclassesmodeluser. create a user in the php path. php, and basic use of a Kohana framework ORM class, kohana framework orm

1. create a model class first. take the user as an example.Application/classes/model/user. create a user in the php path. php, and a table corresponds to a model, and the table name must be added "S" after the class name, that is, the table name should be users. in this file, you must inherit the ORM class:

 

Create an ORM instance in the controller (the access method must be prefixed with "action _", and the inherited class "Controller_Admin" is used to facilitate permission control ):

 // Insert
$ User-> name = 'Tina ';
$ User-> age = '22 ';
$ User-> save ();
// Query records. The result is an object.
$ Result = ORM: factory ('user')-> where ('id', '=', 1)-> find ();
// Update. The second parameter is the primary_key of the users table, which is equivalent to ORM: factory ('user')-> where ('id', '=', 1) -> find ();
$ User_update = ORM: factory ('user', 1 );
// Determine whether to load the loaded method
If ($ user_update-> loaded ()){
$ User_update-> name = 'Jack ';
$ User_update-> save ();
}
// Delete
ORM: factory ('user', 1)-> delete () ;}}?>


What is the ORM framework and its specific usage?

ORM-Object/Relation Mapping
For more information, see baike.baidu.com/view/197951.htm.

Generally speaking, this type of framework is used to map class objects and relationships, and establish an intermediate layer between application programs and database IO, in a program, you only need to directly operate on objects (adding, deleting, modifying, and querying objects in the database), instead of worrying about columns and relationships in tables in the database.

For example:
I used to eat at home by myself. I had to buy rice for food, and then I did it myself. I had to clean up after I had done it. I felt very troublesome, but I had to do it too. I couldn't help it. I was a single man --
This is equivalent to the traditional operational relationship (not using ORM );
One day, I found it very convenient to eat at a restaurant. I don't have to worry about buying food or anything, and I have to pick up a lot of food after I finish eating it, you just need to pay for your food and leave the house.-anyone else can cook and cook food. you don't have to worry about how people do it --
This restaurant is equivalent to an ORM ing framework. it handles tedious and boring things for you and only takes the most important part-eat-for you to do it.
Ordering is equivalent to configuring ORM ing. if you tell the restaurant what you want to eat, the restaurant prepares food according to your needs. once you have prepared the food, it will be sent to you!

How can I configure the php kohana framework after it is downloaded?

Not found MODPATH \ database \ classes \ kohana \ db. php [63] 58 * @ param please state how you call the database or ORM in the process, or the method you call may be incorrect.
 

First, create a model class. take user as an example. create user. php in the application/classes/model/user. php path and...

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.