[英]Can i pass data between functions in codeigniter?
im loading a simple form as a subview, i need to pass the data to the next function but when I use $this->data
i get a blank page. 即时通讯加载一个简单的窗体作为子视图,我需要将数据传递给下一个函数,但是当我使用
$this->data
我得到了一个空白页。 here is my controller: 这是我的控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Search extends Admin_Controller {
function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->load->helper('form');
$this->load->model('search_model');
}
function index()
{
$this->data['subview'] = ('../views/user/search_form');
$this->load->view('../views/_layout_admin', $this->data);
}
function execute_search()
{
// Retrieve the posted search term.
$search_term = $this->input->post('search');
// Use a model to retrieve the results.
$data['results'] = $this->search_model->get_results($search_term);
// Pass the results to the view.
$this->data['subview'] = ('../views/user/search_results');
$this->load->view('../views/user/search_results', $this->data);
}
}
Any help/ideas? 任何帮助/想法吗? much apreciated
非常感激
您还可以通过在主视图中执行以下操作来加载子视图:
<?php $this->load->view('user/search_form'); ?>
Replacing your controller by this code: 用以下代码替换您的控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Search extends Admin_Controller {
function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->load->helper('form');
$this->load->model('search_model');
}
function index()
{
$data['subview'] = ('../views/user/search_form');
$this->load->view('layout_admin', $data);
}
function execute_search()
{
// Retrieve the posted search term.
$search_term = $this->input->post('search');
// Use a model to retrieve the results.
$data['results'] = $this->search_model->get_results($search_term);
// Pass the results to the view.
$data['subview'] = ('../views/user/search_results');
$this->load->view('search_results', $data);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.