Welcome Guest, Not a member yet? Register   Sign In
Checking if a file exists
#1

[eluser]Jacob Krustchinsky[/eluser]
Hello,

Im trying to create a simple template system that works as follows.

Within the views folder there are two sub-directories labeled, themes and templates. The themes houses a header.tpl and footer.tpl as well as the theme specific styles and graphics. The templates houses a default set of view templates in correspondence with their appropriate controllers. When I go to render a template I simply call $this->template->render($template_name, $data); . Now the issues is, I want to check if a file exists in the theme folder with the template_name, if so render that file otherwise render the one in the default set. How can I check if the file_exists in the themes folder from within a library class? I cant use file exists and fopen returns an error. Any help?
#2

[eluser]KingSkippus[/eluser]
Why can't you use file_exists()?

In your controller, you can do this:

Code:
if (file_exists(APPPATH.'views/themes/'.$filename)) {
    $this->load->view('themes/'.$filename);
}
else {
    $this->load->view('themes/default.tpl');
}

Note that there's no $ in front of APPPATH and no slash after it, it is a constant that points to your application directory.




Theme © iAndrew 2016 - Forum software by © MyBB