[英]How to pass the array value from one function to another function and send it to view the page using Codeigniter?
I am getting array value from model and that value I have to pass the other function 我从模型中获取数组值,并且该值我必须传递其他函数
Controller 调节器
First function 第一功能
public function example_from_view(){
$int_id = $this->session->userdata['int_url_id']['int_id'];
$result['data']=$this->formbuilder_Model->check_example_form_builder_fields($int_id);
print_r($result['data']); //I have to pass this array to second function so I tried $this->new_example_added($result);
$this->load->view('user-example-form',$result);//passing elements to the view page
}
Second function 第二功能
public function new_example_added($result)
{
print_r($result['data']);
$this->load->view('user-example-form', $result);
}
View 视图
foreach ($data as $key) {
echo $exp_fields_name=$key->fields_name;
}
But I am getting in view page undefined variable: data and Undefined variable: result
. 但是我进入视图页面undefined variable: data and Undefined variable: result
。 I want to use without a session. 我想在没有会议的情况下使用。 Would you help me out in this? 您能帮我这个忙吗?
Change First function code 更改优先功能代码
public function example_from_view(){
if(isset($this->input->post('SUBMIT_BUTTON_NAME'))){
//do your validation here
}
$int_id = $this->session->userdata['int_url_id']['int_id'];
$data = $this->formbuilder_Model->check_example_form_builder_fields($int_id);
//print_r($result['data']); //I have to pass this array to second function so I tried $this->new_example_added($result);
$result['data'] = $data;
$this->load->view('user-example-form',$result);//passing elements to the view page
}
Remove this function, 删除此功能,
public function new_example_added($result)
{
//print_r($result['data']);
$data['data'] = $result;
$this->load->view('user-example-form', $data);
}
I would recomment that you should not load the view from 1st function. 我建议您不要从第一个函数加载视图。 You should just pass the $result
array to the other function new_example_added
and then load view from there. 您应该只将$result
数组传递给另一个函数new_example_added
,然后从那里加载视图。 Which is done in correct way. 这是以正确的方式完成的。
Its Very Simple Add Second Function in First Function like this .. 它的第一个功能非常简单地添加第二个功能,例如..
IN the contorller 在控制器中
class Test extends CI_Controller{
public function one(){
$data['result'] = array(
'one' => '1',
'two' => '2',
'three' => '3'
);
#calling Second function
$data['view'] = $this->second($data);
$this->load->view('testview', $data);
}
public function second($data)
{
$data = array(
'four' => '4',
'five' => '5',
'six' => '6'
);
return $data;
}
}
Then in view page 然后在查看页面
foreach($result as $res):
echo $res."<br/>";
endforeach;
foreach($view as $res):
echo $res."<br/>";
endforeach;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.