variable in controller for view |
hello , how do I store the result of a field of a table in a variable in the controller and access that variable in the view ? what I wanted was to display the user's name in superios bar of my system , example after the user logs appears "Hello user"
thanks You Ps . Excuse my English , I am Brazilian .
Hello, i hope to answer your problem
PHP Code: class User_controller extends CI_controler have a good day
With Session, for example, at the connexion, you store a value in a session variable like this for example :
PHP Code: $this->session->set_userdata('key', 'balbla'); You control that the session user is again available by controlling the existence of your session variable ($this->session->userdata('key')) defined before. After you can do everything with session variables. If you get a variable in your controller like the example before "public function get_first_view($id_user)", think to control the type of the variables. For example, here, if $id_user would be an integer, think to protect and cast the variable like this for example : [php] $id_user = (int) $this->security->xss_clean($id_user) ; // cast to integer and secure agaist xs attack I hope that help you. Refer to userguide of CI3 or CI2 switch your version. Have a good day.
Hello Casa ,
I looked and studied the documentation and I could do what I wanted , I used session , follows the code : Code: $query = $this->db->query("select email, usuario, senha from usuarios where email = '$email' and senha = '$senha'"); Thank you for your help , thanks very much Problem resolved ^^
Hello,
It's with pleasure. ![]() I advise you that for your query (to secure it) PHP Code: $query = $this->db->query("select email, usuario, senha from usuarios where email = '$email' and senha = '$senha'"); |
Welcome Guest, Not a member yet? Register Sign In |