繁体   English   中英

传递数据以查看codeigniter

[英]Pass data to view codeigniter

嗨,我需要访问echo $Data->var_....在我看来。 但是,当我尝试使用echo我没有得到数据输出。 如何修复它以便在我的视图中获取数据?

我在这里压缩了一个包含所有三个 PHP 页面的文件。 关联

*控制器 *模型 *视图

提前感谢您的帮助

控制器

{
<?php
class reservationleads extends Front_Controller {

    function __construct() {

        parent::__construct();
        $this->load->model('reservationleads_model', 'module_model');
        $this->module_url = FRONT_MODULE_URL;
        /* if(!empty($_POST)){
        $filename="logrecord/booking_".time().".txt";
        $myfile = fopen($filename, "w") or die("Unable to open file!");
        $txt = "Post\n";
        foreach($_POST as $key=>$value){
        $txt.= $key."=>".$value."\n"; }
        $txt.= "\nSession\n";
        foreach($_SESSION as $key=>$value){
        $txt.= $key."=>".$value."\n"; }
        fwrite($myfile, $txt);
        fclose($myfile); } */
    }

    public function index() {

        $location_idarr = array("60", "61", "62");
        $SegmentArray = $this->uri->rsegment_array();
        $this->common_model->set_page_hits('pages', RECORD_ID, 2, CURRENT_LOCATION);

        /* 58,63,64 */
        $CurrentPageData = $this->common_model->getpagedata(RECORD_ID, "pages");
        $Seo_array['title'] = $CurrentPageData['var_metatitle'];
        $Seo_array['keywords'] = $CurrentPageData['var_metakeyword'];
        $Seo_array['description'] = $CurrentPageData['var_metadescription'];

        $canonicalurl = SITE_PATH . LOCATION_ALIAS . '/' . $CurrentPageData['var_alias'];
        $this->viewData['CanonicalURL'] = $canonicalurl;

        $this->common_model->get_metadata($Seo_array);
        if (in_array($SegmentArray[3], $location_idarr)) {

            $this->viewData['ContactDetail'] = $this->common_model->get_contactdetail();
            $banner_query = $this->module_model->selectAll_Banner();
            $this->viewData['banner_data'] = $banner_query->result_array();
            $this->viewData['banner_count'] = $banner_query->num_rows();
            /* $bookingid = $_SESSION['BOOKING_ID']; */



            /* if (empty($bookingid)) {
                $excu_idarr = array("6", "7", "8");
                $location_page = $this->common_model->getpagedataForCMS($excu_idarr, 'pages', CURRENT_LOCATION);
                redirect(SITE_PATH . LOCATION_ALIAS . "/" . $location_page['var_alias']);
                exit;
            } */
            if($this->input->get_post('BookingId')!=''){
                $bookingid = $_GET['BookingId'];
                $booking_data = $this->module_model->select_Rows($bookingid);
            } else {
                $specialid = $_GET['SpecialId'];
                $booking_data = $this->module_model->select_Special_Rows($specialid);
            }

            $name = $booking_data['var_firstname'] . ' ' . $booking_data['var_lastname'];
            $thankyou_meta = $CurrentPageData['var_metatitle'] . " " . $name . " for booking " . $booking_data['Activity'] . " with Discount Excursions";

            $this->viewData['booking_data'] = $booking_data;
            $Seo_array['title'] = $thankyou_meta;

            $this->common_model->get_metadata($Seo_array);
            $banner_query = $this->module_model->selectAll_Banner();
            $this->viewData['banner_data'] = $banner_query->result_array();
            $this->viewData['banner_count'] = $banner_query->num_rows();
            $this->viewData['ContentPanel'] = 'front/thankyou_tpl';
        } else {

            if($this->input->get_post('special', TRUE)!=''){
                $specialname = $this->input->get_post('special', TRUE);
                $query_rs = $this->module_model->get_specialnamedata($specialname);
                $specialdata = $query_rs->row();
                $specialcount = $query_rs->num_rows();
                $specialid = $specialdata->int_glcode;
                $special_name = $specialdata->var_title;
                $this->viewData['location_name']  = $specialdata->location_title;
                $this->viewData['location_alias'] = $specialdata->location_alias;
                $this->viewData['activity_combo'] = $this->module_model->special_combo($specialid);
            } else {
                $tourname = $this->input->get_post('tour', TRUE);
                $query_rs = $this->module_model->get_tourdata($tourname);
                $tourdata = $query_rs->row();
                $tourcount = $query_rs->num_rows();
                $tourid = $tourdata->int_glcode;
                $tour_name = $tourdata->var_title;
                $this->viewData['location_name'] = $tourdata->location_title;
                $this->viewData['location_alias'] = $tourdata->location_alias;
                $this->viewData['activity_name'] = $tour_name;
                $this->viewData['activity_combo'] = $this->module_model->activity_combo($tourid);
            }


            $this->viewData['activitytime_combo'] = $this->module_model->Timecombo($id);

            $this->viewData['departure_combo'] = $this->module_model->Departurecombo($id, $style = "");
            $this->generateCaptcha();

            $this->viewData['CurrentPageData'] = $this->common_model->getpagedata(RECORD_ID, "pages");
            $Seo_array['title'] = $CurrentPageData['var_metatitle'];
            $Seo_array['keywords'] = $CurrentPageData['var_metakeyword'];
            $Seo_array['description'] = $CurrentPageData['var_metadescription'];

            $this->common_model->get_metadata($Seo_array);

            $banner_query = $this->module_model->selectAll_Banner();
            $this->viewData['banner_data'] = $banner_query->result_array();
            $this->viewData['banner_count'] = $banner_query->num_rows();
            $location_query = $this->module_model->getlocation_excursion();
            $this->viewData['location_excursion_numrows'] = $location_query->num_rows();
            $this->viewData['location_excursion'] = $location_query;

            $this->viewData['ContentPanel'] = 'front/book_now_tpl';
        }
        $this->load_view();
    }


    function generateCaptcha() {

        $this->session->set_userdata("pin_value", md5(rand(2, 99999999)));
        $generated_pin = $this->mylibrary->generate_pin($this->session->userdata("pin_value"));
        $this->viewData['generated_pin'] = $generated_pin;
        $this->viewData['captcha_core_value'] = $this->mylibrary->cryptPass($generated_pin);
        $this->session->set_userdata('generated_pin_activity_reservation', $generated_pin);

        $pin_image_output = $this->mylibrary->show_pin_image($this->session->userdata("pin_value"), $generated_pin);
        $this->viewData['pin_image_output'] = $pin_image_output;
    }

    public function refershcaptcha() {
        $this->session->set_userdata("pin_value", md5(rand(2, 99999999)));
        $generated_pin = $this->mylibrary->generate_pin($this->session->userdata("pin_value"));
        $this->viewData['generated_pin'] = $generated_pin;
        $captcha_core_value=$this->mylibrary->cryptPass($generated_pin);
        $this->session->set_userdata('generated_pin_activity_reservation', $generated_pin);
        echo $this->mylibrary->show_pin_image($this->session->userdata("pin_value"), $generated_pin) . '#' . $generated_pin.'#'.$captcha_core_value;
        exit;
    }

    public function insert() {

        if (!$this->input->post()) {
            redirect(SITE_PATH . LOCATION_ALIAS . "/" . MODULE);
        }

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->form_validation->set_rules('var_firstname', 'First Name', 'trim|required');
        /* $this->form_validation->set_rules('var_lastname', 'Last Name', 'trim|required'); */
        $this->form_validation->set_rules('fk_activity', 'Excursion', 'trim|required');
        $this->form_validation->set_rules('dt_excursiondate', 'Excursion Date', 'trim|required');
        $this->form_validation->set_rules('var_email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('var_phone', 'Phone', 'trim|required');
        $this->form_validation->set_rules('int_no_of_people', 'No of People', 'trim|required');
        $this->form_validation->set_rules('int_no_of_child', 'No of child', 'trim|required');
        $this->form_validation->set_rules('fk_port_of_departure', 'Port Of Departure', 'trim|required');

        if ($_SESSION['is_mobile_browser'] == 'no') {
            $this->form_validation->set_rules('var_captcha', 'Captcha', 'trim|required|callback_valid_captcha');
        }

        if ($this->form_validation->run($this) == FALSE) {
            $this->index();
        } else {

            $insertData = $this->module_model->insert();

            /* $thank = $this->common_model->getpagedata(60, 'pages'); */
            $location_idarr = array("60", "61", "62");
            $location_page = $this->common_model->getpagedataForCMS($location_idarr, 'pages', $this->input->post('fk_location'));
            $thankyou = SITE_PATH . LOCATION_ALIAS . '/thankyou?BookingId='.$insertData;
            redirect($thankyou);
        }
    }

    public function insertspecial() {

        $activity = $this->input->post('fk_activity', TRUE);
        $activity_val = substr($activity,0,1);
        if($activity_val=="A"){
            $this->insert();
        }else{
                if (!$this->input->post()) {
                redirect(SITE_PATH . LOCATION_ALIAS . "/" . MODULE);
            }

            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            $this->form_validation->set_rules('var_firstname', 'First Name', 'trim|required');
            /* $this->form_validation->set_rules('var_lastname', 'Last Name', 'trim|required'); */
    //        $this->form_validation->set_rules('fk_special', 'Excursion', 'trim|required');
            $this->form_validation->set_rules('dt_excursiondate', 'Excursion Date', 'trim|required');
            $this->form_validation->set_rules('var_email', 'Email', 'trim|required|valid_email');
            $this->form_validation->set_rules('var_phone', 'Phone', 'trim|required');
            $this->form_validation->set_rules('int_no_of_people', 'No of People', 'trim|required');
            $this->form_validation->set_rules('int_no_of_child', 'No of child', 'trim|required');
            $this->form_validation->set_rules('fk_port_of_departure', 'Port Of Departure', 'trim|required');

            if ($_SESSION['is_mobile_browser'] == 'no') {
                $this->form_validation->set_rules('var_captcha', 'Captcha', 'trim|required|callback_valid_captcha');
            }

            if ($this->form_validation->run($this) == FALSE) {
                $this->index();
            } else {

                $insertData = $this->module_model->insert_special();

                /* $thank = $this->common_model->getpagedata(60, 'pages'); */
                $location_idarr = array("60", "61", "62");
                $location_page = $this->common_model->getpagedataForCMS($location_idarr, 'pages', $this->input->post('fk_location'));
                $thankyou = SITE_PATH . LOCATION_ALIAS . '/thankyou?SpecialId='.$insertData;
                redirect($thankyou);
            }
        }
    }



    public function thankyou() {


        $banner_query = $this->module_model->selectAll_Banner();
        $this->viewData['banner_data'] = $banner_query->result_array();
        $this->viewData['banner_count'] = $banner_query->num_rows();
        /* $BookingId = $_SESSION['BOOKING_ID']; */        

        if($this->input->post('BookingId')!='')
            $BookingId = $_GET['BookingId'];
        else
            $SpecialId = $_GET['SpecialId'];

       /* if (empty($bookingid)) {
            $excu_idarr = array("6", "7", "8");
            $location_page = $this->common_model->getpagedataForCMS($excu_idarr, 'pages', CURRENT_LOCATION);

            redirect(SITE_PATH . LOCATION_ALIAS . "/" . $location_page['var_alias']);
        } */

        if($BookingId!=''){
            $booking_data = $this->module_model->select_Rows($BookingId);
        }else{
            $booking_data = $this->module_model->select_Special_Rows($SpecialId);
        }

        $this->viewData['booking_data'] = $booking_data;

        $CurrentPageData = $this->common_model->getpagedata(RECORD_ID, "pages");
        $Seo_array['title'] = $CurrentPageData['var_metatitle'];
        $Seo_array['keywords'] = $CurrentPageData['var_metakeyword'];
        $Seo_array['description'] = $CurrentPageData['var_metadescription'];
        $this->common_model->get_metadata($Seo_array);
        $this->viewData['ContentPanel'] = 'front/thankyou_tpl';
        /* unset($_SESSION); */
    }




    function valid_captcha() {

        /* if ($this->session->userdata('generated_pin_activity_reservation') != $this->input->get_post('var_captcha')) { */
        if ($this->input->get_post('captcha_core_value') != $this->mylibrary->cryptPass($this->input->get_post('var_captcha'))) {
            $this->form_validation->set_message('valid_captcha', 'Please enter the captcha code exactly as mentioned in order to verify and continue.');
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function get_review_data() {
        $tour = $this->input->get_post('fk_activity');
        $tour=  explode("-",$tour);
        $location = $this->input->get_post('fk_location');
        if($tour[0]=='S'){
            echo $review_data = $this->module_model->select_Special_Review_data($location, $tour[1]);
        } else {
            if(count($tour)==2)
                $tour=$tour[1];
            else
                $tour=$tour[0];
            echo $review_data = $this->module_model->select_Review_data($location, $tour);
        }
        exit;
    }
}
?>
}

我相信问题是这一行:

$this->load_view();

您需要以这种方式加载视图:

$this->load->view("viewname", $data_to_pass_array);

你在哪里定义这个: $this->viewData 是不是来自: FRONT_MODULE_URL; ? 如果是这样,您不包括该代码

第一技术

我出于某种目的在视图中传递与管理员相关的电子邮件

//First I get the Modal's result in a variable
$data['user_e_mail'] = $this->m_user->getUserEmail("t_users");

//Then, I pass the variable in the view
$this->load->view("admin_panel", $data);

第二种技术

您可以在变量中加载特定视图并向其传递一些值。 以下是我加载并保存在$data['head_top_bar'] 中的 Navbar/titlebar/ topbar

$data['head_top_bar']   = $this->load->view('templates/top_bar' , $login_data, TRUE);

不,如果你在视图中传递 $data,你可以简单地

echo $head_top_bar;

并且您将使用您之前提供的 $login_data 输入加载该导航栏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM