Welcome Guest, Not a member yet? Register   Sign In
using other controller's method
#1

[eluser]thevenin[/eluser]
Hi guys,

I have two controllers: one for admin panel and one for frontend app.
In both places I need a method which will output an array of objects - let's say the method name is "Rankings".

Admin panel controller:
Code:
class Standings extends Controller {

  ....

  function Rankings() {
    //some code
  }

  ....
}

I would like to call this method in my front controller Frontpage:

Code:
class Frontpage extends Controller {

   //is it possible to call it somehow here?
   //or I have to paste the whole method from Standings controller?

}
#2

[eluser]Mareshal[/eluser]
Frontpage.php

Code:
require "Standings.php";

class Frontpage extends Controller {

   function test(){
        $stang = new Standings();
        $stand::Rankings(); //$stand->Rankings(); works too
   }

}

BUT, this is not recommended. try building rankings() function inside a model/library/helper . Is better.
#3

[eluser]thevenin[/eluser]
Thanks.
#4

[eluser]John_Betong[/eluser]
 
Search this forum for "extends MY_Controller".
 
 
 
#5

[eluser]Phil Sturgeon[/eluser]
Directly calling controllers from other controllers is like bending MVC over a barrel and cracking out a truncheon... That is a horrible way to work and if you find yourself needing to do it then you are clearly doing something wrong.

Either share your code in a library so the logic can be used correctly in both controllers, or redirect users to the correct controller.




Theme © iAndrew 2016 - Forum software by © MyBB