Welcome Guest, Not a member yet? Register   Sign In
how do I get all methods from controller?
#1

[eluser]wise_fox[/eluser]
Hi all,

Can somebody help me in this complicated question?
I need to get methods names from controller A within controller B.

I know there is php function get_class_methods(), but it doesn't work for me.
#2

[eluser]toopay[/eluser]
Before you use get_class_methods(), you must include 'controller A' first!
Code:
public function get_allmethods()
{
   include_once '/application/controllers/some_controller'.EXT;
   print_r(get_class_methods('Some_controller'));
}
#3

[eluser]wise_fox[/eluser]
Hey,

Yes. I know about this, but when I include some controller my current object "$this" will be replaced with name of inclueded controllers and I'll get errors like this:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Auth::$db

Filename: core/Model.php

Line Number: 50
#4

[eluser]toopay[/eluser]
Above explanation is about how to returns an array of method names, NOT TO USE THAT!

If you're want some function available in any controller, or even in your model, your option is:
1. If your function is simple enough, and doesn't need any CI resource, you could create a helper class.
2. If your function is uses some CI resource (like session, db, form_validation, and so on), you could create a library.
3. If you need some function run EVERYTIME, you could set a hook.
4. If you need some function which only at Controller scope, you could create a base controller which can extended by other controller.

In addition, before you came back to this thread and ask : "HOW TO DO THAT?", please check the CodeIgniter user guide corresponding with above option.
#5

[eluser]wise_fox[/eluser]
My goal is to get methods names from every controller.
I have already needed code, but something goes wrong.
I use this helper to get controller instance http://ellislab.com/forums/viewreply/284124/
But I'd like to create instance of some controller and then destroy it. Maybe it seems I'm not excellent coder, but it's not clear for me how to get it works.
#6

[eluser]toopay[/eluser]
If you follow that thread, based MVC approach, its clearly recommended (as i stated above) to use library, helper or modular hmvc instead include the controller directly!

And there is no such thing of ‘create instance of some controller and then destroy it’. Once you include some class, then it will be stayed there!

If, you’re, in some (very rare) case, want to easily generate a result from some controller’s function, use proxy technique instead includes the controller class. Look at my signature, play with it will give you an idea how to do that.

Btw, i’m absolutely have no intend, to say are you good or bad programmer. I don’t know why or how my last response, put you in that way.




Theme © iAndrew 2016 - Forum software by © MyBB