简体   繁体   English

如何将数组值从一个函数传递到另一个函数,并使用Codeigniter将其发送以查看页面?

[英]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.

相关问题 如何在Codeigniter中将数组从一个函数传递给另一个函数 - How to pass an array from one function to another in codeigniter 如何通过使用会话将数据从一个功能传递到Codeigniter中的另一个功能? - How to pass data from one function to another in codeigniter by using session? 如何将数据从一个视图页面传递到codeigniter中的另一个视图? - how to pass the data from one view page to another view in codeigniter? 如何在Codeigniter中将变量从一个函数传递给另一个函数 - how to pass variable from one function to another function in codeigniter 如何将函数的值从一页返回到PHP的另一页,并使用会话将其存储在数组中? - How to return a value of a function from one page to another page i php and store it in an array using session? CodeIgniter:如何将值从特定函数传递给另一个函数 - CodeIgniter: how to pass values from a specific function to another one 如何将值从一个函数传递到另一个函数 - How could I pass a value from one function to another function 我想将变量从一个函数传递给Codeigniter中的另一个函数 - I want to pass variables from one function to another function in codeigniter 使用codeigniter从另一个函数调用一个函数 - Call one function from another using codeigniter 如何使用jQuery将值从一页传递到另一页? - How to pass value from one page to another page using jQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM