【问题标题】:Undefined property: stdClass::$title未定义的属性:stdClass::$title
【发布时间】:2014-11-20 16:29:19
【问题描述】:

我想从数据库中获取没有 parent_id 的页面的记录,或者我们可以说没有父页面的页面..

页面模型 ......................................

public function get_no_parents() {
// fecth pages wihtout parents
$this->db->select ( 'id','title' );
$this->db->where ( 'parent_id', 0 );
$pages = parent::get ();
// if there are pages then return key as page->id and value $page->title
$array = array (
0 => 'no parent'
);

if(is_array($pages)){

foreach ($pages as $page){

 $array[$page->id]=$page->title;
   $return $array;


    }
  }
}

.....页面控制器

$this->data['pages_no_parents']=$this->Page_model->get_no_parents();
    var_dump($this->data['pages_no_parents']);

.... 转储为空我有两个错误

1- 未定义属性:stdClass::$title

2- 为 foreach() 提供的参数无效

有人可以帮助我吗?

【问题讨论】:

  • 问题依然存在
  • 仍然存在一个问题,但您还有另一个问题。 parent::get(); 返回什么?
  • 它将从父类返回数据库中的页面
  • 嗯,它应该,但它不返回一个数组...var_dump
  • 没有一个错误被修复,未定义的属性:stdClass::$title 我仍然收到错误

标签: php mysql codeigniter


【解决方案1】:

变化:

$this->db->select ( 'id','title' );

收件人:

$this->db->select ( 'id, title' );

希望这会有所帮助!

【讨论】:

  • 谢谢它的工作,你能给我解释一下吗?它们之间有什么区别?
  • $this->db->select() 只需要 2 个参数:1) 选择字符串 2) 显示字符串是否应转义的标志。那么,当你有 ('id', 'title') id 时,如果这有意义的话,这是唯一作为选择的一部分传递的字符串吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-29
  • 1970-01-01
  • 2016-04-20
  • 2019-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多