• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
header location

#1
[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.

#2
[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)

}

#3
[eluser]huangxiao[/eluser]
Thank you Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.