CodeIgniter Forums

Full Version: Can Any body give me explanation and example for function _remap() and function _output() ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Mario "St.Peter" Valentino[/eluser]
Hi, i'm newbie for codeigniter.
I have some questions about function _remap() and function _output()
can any body expert give me explanation and examples ?
Please give me answer expert.
Thanks
:lol:

El Forum

[eluser]PhilTem[/eluser]
Function _remap() is used when you wan't to - who would have thought - remap function calls. Usually, the method executed is determined by the URI, e.g.
Code:
example.com/user/login

calls method login of controller user. But if you want to make something like e.g. a gallery with urls like

Code:
example.com/gallery/my-awesome-gallery

where my-awesome-gallery will be your gallery name, you would actually have to create a method called my-awesome-gallery within your gallery controller. But if you used the _remap() method, it will be called with my-awesome-gallery as first argument.
So you can grab method execution before they are executed (when a _remap()-method is found by the CI super-object it's called no matter what - even if a my-awesome-gallery-method existed).

It's basically some other usage of routing - since routing can be used for first-level dynamic uris (in the previous examples gallery as well as user are first-level dynamic uris. You just clear your mind about whether you want to use routes or _remap or both Wink

Method _output(): Never seen it, don't know about it Big Grin Sorry for that^^

El Forum

[eluser]toopay[/eluser]
Welcome to CI forum, Mario "St.Peter" Valentino.

To re-route the given url, is one of _remap main job, just like @PhilTem try to describe above. Just to make it more straight forward, _remap is similar with the usage of __call (magic method in PHP). So you could utilize it more, than just doing re-routing. Eg for some REST application, you could have just one controller, to act as a single gateway. You could also use _remap, to distinct whether a controller method is accessible or not, via some request. Or, even to create a Controller Factory, if you have some base controller. You will need this _remap, mostly, if you feel you are sharing several method (for example, you consistenly have to set a same session value, or you consistenly have to load same view file with similar data structure to send) accross your controller(s).

_output, is a method that, if it exists in your controller, then the output class will send the final output to these method. This will handy, if you want to filtering your content, in spesific controller and not applied to all controller(s). Eg, you have a blog, and in Post controller, you want to filter your content, to replace all external links with your own internal links using some regular expression pattern (so you could monitoring your reader condition, like what link attract them to leave your blog, etc). Combined with base controller concept, and _remap, this method could creating a reusable and consistent templating logic, within your application.