Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我可以在codeigniter中的函数之间传递数据吗?_Php_Forms_Codeigniter - Fatal编程技术网

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?