CodeIgniter Forums

Full Version: call one of the method from another class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Uresh Patel[/eluser]
Respected,

I have two controllers.I want to call one of the method from one class.
Below both class are different controller files
E.g:
Code:
class User extends CI_Controller {

             function index(){
                 //code
             }

              function list(){
                   //i want to call class 'Blog.Add' method....
             }
}


  class Blog extends CI_Controller {

         function index(){
            //code
         }

         function Add(){
              //code
         }
}
Please suggest good way to do so ....

El Forum

[eluser]Otemu[/eluser]
Hi,

The best way to do something like this is either create a library or helper.

Also check out this excellent article CodeIgniter Base Classes: Keeping it DRY.

Hope that helps

El Forum

[eluser]Uresh Patel[/eluser]
HI,

Thank you for reply.But i am looking forward to have a proper solution.i have foggy idea but not clear with it.
We can create instance or can we do like language "C++" using friend function using that access modifier ?????

[quote author="Otemu" date="1366624431"]Hi,

The best way to do something like this is either create a library or helper.

Also check out this excellent article CodeIgniter Base Classes: Keeping it DRY.

Hope that helps[/quote]

El Forum

[eluser]jairoh_[/eluser]
do not use the controller. the proper way is to use model or library or helper. it depends. tell us the purpose of the add function.