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一开始搭建中
随机推荐
- openStack queens 功能验证调试
linux已经加载 的内核模块查看
- MySQL配置文件以及服务的开启关闭重启
linux系统中,配置文件路径一般为/etc/my.cnf [root@host ~]# mysql --help|grep my.cnf order of ...
- asp.net excel模板下载
string filePath = Server.MapPath("~/model/模板.xls");//路径 FileInfo fileInfo = new FileInfo(f ...
- idea 安装三方插件的方法
<一>在线安装 1,File -> Setting -> Plugins, 大红框内是已经安装的插件,可以搜索 2, 点击上图小红框内的按钮, 如下,搜索自己想要的插件,选中, ...
- linux驱动开发(四) 字符设备驱动框架(自动创建设备节点)
代码如下 #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> # ...
- RADIDE MultiPaste
RADIDE MultiPaste https://community.embarcadero.com/blogs/entry/multipaste-in-the-rad-studio-ide htt ...
- 直接下载:Windows 10正式版官方原版镜像!
本文搜集整理微软官方发布的Windows 10正式版镜像下载链接,从RTM原始正式版开始,按照时间倒序排列,即越往上的越新. 注意:以下资源均来自于微软官方原版,ed2k可视为P2P下载链接.下载完成 ...
- js人形时钟
https://blog.csdn.net/rsylqc/article/details/44808063 分享自:http://chabudai.org/blog/?p=59 在这个网站看到一个很有 ...
- pod引用第三方库的几种方式
pod引用库的原理,本质上是去找.podspec文件,podspec中包含库的地址及最新的版本号(tag标签),如果pod时没有指定版本,则pod install时会去下载podspec文件中指定的最 ...
- Delphi处理TWebBrowser的Close事件
当TWebBrowser控件访问的 Web 页上的脚本调用window.close方法时,TWebBrowser控件可能会在窗体中消失.我们的程序应该对此作出反应,否则再次访问TWebBrowser控 ...