CodeIgniter Forums

Full Version: header location
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]huangxiao[/eluser]
Hi, can you help me please i am still learning the code igniter,..how can i pass variable using header location

like this

login_controller
Code:
function members(){
        $username = $this->session->userdata('username');

        $data['user'] = $username;
  
       header("location:".base_url()."index.php/success/page/home/$data");

    }

this is the error in loguser_view

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: user
Filename: views/loguser_view.php
Line Number: 47


Thank you in advance.

El Forum

[eluser]Tpojka[/eluser]
Code:
header("location:".base_url()."index.php/success/page/home/$data");
Will redirect you to:
controller Success/
method page/
with arguments home/
and $data as provided.

[url=
http://ellislab.com/codeigniter/user-gui...gniterURLs[/url]

If not changed anything in [url=
http://ellislab.com/codeigniter/user-gui...]route.php[/url]
file.

If you want to pass variable to your some_view.php file, you don't need to
use redirect function, but just loading [url=
http://ellislab.com/codeigniter/user-gui....html]view[/url].
Pay attention of 'Adding dynamic data to view' section of the page. That
would be needed part.

Code:
public function members(){
$username = $this->session->userdata('username');

$data['user'] = $username;

$this->load->view('name_of_view_file_without_php_extension', $data);
// in view file you have approach to this variable simply calling it with
*$user* (no stars)

}

El Forum

[eluser]huangxiao[/eluser]
Thank you Smile