Is this a legit practice for a controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Is this a legit practice for a controller (/showthread.php?tid=6949) |
Is this a legit practice for a controller - El Forum - 03-18-2008 [eluser]uprise78[/eluser] I am curious is there are any pitfalls to using the PHP5 magic __construct and __destruct to throw my header and footer into the view. As far as I can tell, the Output class handles it all correctly but I figure I would check in to be sure. Code: class Test extends Controller { Is this a legit practice for a controller - El Forum - 03-18-2008 [eluser]Tom Glover[/eluser] As far as I know this is correct! Is this a legit practice for a controller - El Forum - 03-18-2008 [eluser]Pygon[/eluser] As a matter of opinion, relying on the PHP shutdown sequence to introduce your footer into the page is a bad idea. Also, again as a matter of opinion, you should really be relying on your view to handle view related material. In practice -- you can do this, however realize that should you redirect a request to a seperate controller, you've now processed __construct twice (two headers) and registered two shutdown functions (__destruct). Personally, I would either: 1) Move Header/Footer to the view structure. 2) Handle them as usual in a procedural fashion once you've determined what will be displayed. You can do it however you wish though. Is this a legit practice for a controller - El Forum - 03-18-2008 [eluser]uprise78[/eluser] Good point Pygon. It's always good to prepare for those just in case scenarios. Header/Footer officially moved out of __construct __destruct. Thanks for the opinion. Is this a legit practice for a controller - El Forum - 03-18-2008 [eluser]Pygon[/eluser] That's good in my opinion. __destruct is unreliable at best in my opinion. All you really know that is *at some point and in no particular order* during the shutdown process, it's *probably* going to be run. |