Welcome Guest, Not a member yet? Register   Sign In
Using variables in controller class
#1

[eluser]rossmurphy[/eluser]
Not sure if its a thing to do, but i have been using class vars to store info that is common to a number of methods in my class. Here is an example. Let me know what people think, if i'm doing something i'm not supposed to be, or tips. Thanks.

Code:
<?php
class forgotpassword extends MY_Controller {
    
    var $error = '';
    var $info = '';
    var $response = '';
    var $page_title = '';
    
    function forgotpassword()
    {
        
        parent :: MY_Controller();
        
        // load the models
        $this->load->model('site-api/dogetplayerpassword');
        
        // load libraries
        $this->load->library('email');
        
        $this->page_title = lang('title.forgot.password');
        
    }

    function index()
    {
        
        $data['pageTitle'] = $this->page_title;
        
        // load the views
        $this->load->view('templates/header', $data);
        $this->load->view('templates/public_menutop');
        $this->load->view('members/forgotpassword');
        $this->load->view('templates/footer');
        
    }

    function retrieve_password()
    {
        
        $data['pageTitle'] = $this->page_title;
        
        $api_call = $this->dogetplayerpassword->index();

        $this->response = $api_call["xml"];
        $this->error = $api_call["error"];
        
        if (empty($this->error))
        {
            
            // send the email
            $email_data["password"] = $this->response->row['password'];
            $email_data["site_name"] = $this->config->item('site_name');
            $email_data["support_email"] = $this->config->item('support_email');
            
            $this->email->from($this->config->item('support_email'), $this->config->item('support_name'));
            $this->email->to($this->input->post('email'));

            $this->email->subject(lang('email.subject.forgot.password'));
            
            $message = $this->parser->parse('email-templates/forgot_password_email_'. $this->config->item('default_language').'.txt', $email_data, TRUE);
            $this->email->message($message);
            
            if ($this->email->send())
            {
                
                $this->info = 'msg.forgot.password.success';
                
            }
            else
            {
                
                $this->error = 'email.fail.send';
                
                // log error message
                log_message('error', 'Email failed to send (password recovery).');
                
            }
        
        }
        
        // load the views
        $this->load->view('templates/header', $data);
        $this->load->view('templates/public_menutop');
        $this->load->view('templates/displaymsgs');
        $this->load->view('templates/footer');
                    
    }
    
}
#2

[eluser]rossmurphy[/eluser]
Can anyone improve my code or give me an idea if i am doing anything wrong in regards to CI?
#3

[eluser]contact_kram[/eluser]
I have the same question. Can some CI guru please chime in here?




Theme © iAndrew 2016 - Forum software by © MyBB