How to access a variable in a view from a controller?? |
[eluser]flyingfish[/eluser]
Hi All, I'm new to CI and as a project to get my feet wet Im rewriting a small app to use the CI framework. My question is how do I access the value of a input variable in a view from the controller of that view? Thanks for any examples! cheers! davej
[eluser]bubbafoley[/eluser]
http://ellislab.com/codeigniter/user-gui...views.html
[eluser]flyingfish[/eluser]
Hi bubbafoley, Thanks for your response. Basically I have a logon screen and want to access the values entered by the user so I can validate them against a database of users. So my view file looks like: [code above here] <td width="286" align="left" valign="top"> <label> <input name="username" type="text" id="username" maxlength="16" value="<?php echo set_value('username'); ?>" /> </label> <?php echo form_error('username'); ?> </td> </tr> <tr> <td align="left" valign="top"><strong>Password:</strong></td> <td align="left" valign="top"> <label> <input type="password" name="password" id="password" value="<?php echo set_value('password'); ?>" /> </label> <?php echo form_error('password'); ?> </td> </tr> [code below here] and my controller looks like: [code above here] $this->load->database(); //set validation ruels $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|max_length[16]|xss_clean'); $this->form_validation->set_rules('password', 'Password', 'trim|required'); if ($this->form_validation->run() == FALSE) { $this->load->view('index'); } else { //check details and give login page if all ok $sql = "SELECT iduser FROM fmg_user WHERE (status = 'A') AND username = ? AND password = ?"; $result = $this->db->query($sql, array([username need to be here],[passwrd needs to be here])); [code below here] How to I get the username and password values from the input variables into code above? cheers! davej
[eluser]bubbafoley[/eluser]
ah, i see now. use $this->input->post() to get form data Code: $username = $this->input->post('username'); OR you can use CI's active record Code: $result = $this->db->select('iduser')
[eluser]CroNiX[/eluser]
The first manual example above is not safe as you are not escaping your input. AR does it automatically. $var = $this->db->escape($var);
|
Welcome Guest, Not a member yet? Register Sign In |