Phalcon 列名前缀
Phalcon Column name Prefixes
我下面有这个用户table。
在 phalcon 中,是否可以映射列名,以便在执行所有与模型相关的过程时删除所有前缀名称?在 YII 中,这是可行的。
所以可以说,
$user->id will point to $user->tbl_user_id;
$user->fullname will point to $user->tbl_user_fullname;
$user->phone will point to $user->tbl_user_phone;
我调用 table 名称没问题,因为在模型中您可以指定 getSource()。我尝试了在网上找到的列映射,但无法正常工作,不确定它是否理想。
此外,如果我要以这种方式实施,这会导致可能的问题吗?任何已知的缺点?
PHP版本
PHP 5.4.44-0+deb7u1 (cli) (built: Aug 16 2015 09:51:53) Copyright (c)
1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014
Zend Technologies
您可以将数据库列名称映射到内部 Phalcon 命名:
将其放入您的 User
模型中
public function columnMap()
{
return [
// database column name => phalcon name
'tbl_user_id' => 'id',
'tbl_user_fullname' => 'fullname',
'tbl_user_phone' => 'phone',
];
}
查看 the documentation 了解有关列映射的更多信息。
The ORM supports an independent column map, which allows the developer to use different column names in the model to the ones in the table. Phalcon will recognize the new column names and will rename them accordingly to match the respective columns in the database. [...].
我下面有这个用户table。
$user->id will point to $user->tbl_user_id; $user->fullname will point to $user->tbl_user_fullname; $user->phone will point to $user->tbl_user_phone;
我调用 table 名称没问题,因为在模型中您可以指定 getSource()。我尝试了在网上找到的列映射,但无法正常工作,不确定它是否理想。
此外,如果我要以这种方式实施,这会导致可能的问题吗?任何已知的缺点?
PHP版本
PHP 5.4.44-0+deb7u1 (cli) (built: Aug 16 2015 09:51:53) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
您可以将数据库列名称映射到内部 Phalcon 命名:
将其放入您的 User
模型中
public function columnMap()
{
return [
// database column name => phalcon name
'tbl_user_id' => 'id',
'tbl_user_fullname' => 'fullname',
'tbl_user_phone' => 'phone',
];
}
查看 the documentation 了解有关列映射的更多信息。
The ORM supports an independent column map, which allows the developer to use different column names in the model to the ones in the table. Phalcon will recognize the new column names and will rename them accordingly to match the respective columns in the database. [...].