问题: 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. OpenGL Hello World

    ▶ OpenGL 的环境配置与第一个程序 ● CUDA 中自带 OpenGL 需要的头文件和库,直接拉进项目里边去就行 ● VS项目属性右键,属性,C/C++ 目录,包含目录,添加 CUDA 的头文件 ...

  2. 浅谈Android MVP

    什么是MVP MVP,全称 Model-View-Presenter.要说MVP那就不得不说一说它的前辈--MVC(Model-View-Controller,模型-视图-控制器). View:对应于 ...

  3. eclipse中无法新建Android工程 出现问题:Plug-in org.eclipse.ajdt.ui was unable to load

    转自:http://www.bubuko.com/infodetail-757338.html eclipse中打开后新建Android项目区仍无法创建,出现下列提示对话框: Plug-in org. ...

  4. localStorage本地存储的用法

    localStorage用法 if(window.localStorage){ alert('这个浏览器支持本地存储'); }else{ alert('这个浏览器支持不本地存储'); } localS ...

  5. MySQL 5.7 以上版本默认禁止 0000-00-00 的日期

    今天做数据同步,发现一直有报错,集中在时间的默认值.数据源的mysql版本是5.5.30,有些时间字段默认值设置为0000-00-00 00:00:00.目标mysql版本为5.7.17,查资料发现, ...

  6. Centos 7 安装 sphinx2.2 (转)

    一.首先到Sphinx官网找到下载地址:http://sphinxsearch.com/downloads/release/如果你比较懒,好吧:http://sphinxsearch.com/file ...

  7. Yum安装MySQL以及相关目录路径和修改目录

    有些时候,为了方便,有些同学喜欢通过yum的方式安装MySQL,没有设置统一的文件目录以及软件目录,那么就会为后续的维护工作带来很大的麻烦! 下面就简单介绍一下yum安装MySQL的步骤以及这类安装下 ...

  8. Linux zookeeper 单机安装

    Zookeeper(端口2181) 下载地址 http://mirror.bit.edu.cn/apache/zookeeper/ 解压到/usr/local目录 >tar -zxvf zook ...

  9. vue.js 作一个用户表添加页面----初级

    使用vue.js 制作一个用户表添加页面,实际上是把原来需要使用js写的部分,改写成vue.js的格式 首先,想象一下,先做思考,我们要添加用户表,设涉及到哪些数据,一个是用户id,一个是用户名,一个 ...

  10. html lesson one

    Review Congratulations on completing the first lesson of HTML & CSS! You are well on your way to ...