CodeIgniter Forums
file_exists and DRY principle - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: file_exists and DRY principle (/showthread.php?tid=73411)



file_exists and DRY principle - tomtom - 04-21-2019

Hi,

i was reading the documentation here https://www.codeigniter.com/user_guide/tutorial/static_pages.html
to the section "Adding logic to the controller". I think repeating ! file_exists(APPPATH.'views/pages/'.$page.'.php')) in each view does violate the DRY principle ? Confused


RE: file_exists and DRY principle - dave friend - 04-21-2019

The function view($page = 'home') is a single method used to display any number of pages. Violating DRY would be to have a separate method for each possible "page" that repeats the same lines of code in each one.