0

>> 我的控制器 - 验证注册

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class verifyregistration extends CI_Controller {

function __construct()
{
    parent::__construct();
    $this->load->model('users_model','',TRUE);
    $this->load->library('email');
}

function index()
{
    //This method will have the credentials validation
    $this->load->library('form_validation');

    $this->form_validation->set_rules('Login', 'Login', 'trim|required|xss_clean|callback_check_database|min_length[6]|strtolower|callback_username_not_exists');
    $this->form_validation->set_rules('Haslo', 'Haslo', 'trim|required|xss_clean|min_length[6]');
    $this->form_validation->set_rules('Powtorz_Haslo', 'Powtorz haslo', 'trim|required|xss_clean|matches[Haslo]|min_length[6]');
    $this->form_validation->set_rules('Imie', 'Imie', 'trim|required|xss_clean|min_length[2]');
    $this->form_validation->set_rules('Nazwisko', 'Nazwisko', 'trim|required|xss_clean');
    $this->form_validation->set_rules('Email', 'Email', 'trim|required|xss_clean|valid_email|min_length[6]');
    $this->form_validation->set_rules('Data_urodzenia', 'Data urodzenia', 'trim|required|xss_clean');
    $this->form_validation->set_rules('Telefon', 'Telefon', 'trim|required|xss_clean|min_length[8]');
    $this->form_validation->set_rules('Miasto', 'Miasto', 'trim|required|xss_clean');
    $this->form_validation->set_rules('Ulica', 'Ulica', 'trim|required|xss_clean|min_length[6]');
    $this->form_validation->set_rules('Kod_pocztowy', 'Kod pocztowy', 'trim|required|xss_clean');
    $this->form_validation->set_error_delimiters('<span style="color: red; font-size:    12px; ; line-height: 14px; ">', '</span>');
    $this->form_validation->set_error_delimiters('<li>', '</li>');
    $data['heading'] = "My Real Heading";  

    if($this->form_validation->run() == FALSE)
    {
        $this->load->view('register/register_open',$data);
    }
    else
    {
        return false;  //this is not important
    }
}

>> 我的视图打开 - register_open

<?php
$this->load->view('mains/header'); 
$this->load->view('login/loggin');
$this->load->view('mains/menu');
$this->load->view('left_column/left_column_before');
$this->load->view('left_column/menu_left');
$this->load->view('left_column/left_column');
$this->load->view('center/center_column_before');
$this->load->view('register/register_view',$data);
$this->load->view('center/center_column');
$this->load->view('right_column/right_column_before');
$this->load->view('right_column/right_column');
$this->load->view('mains/footer');
?>

>>我的观点 - register_view

<?php echo form_open('verifyregistration/index'); ?>
    <form>
        <label for="username">Login:</label>
        <input type="text" size="25" id="Login" name="Login" set_value='Login' /> 
        .
        .
        .

        <legend>
            <input type="checkbox" id="regulamin" name="Regulamin" onclick="this.form.elements['Wyslij'].disabled = !this.checked" /> 
            Akceptuję regulamin serwisu. </legend>

            <label>&nbsp;</label>
            <input type="submit" name="Wyslij" value="Wyslij" disabled="disabled"/>
            <label>&nbsp;</label>

        <legend>
            <<?php echo $heading;?>
        </legend>
    </form>

我有错误:

严重性:通知消息:未定义变量:数据文件名:register/register_open.php 行号:9 此行->$this->load->view('register/register_view',$data);

严重性:通知消息:未定义变量:标题文件名:register/register_view.php 行号:48 此行-><<?php echo $heading;?>

如何将数据传递到另一个视图?

4

1 回答 1

4

在您的控制器中,更改

$this->load->view('register/register_open',$data)

$this->load->view('register/register_open',array('data' => $data));

当你这样做时$this->load->view('view', $variable),它需要$variable并使用 php 函数extract()将数组键转换为变量。所以,如果你想$data在嵌套视图中使用变量,你必须像我上面那样发送另一个数组。

于 2012-10-25T22:26:42.670 回答