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