Basic use of the Kohana framework ORM class

Source: Internet
Author: User
Tags kohana

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:

<?phpclass Model_User extends ORM{    ...}?>

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 ):

<? Phpclass controller_admin_user extends controller_admin {public function action_test () {$ user = ORM: Factory ('user ');
// 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 () ;}}?>

 

Basic use of the Kohana framework ORM class

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.