Welcome Guest, Not a member yet? Register   Sign In
How to call a method in another controller
#1

[eluser]WebMada[/eluser]
Hello everybody!

I want to use a method of another class (controller more exactly).
But a code like the following does not work:
$object = new MySQLClass ();
$num_rows = $object-> getNumRows ();

How to do?

Thanks in advance!
#2

[eluser]LuckyFella73[/eluser]
In your case you would set up a model with your database method.
load the model in every controller you need the method and just
call it.
#3

[eluser]WebMada[/eluser]
I want to call a method in another controller but not a model
#4

[eluser]LuckyFella73[/eluser]
Ok. Looking at your example all I can say is you would set up a model
for that kind of tasks.
#5

[eluser]CroNiX[/eluser]
You can't (easily) use a controller from another controller. If you have a controller that has methods that need to be used in other controllers, create a library and then use that whereever you need. You can also, as mentioned above, create a different model and call that model from whatever controller you need, or autoload it and use it everywhere if its a major component such as an authorization module.
#6

[eluser]WebMada[/eluser]
OK, I think I'll use your technics: create a model or a library!

I also want to hear your opinions about the technics that I used before: to inherit a class from the class which contains the method to use

class Infos extends Controller {
public function X(){}
}

class DataBinds extends Infos {
}
#7

[eluser]wiredesignz[/eluser]
Or try Modular Extensions - HMVC
#8

[eluser]WebMada[/eluser]
I relaunch this item because till now I haven't yet found the solution

I have to use it in UNIT TEST, execute all test methods in all controllers
#9

[eluser]Atik[/eluser]
I am not sure but u can try Scope Resolution Operator (:Smile Like classname::method()
#10

[eluser]WebMada[/eluser]
[quote author="Atik" date="1294442357"]I am not sure but u can try Scope Resolution Operator (:Smile Like classname::method()[/quote]

That doesn't work!

But someone said me that I wrongly use the MVC model because all treatment methods are to put in models, we just use controllers for retrieving $_POST or $_GET datas and calling views.

So I have to move my methods written in controllers in models, model is not just for database interface




Theme © iAndrew 2016 - Forum software by © MyBB