• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
call function beetween controllers

#1
[eluser]GabrieleMartino[/eluser]
Hi, is it possible to execute a function beetween controllers without making a redirect?
Thanks

#2
[eluser]TheFuzzy0ne[/eluser]
Can you be more specific?

If you need shared functionality, it's probably best to put it into a library or helper, or to create a base controller which has the functionality you require, and extend that from the other controllers that require it.

#3
[eluser]Seto El Kahfi[/eluser]
[quote author="GabrieleMartino" date="1363162965"]Hi, is it possible to execute a function beetween controllers without making a redirect?
Thanks[/quote]
Do you mean making instance from another controller? As long as I know, CI restrict you from do that method. Maybe I'm wrong.

#4
[eluser]GabrieleMartino[/eluser]
[quote author="TheFuzzy0ne" date="1363163937"]Can you be more specific?

If you need shared functionality, it's probably best to put it into a library or helper, or to create a base controller which has the functionality you require, and extend that from the other controllers that require it.[/quote]

Of course, thanks.

I have in my pages controller the following function

Code:
public function pick_up($user_id){
            /* Questo metodo fa riferimento agli id ma per via della
             * Select nella DROPDOWNLIST della home è stato chiamato
             * id anche Select not necessary che è una stringa.
             *
             */
            
            $name_language = $this->input->post('languages');//The language of the site
            $email = $this->session->userdata('email');
            $this->users_model->set_current_chat_by_email($email,'1'); //This set the current chat to no one
            $subjects = $this->input->post('subject'); //The subject of the room
            if($subjects == ''){    //If no subject is specified
                redirect('chat/enter_living_room/'.$this->input->post('languages')); //enter the lounge
            }
            
            $data['title'] = 'Safe Memoirs';
            $data['subjects'] =  $subjects;
            $data['language'] = $this->languages_model->get_language_by_name($name_language);
            //The numbers of room active with the same subject
            $data['number_rooms'] = $this->chats_model->number_online($subjects,$data['language']);
            //Load language files
            if ($this->session->userdata('language')!== FALSE){
                    $this->lang->load('menu',$this->session->userdata('language'));
                    $this->lang->load('pick_up',$this->session->userdata('language'));
                }else{
                    $this->lang->load('menu','english');
                    $this->lang->load('pick_up','english');
                }
            $this->load->view('templates/header', $data);
            $this->load->view('templates/menu');
            $this->load->view('pages/pick_up', $data);
     $this->load->view('templates/footer', $data);
        }

And in my chat controller

Code:
public function enter_living_room($language){
            $this->lang->load('chat_view',$this->session->userdata('language'));
            $subject = $this->lang->line('living_room');
            $chat_id =  $this->chats_model->exist_room($subject,$language);//If a living_room already exist
            if($chat_id == false){
                $this->create_new_living_room($subject,$language);
                $chat_id =  $this->session->userdata('chat_id');  
            }
            $this->session->set_userdata('room','living_room');
            $this->enter($chat_id,'false');
        }

#5
[eluser]TheFuzzy0ne[/eluser]
Would it not make more sense to make a library, and then manipulate that from your controllers?

#6
[eluser]Otemu[/eluser]
[quote author="TheFuzzy0ne" date="1363168677"]Would it not make more sense to make a library, and then manipulate that from your controllers?[/quote]

As the TheFuzzy0ne said best to use a library then you could use something like this:
Code:
$this->yourLibrary->yourFunction('do something’)



Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.