Codeigniter - Is it ok to add functionality to the constructor in controllers?

Posted by Irro on Stack Overflow See other posts from Stack Overflow or by Irro
Published on 2010-06-05T08:50:18Z Indexed on 2010/06/05 8:52 UTC
Read the original article Hit count: 211

Filed under:
|

I'm making a project where I want the user to search for shops in different cities and would like the url to be like this: domain/shop/city/name.

So I created a controller in codeigniter called Shop. But I cant create a city function since the city part of the url changes dependent on city name. One easy way to do it would be to add a function called "search" and add the functionality there but then I get url's like: domain/shop/search/city/name which I really would like to avoid.

So my question is if it's ok to add my functionality directly into the constructor to avoid that extra "search" part in the url? I'm afraid that there might be some performance tricks involved that potentially keeps the class in memory so the constructor will not be called every time.

© Stack Overflow or respective owner

Related posts about php

Related posts about codeigniter