need to display username! |
[eluser]newbie boy[/eluser]
hi everyone!!! im new to this matter, hope you can help me with my problem. i'm still continiously learning and practicing the doctrine. how can i display the user's username to all succeding pages after the user successfully logged-in? hope you'll forgive my stupidity! thanks!!! here's my codes: for my controller: <?php class LoginController extends Controller { function LoginController(){ parent::Controller(); $this->load->database(); $this->load->helper(array('url', 'form')); $this->load->library(array('calendar','validation','session')); } function index(){ $isValid = true; $username = $this->input->post('username'); $password = $this->input->post('password'); if (empty($username)) { $isValid = false; } if (empty($password)) { $isValid = false; } if ($this->session->userdata('logged_in') == '0') { if ($isValid) { $user = new UserModel(); $user = Doctrine_Query::create() ->select('u.*') ->from('UserModel u') ->where('u.user_id = ?', $username) ->fetchone(); $data['newUsername'] = $username; $this->session->set_userdata('logged_in', '1'); $this->session->userdata('username'); redirect('HomeController', $data); } else { $this->load->view('userLoginView','refresh'); } } } ?>; how do I pass the username to the other controller? So I can display them to the succeeding views? Thanks again!
[eluser]OES[/eluser]
Session Data !. http://ellislab.com/codeigniter/user-gui...sions.html If you have a login/logout section to your site then set a users data while logging in. IE a simple model example. Code: //Check against user table Then you can collect your user details from within views or controller passing to a view ie using a controller method. Code: $this->data['user'] = $this->session->userdata('user'); Then within the view file. (As a smarty example) Code: {$user.username} Hope this makes sense to you.
[eluser]newbie boy[/eluser]
this one i can't solve yet! The solution must use the code igniter and doctrine. thanks!
[eluser]manilodisan[/eluser]
What doctrine has to do with passing a username from one page to another? I have a strong feeling you're here with little to no PHP experience at all and all you need is someone to write your code. Do you know what doctrine does?
[eluser]newbie boy[/eluser]
hey manilodisan, did you see my username. It actually read as "newbie boy". Hello. I hope you do know what the word "newbie" means!
[eluser]newbie boy[/eluser]
i tried this but still doesn't display the logged user. anyone? controller: Code: $this->load->library('session'); view: Code: <h3>Welcome <?php echo $username; ?></h3>
[eluser]CIfan1000[/eluser]
Hi, In a redirect function, the 2nd parameter, in your case $data, cannot be data. See the URL helper in the manual for this function. You can pass your data by loading a view. See Views in the manual. Hope this helps.
[eluser]lmv4321[/eluser]
[quote author="newbie boy" date="1225874181"]i tried this but still doesn't display the logged user. anyone? controller: Code: $this->load->library('session'); view: Code: <h3>Welcome <?php echo $username; ?></h3> You should not redirect, you should load a view. In simple terms, a view is a webpage which will display the data that is passed to it from the controller. So, change the redirect line to this: Code: $this->load->view('viewFileName', $data); Change viewFileName to whatever the name is of the view php webpage you create. It should be in the view folder.
|
Welcome Guest, Not a member yet? Register Sign In |