how to get list of the controller methods |
[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 please do not suggest class parsing with preg_match any ways to do this with the CI ?
[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"); And the output: Code: Array
[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"); And the output: Code: Array if anothercontroller includes libraries and helpers then this way is wrong here is what i tried to do: http://ellislab.com/forums/viewthread/66100/
[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.
[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
[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).
[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 [/quote] not a way i have for example 20 controllers and i need to receive all their methods at once
[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.
[eluser]Keph[/eluser]
[quote author="EugeneS" date="1196530222"]not a way 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?
[eluser]EugeneS[/eluser]
[quote author="Keph" date="1196532407"][quote author="EugeneS" date="1196530222"]not a way 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 |
Welcome Guest, Not a member yet? Register Sign In |