0

>> My controllerv - verifyregistration

<?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
    }
}

>> My view open - 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');
?>

>>My view - 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>

And I have errors:

Severity: Notice Message: Undefined variable: data Filename: register/register_open.php Line Number: 9 this line-> $this->load->view('register/register_view',$data);

Severity: Notice Message: Undefined variable: heading Filename: register/register_view.php Line Number: 48 this line-> <<?php echo $heading;?>

How I can pass the data to another view?

1
  • 1
    First thing to change is class names have the first letter capitalized in the declaration. It should be: class Verifyregistration extends CI_Controller { Commented Oct 25, 2012 at 22:23

1 Answer 1

4

In your controller, change

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

to

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

When you do $this->load->view('view', $variable) it takes $variable and uses the php function extract() to turn the array keys into variables. So, if you want to use the variable $data in a nested view, you have to send another array like I did above.

Sign up to request clarification or add additional context in comments.

6 Comments

When I change this line in my controller to: {$this->load->view('register/register_open',array('data' => $data));} Errors are still this same.
It should work, but to test, please do this: In your register_open view, put die(var_dump($data)); as the first line, and see what it outputs.
when i add this line, I have this error: A PHP Error was encountered Severity: Notice Message: Undefined variable: data Filename: register/register_open.php Line Number: 2 I add: die(var_dump($data));
So, $data isn't getting passed to that view. If you pass an array with 'data' as a key, it should work...
I just tested it on my local copy of CI, and it worked. What version of CI are you using?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.