Codeigniter Check View File Exists

[Solved] Codeigniter Check View File Exists | Php Frameworks Codeigniter - Code Explorer | yomemimo.com
Question : codeigniter check view file exists

Answered by : matteo-puppis

class MY_Loader extends CI_Loader
{ public function view($view, $vars = array(), $return = FALSE) { foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) { $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE; } $file_exists = FALSE; // Set the path to the requested file if (is_string($_ci_path) && $_ci_path !== '') { $_ci_x = explode('/', $_ci_path); $_ci_file = end($_ci_x); } else { $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view; foreach ($this->_ci_view_paths as $_ci_view_file => $cascade) { if (file_exists($_ci_view_file.$_ci_file)) { $_ci_path = $_ci_view_file.$_ci_file; $file_exists = TRUE; break; } if ( ! $cascade) { break; } } } if ( ! $file_exists && ! file_exists($_ci_path)) { throw new Exception('View file '.$view.' doesn\'t exist.'); } return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return)); }
}

Source : https://stackoverflow.com/questions/58955082/how-to-check-if-view-file-exist-in-codeigniter | Last Update : Fri, 12 Jun 20

Answers related to codeigniter check view file exists

Code Explorer Popular Question For Php Frameworks Codeigniter