En Construcción

Páginas: 16 (3986 palabras) Publicado: 11 de junio de 2012
Kohana PHP

Object Relational Mapping guide

Written by Sam Clark Version 1.4 (Draft)

http://sam.clark.name

Kohana PHP Object Relational Mapping guide

Contents
Introduction Credits and contributions What is this ORM thing anyway? Creating an ORM class Using Customer_Model with Customer_Controller Extending the behaviour of Customer_Model Creating ORM relationships
One to manyrelationship Many to many relationship ORM relationships summary

3 3 4 5 8 14 16
16 18 20

Using ORM relationships in your code
find_related add remove

21
21 21 21

Appendix A - Full Files
customers.sql customer_addresses.sql addresses.sql customers_addresses.sql application/models/customer.php application/models/customer_address.php application/models/address.phpapplication/controllers/customer.php

22
22 22 23 23 24 24 24 25
2

Kohana PHP Object Relational Mapping guide

Introduction
The impetus for writing this guide came from discovering there was no real documentation for my favourite feature within Kohana PHP - ORM. ORM delivers a robust data manipulation toolset that provides almost everything you could possibly need to write clean, fast code to do wonderfulthings. After reading through many of the posts within the Kohana PHP forum, plus reading an introduction to ORM on the Kohana PHP Development blog, I decided to try and finish the missing bits regarding creating relationships. This document originally started as a blog post but as it started to grow, I decided to create a structured document rather than a meandering post. Because of this, sometimesthe language in this document is in the first person, sometimes in the third and sometimes the person is missing altogether. For this I can only apologise and say, “it will get better”. This is currently only the first draft and I will update in time - but this will be helped if you help me by telling me what works for you, especially what doesn’t and anything you think I missed out. If you have anycomments, just post them on my blog under the “Kohana PHP - ORM guide” post (http://sam.clark.name/2008/03/31/orm-guide/). Hopefully this should help the guys working hard to develop Kohana PHP with some extra documentation in the future. I am a PHP developer based in South London. I have been using and waxing lyrical about Kohana PHP for the last four months on my blog (http://sam.clark.name), aswell as on the geekUp mailing list. I was inspired to write this document after reading “Kohana’s ORM - a brief introduction” at http://learn.kohanaphp.com/2008/02/14/kohanas-orm-a-brief-introduction/. You can read more about ORM at http://doc.kohanaphp.com/libraries/orm .

Credits and contributions
Proof reading and error correction by phelz Further proof reading and error corrections byatomless and Louis

Licence

Kohana PHP Object Relational Mapping Guide by Sam Clark is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales License. Based on a work at learn.kohanaphp.com.

3

Kohana PHP Object Relational Mapping guide

What is this ORM thing anyway?
ORM (Object Relational Mapping) is an object that mirrors data within adatabase. The idea of an Object Relational Mapping is to allow manipulation and control of data within a DB as though it was a PHP object. You may be thinking that this is just a database abstraction layer and you wouldn’t be entirely wrong. But ORM goes further than just removing SQL code from your PHP code, it allows you to tailor how data moves to and from different tables within your Database. UsingORM within your code allows you to pull data from your database, manipulate the data in any way you like and then save the result back to the database without one line of SQL. It goes further by providing methods for maintaining relationships across tables (joins) and finding data by criteria. ORM will even automatically save your object back database if you wish it too. This document provides a...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Construcciones
  • Construccion
  • Construccion
  • Construccion
  • Construccion
  • Construccion
  • construccion
  • construccion

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS