PHP ActiveRecord Demo Pest questions about the class name

Source: Internet
Author: User
Tags php database

Question: ActiveRecord How can I associate a single class name with a table name?
I only found out yesterday ActiveRecord, a wonderful PHP database framework. However, I am still puzzled by the following work:
    

1. The following person model class will automatically point this class to the people table

   

Class person extends Activerecord\model {}

And my understanding of the relation between the class name and the table name is the following relationship

such as post.php

Class Post extends Activerecord\model {}

The Post Model class is the auto-parse post class that points to the posts table

So the problem is coming!!!

Answer: What method did the author use to parse the person class for the people table instead of the persons table ?

Question:

Your Activerecord\model-derived class has a reference to an activerecord\table.

When the Table gets initialized (once per model-class through some static function calls), it's told it's model ' s CLASSNA Me.

Table::__construct ($classname)

Calls

Table::set_table_name ()

Through the model ' s class name it asks if that class has statically overridden the table name. If not, it uses the Inflector library with:

Inflector::instance ()->tableize

Which is really just

Standardinflector::tableize ($classname)

Which underscorifies the name (Inflector::underscorify ())
Converts it to lower case (Strtolower ())
Then hands it off to

Utils::p luralize ()

In the Utils library, you'll find the Pluralize and Singularize implementations, which basically have some predefined pl Urals for the uncountable items (stuff this doesn ' t get pluralized like sheep and deer), some standard irregular forms (Li Ke child > Children), and then some cool pluralization rules ($plural and $singular) that it runs through the regex par Ser.

#person会自动解析转义为people #utils.phpprivate Static $irregular = Array (        ' move ' = ' = '   moves ',        ' foot '   = > ' feet ',        ' goose '  = ' geese ',        ' sex '    = ' sexes ',        ' child '  = ' children ',        ' Man '    = ' men ',        ' tooth '  = ' teeth ',        ' person ' = ' people '    );

And remember you can override the defaults back in your model class with:

Class Mymodelclass extends Activerecord\model {  static $table _name = ' whatever_it_is ';}

  

Thank you!

PHP ActiveRecord Demo Pest questions about the class name

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.