Welcome Guest, Not a member yet? Register   Sign In
Call a controller from a library
#3

(01-29-2016, 03:45 AM)Narf Wrote: You shouldn't do this ... calling a controller from a library is the complete opposite of making it independent.

Controllers are application-specific, libraries are not - that's the main difference between them. When you call a controller from within a library, that makes the controller a dependency for your library, and that in turn means that your library is no longer portable.

mmm =( you right...you damn right...so I have to loose my intention to write a library =( to do an example I have this function

PHP Code:
 public function login_validation(){
        
// caricamento della librerira per la validazione del form
        
$this->load->library('form_validation');

        
// setting delle regole per input
        //il callback rimanda ad una funzione dello stesso controller che controlla le credenziali d'accesso
        
$this->form_validation->set_rules('email','Email','required|trim|callback_validate_credentials');
        
$this->form_validation->set_rules('password','Password','required|md5|trim');

        
// la funzione run ritorna un true solo se le regole sopra sono verificate
        
if ($this->form_validation->run() == true) {
            
//salviamo la mail nella sessione, se i dati sono esatti. e impostiamo un flag a 1.
            
$data = array('email' => $this->input->post('email'),
                                         
'is_logged_in' => true);
            
$this->session->set_userdata($data);
            
$this->members();
        } else {
            
$this->login();
        } 

where members(); and login(); that you see at the end are function of the same controller.
With a code like this there is no way to make a library...
Reply


Messages In This Thread
Call a controller from a library - by Psygnosis - 01-29-2016, 03:38 AM
RE: Call a controller from a library - by Narf - 01-29-2016, 03:45 AM
RE: Call a controller from a library - by Psygnosis - 01-29-2016, 04:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB