Php 我可以在codeigniter中的函数之间传递数据吗?
我正在加载一个简单的表单作为子视图,我需要将数据传递给下一个函数,但是当我使用Php 我可以在codeigniter中的函数之间传递数据吗?,php,forms,codeigniter,Php,Forms,Codeigniter,我正在加载一个简单的表单作为子视图,我需要将数据传递给下一个函数,但是当我使用$this->data时,我会得到一个空白页面。这是我的控制器: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Search extends Admin_Controller { function __construct() { parent::__construct(
$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);
}
}
您也可以通过在主视图中执行以下操作加载子视图:
<?php $this->load->view('user/search_form'); ?>
用以下代码替换控制器:
<?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);
}
}
您好,我认为您需要阅读所有codeigniter的文档,因为当您在应用程序/views/…
中加载视图时,您不需要使用$this->load->view('../views/--
仅$this->load->view('views/…
然后,当您向视图发送$data时,您需要的是$this->load->view('../views/view\u-tamplate',$data);
作为文档,您使用$this->data的目的是什么?为什么不使用$data?