[英]Codeigniter undefined property on core/Model.php
Controller 控制者
public function editItem(){
$this->load->helper('form');
$this->load->model('ItemModel');
$data['items'] = $this->ItemModel->itemlist();
$item_details = $this->ItemModel->edititem($this->input->get('id'));
$data2['item_name'] = $item_details->name; //THIS IS LINE 28
$data2['item_description']= $item_details->description;
$data2['item_price'] = $item_details->price;
$this->load->view('item/item_edit',$data2);
}
There's an error to my view, and I don't know why 我的观点有误,我不知道为什么
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Item::$name
Filename: core/Model.php
Line Number: 77
Backtrace:
File: C:\xampp\htdocs\itwa213\application\controllers\Item.php
Line: 28
Function: __get
File: C:\xampp\htdocs\itwa213\index.php
Line: 292
Function: require_once
I already checked my autoload on config and it's properly configured with 我已经检查了config上的自动加载,并使用
$autoload['libraries'] = array('database');
You could try this 你可以试试这个
public function editItem() {
$this->load->helper('form');
$this->load->model('ItemModel');
$data['items'] = $this->ItemModel->itemlist();
$item_details = $this->ItemModel->edititem($this->input->get('id'));
$data2['item_name'] = $item_details['name']; //THIS IS LINE 28
$data2['item_description'] = $item_details['description'];
$data2['item_price'] = $item_details['price'];
$this->load->view('item/item_edit',$data2);
}
Your controller function change to like this 您的控制器功能更改为这样
public function editItem(){
$this->load->helper('form');
$this->load->model('ItemModel');
$data['items'] = $this->ItemModel->itemlist();
$data2['item_details'] =$this->ItemModel->edititem($this->input->get('id'));
$this->load->view('item/item_edit',$data2);
}
and in your view page 并在您的查看页面中
echo $item_details->name;
You should look at your code for the get function you use. 您应该查看您使用的get函数的代码。 try to replace the
$this->input->get('id')
to existing id number first. 尝试先将
$this->input->get('id')
替换为现有的ID号。 check whether it success or not. 检查是否成功。 If success by using existed id number, so it should your get function not working or something wrong.
如果使用现有的ID号成功,那么您的get函数应该无法正常工作或出现问题。 i'm seldom use $this->input->get() but $this->input->post().
我很少使用$ this-> input-> get(),而是$ this-> input-> post()。
on your edit link, you can use: <a href="controller/method/id">edit</a>
. 在您的编辑链接上,您可以使用:
<a href="controller/method/id">edit</a>
。 so the id is the third segment uri. 因此ID是第三段uri。 use
$this->uri->segment(3);
使用
$this->uri->segment(3);
to get the third segment and store into $item_id variable into your controller. 获取第三段并将其存储到$ item_id变量中到您的控制器中。 so, no need to use $this->input->get();
因此,无需使用$ this-> input-> get(); to get the item_id value.
获取item_id值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.