简体   繁体   English

通过保存在codeigniter中的配置文件中的名称获取数据库$ row属性

[英]Getting database $row property by name saved in config file in codeigniter

I am trying to go over $row object which I got from the $this->db->get()->result(); 我试图越过从$this->db->get()->result(); $row对象$this->db->get()->result();

The table column names are stored in config file, which I can access like this : $this->tableTask [ 'column' ] [ 'id' ]; 表列名称存储在配置文件中,我可以像这样访问: $this->tableTask [ 'column' ] [ 'id' ];

How do I do the following in a single command instead of first assigning the column name to a variable then reaching the $row property ? 如何在单个命令中执行以下操作,而不是先将列名称分配给变量,然后到达$ row属性?

This works. 这可行。

$id = $this->tableTask['column']['id'];
$this->data[$this->tableTask[ 'column']['id']] = $row->$id;

This does not. 这不是。 I get the following error. 我收到以下错误。

Error Message: Object of class Task could not be converted to string 错误消息:无法将任务类的对象转换为字符串

$this->data[$this->tableTask['column']['id']] = $row->$this->tableTask['column']['id'];

Note: This all is happening inside a method of class Task which is an auxiliary class to a custom library I am working on. 注意:这一切都是在Task类的方法内部发生的,该类是我正在使用的自定义库的辅助类。

Try encapsulating your variable like this (notice the "{}" marks): 尝试像这样封装变量(注意“ {}”标记):

$this->data[$this->tableTask['column']['id']] = $row->{$this->tableTask['column']['id']};

If you want to use the property value for obtaining the name of another property you have to encapsulate your your value call. 如果要使用属性值获取另一个属性的名称,则必须封装您的value调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM