Home > Backend Development > PHP Tutorial > YII根据表字段名生成的类如何自己更改名字?

YII根据表字段名生成的类如何自己更改名字?

WBOY
Release: 2016-06-06 20:45:02
Original
1000 people have browsed it

比如:

<code class="lang-sql">CREATE TABLE 'tbl_myr_version' (
  'current_version_id'
);
</code>
Copy after login
Copy after login

如果是YII根据AR生成的,那么类的名字也应该是current_version_id,,如何让生成的类的名字变成currentVersionId呢?
事情紧急,请YII大神回答。。

回复内容:

比如:

<code class="lang-sql">CREATE TABLE 'tbl_myr_version' (
  'current_version_id'
);
</code>
Copy after login
Copy after login

如果是YII根据AR生成的,那么类的名字也应该是current_version_id,,如何让生成的类的名字变成currentVersionId呢?
事情紧急,请YII大神回答。。

这个在gii里边Model生成时,可以自已填写的.


如果不用gii,可以自已在models目录下创建一个文件名CurrentVersionId.php,然后写上代码.

<code class="lang-php">class CurrentVersionId extends CActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        //为了使用前缀tbl_, 用这种2个花括号方式
        return '{{myr_version}}';
    }
}
</code>
Copy after login

Yii会autoload的.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template