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!
PHP ActiveRecord demo栗子中 关于类名 的问题的更多相关文章
- 干货 | Java中获取类名的3种方法!
获取类名的方法 Java 中获取类名的方式主要有以下三种. getName() 返回的是虚拟机里面的class的类名表现形式. getCanonicalName() 返回的是更容易理解的类名表示. g ...
- 【转】使用JavaParser获得Java代码中的类名、方法形参列表中的参数名以及统计总的文件个数与不能解析的文件个数
遍历目录查找Java文件: public static void ergodicDir(File dir, HashSet<String> argNameSet, HashSet<S ...
- rails 杂记 - erb 中的 link_to 的 ActiveRecord 与 render 中的 partial
路由及路由参数 <%= link_to 'My Blog', {controller: 'articles', demo: "lidsi"}, class: "bl ...
- Swift微博项目--Swift中通过类名字符串创建类以及动态加载控制器的实现
Swift中用类名字符串创建类(用到了命名空间) OC中可以直接通过类名的字符串转换成对应的类来操作,但是Swift中必须用到命名空间,也就是说Swift中通过字符串获取类的方式为NSClassFro ...
- (用微信扫的静态链接二维码)微信native支付模式官方提供的demo文件中的几个bug修正
native支付模式一demo(用微信扫的静态链接二维码)BUG修复,一共4个BUG 1.native_call_qrcode.php这个文件中的代码无法生存native支付的短地址2.WxPayPu ...
- 易宝支付Demo,生产中封装成简洁的代付接口,不用request如何获取项目运行时的真实路径
最近项目在做融360引流,涉及到了易宝支付的代扣和代付.易宝官方给出的demo只能简单运行,而且都是通过form表单的形式提交,返回XML格式.同时接口代码都写在了JSP中看起来不友好.项目在生成中想 ...
- c++中如 <类名 类名::对象> 是什么意思
CComplex CComplex::add(CComplex &x) (这一句 不懂为何 类名 类名::对象) { CComplex y(real+x.real,image+x.image) ...
- 【java】项目中的类名改变
如果已经开发了一段时间,那如何一次性修改所有文件中的该类类名呢,一个个改太麻烦了还浪费时间,匹配关键字又怕误伤. 选中项目中需要改变的类,按F2键 重命名后eclipse会自动修改.
- webpack官网demo起步中遇到的问题
在webpack官网demo一开始搭建中
随机推荐
- val和var和Java
object Hello { def main(args :Array[String]) { val k = i } } jvm代码 public final class Hello$ { publi ...
- Mybatis:通过MapperScannerConfigurer进行mapper扫描
在applicationContext.xml里配置的
- react-native-vector-icons 图标库使用
安装链接 yarn add react-native-vector-icons react-native link react-native-vector-icons 在项目工程中打开 .xcodep ...
- Valgrind简单用法 (转)
转自 http://www.cnblogs.com/sunyubo/archive/2010/05/05/2282170.html Valgrind的主要作者Julian Seward刚获得了今年的G ...
- day37-常见内置模块六(其他模块)
其他内置模块 1.subprocess(系统交互)模块 2.math模块 3.zipfile模块 4.keyword模块 5....
- jsfl 读取xml
var fileURI = "file:///c|/temp/mydata.txt"; var dataXml = new XML(FLfile.read(fileURI)); v ...
- bash中 2>&1 & 的解释
1.首先,bash中0,1,2三个数字分别代表STDIN_FILENO.STDOUT_FILENO.STDERR_FILENO,即标准输入(一般是键盘),标准输出(一般是显示屏,准确的说是用户终端控制 ...
- Runloop原理
简单的说,runloop是一个事件循环的机制,同时能够保活线程.iOS中每个线程都对应一个runloop,主线程的runloop默认开启,其他线程的runloop默认关闭,线程与runloop是一一对 ...
- cordova- cordova-plugin-splashscreen启动页面和图标的设置
https://www.cnblogs.com/a418120186/p/5856371.html
- 今天折腾phantomjs+selenium的笔记
1.debian8里安装phantomjs的方法: 参照:http://www.cnblogs.com/lgh344902118/p/6369054.html a.去https://bitbucket ...