PHP ActiveRecord demo栗子中 关于类名 的问题

问题: ActiveRecord如何将单个类名与表名相关联?
我昨天才发现了ActiveRecord,很奇妙的php数据库框架。

但是,我仍然对以下工作感到困惑:    

1.下面这个Person Model类 会自动将这个类指向到 people表

   

class Person extends ActiveRecord\Model {}

而我对类名和表名的联系的理解是下面这个关系

例如 Post.php

class Post extends ActiveRecord\Model {}

  这个Post Model 类的 话 是自动解析 Post类 指向的是posts表

所以问题就来了 !!!

Answer: 到底作者用了什么方法 把Person类 解析为了 people 表 而不是 persons表?

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 is told it‘s model‘s classname.

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

  In the Utils library, you will find the pluralize and singularize implementations, which basically have some predefined plurals for the uncountable items (stuff that doesn‘t get pluralized like sheep and deer), some standard irregular forms (like child > children), and then some cool pluralization rules ($plural and $singular) that it runs through the regex parser.

#person会自动解析转义为people
#Utils.php

private 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!

 
 
时间: 2024-08-27 11:59:33

PHP ActiveRecord demo栗子中 关于类名 的问题的相关文章

(用微信扫的静态链接二维码)微信native支付模式官方提供的demo文件中的几个bug修正

原文:(用微信扫的静态链接二维码)微信native支付模式官方提供的demo文件中的几个bug修正 native支付模式一demo(用微信扫的静态链接二维码)BUG修复,一共4个BUG 1.native_call_qrcode.php这个文件中的代码无法生存native支付的短地址2.WxPayPubHelper.php中某个代码获取不到WxPayConf_pub类定义的常量CURL_TIMEOUT3.WxPayPubHelper.php curl中cURL会话并且异常释放资源4.微信支付长地址

Java中通过类名创建一个类的实例

Java中通过类名创建类的实例,此类必须是默认的构造方法,不能自己写构造方法. 方法1: UserDao userDao=null; Properties prop=new Properties();    InputStream inStream=DaoFactory.class.getClassLoader().getResourceAsStream("daoconfig.properties");    prop.load(inStream);    String userDao

jQuery 选择器获取组合类中的类名

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

Java中获取类名的3种方法!

获取类名的方法 Java 中获取类名的方式主要有以下三种. getName() 返回的是虚拟机里面的class的类名表现形式. getCanonicalName() 返回的是更容易理解的类名表示. getSimpleName() 返回的是类的简称. 都有什么区别? 通过一个实例来看下它们主要的区别. public class TestClass { public static void main(String[] args) { // 外部普通类 System.out.println("方法名

webpack官网demo起步中遇到的问题

在webpack官网demo一开始搭建中 

Qt 中界面类名的修改

Qt 中如果想要使用多个已经写好的界面类,往往会发现界面类的名称要么是“MainWindow”,要么是“Widget”,或者是“Dialog”.那么重名的界面类在一起就会在所难免.或者你想修改界面类的名称.那么一定要切记不可直接修改界面类的名称.否则和容易出错. 正确的解决方法如下: 1.修改.ui文件名称为xxxmainwindow.ui/xxxwidget.ui/xxxdialog.ui :在工程树下右键修改即可.当然也可以为其他名字,总之要清晰明了有个性. 2.修改.h,.cpp名称与.u

【java】项目中的类名改变

如果已经开发了一段时间,那如何一次性修改所有文件中的该类类名呢,一个个改太麻烦了还浪费时间,匹配关键字又怕误伤. 选中项目中需要改变的类,按F2键 重命名后eclipse会自动修改. 原文地址:https://www.cnblogs.com/ByTwo/p/11801485.html

java中通过类名实例化类

String className ="test.Test1"; Class clazz; try { clazz = Class.forName(className); Test1 userDao=(Test1) clazz.newInstance(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationEx

java中创建对象 类名 对象名=new 类名(); 后面的()什么意思

类名 对象名=new 类名();类名 对象名 这个的解释是创建名称为"对象名"的"类名"类引用变量new ; 这个的解释是实例化对象类名() 这个的解释是无参数构造方法:new 类名();就是说以无参数构造方法实例化对象:类名 对象名=new 类名();用指针的解释就是以无参数构造方法实例化对象并将这个对象的内存引用赋给"类名"类的"对象名"引用变量