Welcome Guest, Not a member yet? Register   Sign In
Do i HAVE to use a helper file?

I want to call validate_username but php says the function is undefined. Do I have to use a helper file to use internal functions or something?

Please ignore the actual code this is my first time using CI I am just figuring out how everything works.


class User extends Controller
    function add($username, $password)
        $data['variables'] = array("username" => $username,
                                   "password" => hash("sha256", $password),
                                   "user_valid" => validate_username($username));

        $this->load->view('output', $data);
    function validate_username($username)
        $this->form_validation->min_length($username,4) &&
        $this->form_validation->max_length($username,15) &&
        $this->form_validation->alpha_numeric($username) &&
        is_string($username[0]);// && //make sure the first character is not a number

/* End of file user.php */
/* Location: ./system/application/controllers/user.php */

[eluser]Michael Wales[/eluser]
You are in an object oriented development environment - you need to tell PHP what class to find that particular function in. In this case, $this works just fine.

$data['variables'] = array("username"   => $username,
                           "password"   => hash("sha256", $password),
                           "user_valid" => $this->validate_username($username));

On a side note, you probably want to make that function private by prepending an underscore (function _validate_username). Otherwise it is accessible via the URI.

Theme © iAndrew 2016 - Forum software by © MyBB