Get the name of the function ?? |
[eluser]chefnelone[/eluser]
Hello It might sound extrange but I need to dinamically grab the function name in a controller. Something like: Code: function hello(){
[eluser]falkencreative[/eluser]
Technically, I'm not sure if that is possible... However, if that function name is part of the URL (yoursite.com/controller/function/variables), you could grab that using the URI class's segment() function: http://ellislab.com/codeigniter/user-gui...s/uri.html Will that work? Otherwise, one other option is to pass in the name of the function as an argument: function hello($function_name) {} and to call the function: function("hello");
[eluser]WanWizard[/eluser]
Try: Code: // get the backtrace
[eluser]falkencreative[/eluser]
Hmm, didn't know about that function. In that case, this works for me: Code: <?php
[eluser]danmontgomery[/eluser]
debug_backtrace() is a lot of overhead for a function name... http://php.net/manual/en/language.consta...efined.php Quote:__FUNCTION__ The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
[eluser]WanWizard[/eluser]
Yup, very good point. I only use it in my error handlers. to figure out where the error occured. Especially with database errors, I know it was caused by line something in a database library, it's more interesting to know what code called the database library. In that case, the error is terminal, so I'm not to worried about the overhead at that point...
[eluser]flaky[/eluser]
[quote author="chefnelone" date="1275683603"]Hello It might sound extrange but I need to dinamically grab the function name in a controller. Something like: Code: function hello(){ Code: $this->router->fetch_method(); |
Welcome Guest, Not a member yet? Register Sign In |