A Little Trick for Dealing with Lots of View Files
2011-07-12
WARNING: This article features ANCIENT code! I'm keeping it online because it's interesting to see what I was thinking 10+ years ago. But you DEFINITELY should not be using this code. Anything you're reading about on this page has changed significantly since this was written.
I've been messing around with the Kohana Framework a lot lately. The simplicity of using the View Factory has led me to have a ton of little view snippets and it gets tricky remembering where they all live. So I started adding this line to the top of all my views:
<?php if(Kohana::$environment !== 'production'): echo('<!-- '.__FILE__.' -->'); endif; ?>
When there's a problem, I can hit "view-source" and instantly locate the offending file. Not exactly some brilliant revolution, but it does come in handy.
Three more thoughts:
- A better solution is probably to subclass View and do this automatically, instead of appending the beginning of every file
- Doing this in production code could leave hints to attackers about the layout of your webserver. The environment check should mitigate that, but still be careful.
- The HTML comment may cause a problem if you're using it for AJAX to generate HTML on the fly - I need to look into that further