我在使用 Codeigniter 时遇到问题。我尝试将值从 View 传递到 Controller 并且它有效。但从 Controller 传递到模型时存在问题。它没有向 View 返回任何值。
这是我的 Controller :
public function Edit2G() {
$id = $this->uri->segment(3);
$this->load->model("main_model");
$data['fetch_data_2G_where'] = $this->main_model->fetch_data_2G_id($id);
$data['id'] = $id;
$data['title'] = "Update Data 2G";
$this->load->view('templates/header');
$this->load->view("pages/Update2G", $data);
$this->load->view('templates/footer');
}
这是模型
function fetch_data_2G_id($id)
{
$get_2G_data_stored_proc = "CALL Get_2G_Data(?)";
$data = array( 'id' =>$id);
$query = $this->db->query($get_2G_data_stored_proc, $data);
$result = $query->result_array();
return $get_2G_data_stored_proc;
}
这是我的观点
<h2 align="center"><?=$title ?></h2>
<h3 align="center"><?=$id ?></h3>
<p align="center"><?php echo $fetch_data_2G_where['id'];?></p> //This is a test
<?php echo form_open('posts/update'); ?>
<input type="hidden" name="id" value="<?php //echo $fetch_data_2G_where['id']; ?>">
<div class="form-group">
<label>Site ID</label>
<input type="text" class="form-control" name="title" placeholder="add title" value="<?php //echo $fetch_data_2G_where['site_name'];?>">
</div>
这是存储过程结果
id, id_site, site_name, bsc_name, bcf_id, vlan1, vlan2, status,status_vlan
'1', 'COK008', 'Combat Batylon754','FBTIMIKA-1','BCF-0112', '3677', '3137', '', 'Metro E'
这是我得到的错误
A PHP Error was encountered Severity: Warning
Message: Illegal string offset 'id'
Filename: pages/Update2G.php
Line Number: 3
Backtrace:
File: C:\xampp\htdocs\DapotTimika\application\views\pages\Update2G.php Line: 3 Function: _error_handler
File: C:\xampp\htdocs\DapotTimika\application\controllers\Pages.php Line: 46 Function: view
File: C:\xampp\htdocs\DapotTimika\index.php Line: 315 Function: require_once
我缺少什么?
PS:存储过程只有一个参数(id)来返回/获取数据
最佳答案
在你的 Controller 中 print_r 以下行
$data['fetch_data_2G_where'] = $this->main_model->fetch_data_2G_id($id);
echo "<pre>"; print_r($data['fetch_data_2G_where']);
只是为了看看您的查询返回的结果是什么。然后您可以根据您的结果进行分析并获得所需的结果。
关于php - 使用存储过程将值从 Controller 传递到模型 CodeIgniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54340713/