问题: 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!

 
 

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

  1. 干货 | Java中获取类名的3种方法!

    获取类名的方法 Java 中获取类名的方式主要有以下三种. getName() 返回的是虚拟机里面的class的类名表现形式. getCanonicalName() 返回的是更容易理解的类名表示. g ...

  2. 【转】使用JavaParser获得Java代码中的类名、方法形参列表中的参数名以及统计总的文件个数与不能解析的文件个数

    遍历目录查找Java文件: public static void ergodicDir(File dir, HashSet<String> argNameSet, HashSet<S ...

  3. rails 杂记 - erb 中的 link_to 的 ActiveRecord 与 render 中的 partial

    路由及路由参数 <%= link_to 'My Blog', {controller: 'articles', demo: "lidsi"}, class: "bl ...

  4. Swift微博项目--Swift中通过类名字符串创建类以及动态加载控制器的实现

    Swift中用类名字符串创建类(用到了命名空间) OC中可以直接通过类名的字符串转换成对应的类来操作,但是Swift中必须用到命名空间,也就是说Swift中通过字符串获取类的方式为NSClassFro ...

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

    native支付模式一demo(用微信扫的静态链接二维码)BUG修复,一共4个BUG 1.native_call_qrcode.php这个文件中的代码无法生存native支付的短地址2.WxPayPu ...

  6. 易宝支付Demo,生产中封装成简洁的代付接口,不用request如何获取项目运行时的真实路径

    最近项目在做融360引流,涉及到了易宝支付的代扣和代付.易宝官方给出的demo只能简单运行,而且都是通过form表单的形式提交,返回XML格式.同时接口代码都写在了JSP中看起来不友好.项目在生成中想 ...

  7. c++中如 <类名 类名::对象> 是什么意思

    CComplex CComplex::add(CComplex &x) (这一句 不懂为何 类名 类名::对象) { CComplex y(real+x.real,image+x.image) ...

  8. 【java】项目中的类名改变

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

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

    在webpack官网demo一开始搭建中 

随机推荐

  1. 代码:jquery自定义插件 demo

    jquery自定义插件 demo 2016-1-13 只是一个简易的示例 <script type="text/javascript" src="http://cd ...

  2. python学习笔记_week17

    note jQuery http://jquery.cuishifeng.cn/ 模块 <=>类库 DOM/BOM/JavaScript的类库 版本: 1.x 1.12 2.x 3.x 转 ...

  3. dubbo 学习资料

    入门: http://www.tuicool.com/articles/FnE3em http://www.cnblogs.com/xuyatao/p/6869231.html 最好 http://w ...

  4. jar 问题 : java.io.IOException: invalid header field

    通过本文, 我们明白了什么是 jar的清单文件 MANIFEST.MF, 简单示例: E:\ws\Test\WEB-INF\classes>jar cvfm testCL.jar ListTes ...

  5. Eclipse集成SonarLint

    https://docs.sonarqube.org/display/PLUG/Writing+Custom+Java+Rules+101

  6. confusing c++ 重写 与 重定义 记录1

    class parent { public: void f() { cout << "parent f()" << endl; } void f(int i ...

  7. image 标签src

    最近对接到前端  src需要填写  src= "data:image/jpg;base64,xxxxxxxooooooo";  记录一下图片转换的问题,需要把图片转换成base64 ...

  8. css:在容器内文字超过容器范围,显示一行加省略号或者两行加省略号

    一.显示一行加省略号:各浏览器兼容 .box{ width: 100px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; } ...

  9. 尚硅谷redis学习6-持久化RDB

    是什么 持久化文件保存在dump.rdb中 持久化策略 在shutdown或flush或flushall后会立即持久化 重新启动后会从rdb文件中恢复数据 可以手动持久化 持久化失败时不允许写,如在强 ...

  10. 1:python 简介与基础

    什么是python? 1.python是一种面向对象的解释型语言,它继承了传统编译语言的通用性和强大性,同时也借鉴了简单脚本和解释语言的易用性. 2.python 在自动化测试.人工智能.数据分析等方 ...