Welcome Guest, Not a member yet? Register   Sign In
how to get list of the controller methods
#1

[eluser]EugeneS[/eluser]
Hello,

any one knows how to get list of some controller methods from the another controller ?

so for example if i go to the url like

http://something.com/listmethods

i receive list of methods from another controller (not from that which i call through the url)

the only way i see is to use get_class_methods php function, but unfortunately i cant find a way to call one controller from another Sad

please do not suggest class parsing with preg_match Smile

any ways to do this with the CI ?
#2

[eluser]PauloBr[/eluser]
I do not know if it is the best way but I did include the class, I made an instance of it and used the function get_class_methods() with this object.

Like this:
Code:
include("anothercontroller.php");
$obj = new AnotherController();
$arr = get_class_methods($obj);

echo "<pre>";
print_r($arr);
echo "</pre>";

And the output:
Code:
Array
(
    [0] => AnotherController
    [1] => index
    [2] => anotherfunction
    [3] => Controller
    [4] => _ci_initialize
    [5] => _ci_scaffolding
    [6] => CI_Base
    [7] => get_instance
)
#3

[eluser]EugeneS[/eluser]
[quote author="PauloBr" date="1196461187"]I do not know if it is the best way but I did include the class, I made an instance of it and used the function get_class_methods() with this object.

Like this:
Code:
include("anothercontroller.php");
$obj = new AnotherController();
$arr = get_class_methods($obj);

echo "<pre>";
print_r($arr);
echo "</pre>";

And the output:
Code:
Array
(
    [0] => AnotherController
    [1] => index
    [2] => anotherfunction
    [3] => Controller
    [4] => _ci_initialize
    [5] => _ci_scaffolding
    [6] => CI_Base
    [7] => get_instance
)
[/quote]

if anothercontroller includes libraries and helpers then this way is wrong

here is what i tried to do:
http://ellislab.com/forums/viewthread/66100/
#4

[eluser]Chris Newton[/eluser]
(if you're interested) According to the MVC design pattern, a controller shouldn't call another controller.Why? Because each controller should essentially be an intermediary between the view and the data (model). If you're calling the controller to make it *do* something then it should just be a part of the first controller, or if you're calling it for data, you should be targeting the model.

Form doesn't really matter until you plan to extend, modify or reuse parts of your code, in which case you'll have to remember to pull in both of your controllers.
#5

[eluser]Keph[/eluser]
You could do a function that'd redirect the user to a relevant controller, and within it have a function that'd list all available methods by, I thing, get_class_methods($this). That could be more MVC compliant Wink
#6

[eluser]EugeneS[/eluser]
[quote author="mahuti" date="1196465175"](if you're interested) According to the MVC design pattern, a controller shouldn't call another controller.Why? Because each controller should essentially be an intermediary between the view and the data (model). If you're calling the controller to make it *do* something then it should just be a part of the first controller, or if you're calling it for data, you should be targeting the model.

Form doesn't really matter until you plan to extend, modify or reuse parts of your code, in which case you'll have to remember to pull in both of your controllers.[/quote]

you think i dont know this ?

as i said before i need to call another controller to receive his methods ... the other way is parsing php files - what is stupidity.

frankly speaking in my other thread i asked to not teach me MVC pattern, i know it very well BUT in my particular case i NEED to call controller from another one (if you read my initial request at all).
#7

[eluser]EugeneS[/eluser]
[quote author="Keph" date="1196469591"]You could do a function that'd redirect the user to a relevant controller, and within it have a function that'd list all available methods by, I thing, get_class_methods($this). That could be more MVC compliant Wink[/quote]


not a way Sad i have for example 20 controllers and i need to receive all their methods at once
#8

[eluser]wiredesignz[/eluser]
If you NEED to call one controller from another without inheritance then (IMO) you build badly.

If there is other good reason to NEED this please explain the situation.
#9

[eluser]Keph[/eluser]
[quote author="EugeneS" date="1196530222"]not a way Sad i have for example 20 controllers and i need to receive all their methods at once[/quote]

Well, my only other guess, if you want to do this dynamically via a controller would be to include() relevant controllers, but if there's so many of them, that'd be madness, And not the Sparta kind.

What about building the list of functions statically through some docmaker?
#10

[eluser]EugeneS[/eluser]
[quote author="Keph" date="1196532407"][quote author="EugeneS" date="1196530222"]not a way Sad i have for example 20 controllers and i need to receive all their methods at once[/quote]

Well, my only other guess, if you want to do this dynamically via a controller would be to include() relevant controllers, but if there's so many of them, that'd be madness, And not the Sparta kind.

What about building the list of functions statically through some docmaker?[/quote]

because all the time i have to remember to add new method in the list.

ok i see the only way is parse php files and receive list of methods Sad




Theme © iAndrew 2016 - Forum software by © MyBB