codeigniter check view file exists

Solutions on MaxInterview for codeigniter check view file exists by the best coders in the world

showing results for - "codeigniter check view file exists"
Bonquesha
22 Aug 2018
1class MY_Loader extends CI_Loader
2{
3    public function view($view, $vars = array(), $return = FALSE)
4    {
5
6        foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
7        {
8            $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE;
9        }
10
11        $file_exists = FALSE;
12
13        // Set the path to the requested file
14        if (is_string($_ci_path) && $_ci_path !== '')
15        {
16            $_ci_x = explode('/', $_ci_path);
17            $_ci_file = end($_ci_x);
18        }
19        else
20        {
21            $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
22            $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view;
23
24            foreach ($this->_ci_view_paths as $_ci_view_file => $cascade)
25            {
26                if (file_exists($_ci_view_file.$_ci_file))
27                {
28                    $_ci_path = $_ci_view_file.$_ci_file;
29                    $file_exists = TRUE;
30                    break;
31                }
32
33                if ( ! $cascade)
34                {
35                    break;
36                }
37            }
38        }
39
40        if ( ! $file_exists && ! file_exists($_ci_path))
41        {
42            throw new Exception('View file '.$view.' doesn\'t exist.');
43        }
44        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
45    }
46
47}