Welcome Guest, Not a member yet? Register   Sign In
Ion Auth - Lightweight Auth System based on Redux Auth 2

[eluser]Andy78[/eluser]
I'm also a little confused about $this->data as opposed to $data. Where is the $this->data array set? Can somebody explain it to me?

For example its used in the login() and in the create_user() functions but in order for me to pass additional $formdate data and data for a country selectbox to my create_user view I had to do
Code:
$data['formdate'] = $formdate;
and

Code:
$data['country'] = $this->country_model->country_select();

because
Code:
$this->data['country'] = $this->country_model->country_select();
would not work.

Here is my create_user function to make things clearer:

Code:
function create_user()
    {  
        $this->data['title'] = "Create User";
        
        $yearmin = date("Y", strtotime('-18 years'));
        $this->load->model('country_model');        
        $this->load->library('formdate');
        //set date params
        $formdate = new FormDate();
        $formdate->setLocale('nl_BE');
        $formdate->year['start'] = 1930;
        $formdate->year['end'] = $yearmin;
        $formdate->year['descend'] = true;
        $formdate->month['values'] = 'string';
        $formdate->month['selected'] = 'January';
        $formdate->day['selected'] = '1';
        
        $data['formdate'] = $formdate;
        
        $data['country'] = $this->country_model->country_select();    
              
        if ($this->ion_auth->logged_in() || $this->ion_auth->is_admin()) {
            redirect('auth', 'refresh');
        }
        
        //validate form input
        $this->form_validation->set_rules('name', 'Name', 'required|xss_clean');
        $this->form_validation->set_rules('username', 'Username', 'required|xss_clean');
        $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required|min_length['.$this->config->item('min_password_length', 'ion_auth').']|max_length['.$this->config->item('max_password_length', 'ion_auth').']|matches[password_confirm]');
        $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('gender', 'Gender', 'required|xss_clean');
        $this->form_validation->set_rules('country', 'Country', 'trim|required');
        $this->form_validation->set_rules('day', 'Day', 'trim|required|callback_valid_country');
        $this->form_validation->set_rules('month','Month', 'trim|required');
        $this->form_validation->set_rules('year','Year', 'trim|required|callback_valid_date');

        if ($this->form_validation->run() == true) {
            $username  = $this->input->post('username');
            $email     = $this->input->post('email');
            $password  = $this->input->post('password');
            
            $additional_data = array('name' => $this->input->post('name'),
                                     'gender'  => $this->input->post('gender'),
                            'country'    => $this->input->post('country'),
                            'dateofbirth'      => $this->input->post('year') .'-'. $this->input->post('month') .'-'. $this->input->post('day'),
                               );
        }
        if ($this->form_validation->run() == true && $this->ion_auth->register($username,$password,$email,$additional_data)) { //check to see if we are creating the user
                //redirect them back to the admin page
            $this->session->set_flashdata('message', "User Created");
               redirect("auth", 'refresh');
        }
        
        else { //display the create user form
            //set the flash data error message if there is one
            $data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
            
            $this->load->view('auth/create_user', $data);
        }
        
    }


Messages In This Thread
Ion Auth - Lightweight Auth System based on Redux Auth 2 - by El Forum - 11-04-2010, 10:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB