我将一个简单的表单作为子视图加载,我需要将数据传递给下一个函数,但是当我使用$this->data
时,我得到一个空白页面。这是我的控制器:
<?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);
}
}
任何帮助/想法?非常贬值
答案 0 :(得分:0)
您也可以在主视图中加载子视图:
<?php $this->load->view('user/search_form'); ?>
答案 1 :(得分:0)
使用以下代码替换您的控制器:
<?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);
}
}