I wanted to ask if there is any way i can get path of my view file in controller. For example
class welcome extends controller{
function __construct(){
parent::__construct();
}
function index(){
$this->load->view('welcome_message');
}
function test(){
$my_variable = $this->load->view('welcome_message','',TRUE);
}
function another_test(){
/// $path_to_view = ???;
/// echo $path_to_view;
}
}
i want to ask if there is any helper function to get this. The test method has variable containing the html contents in it. But i want to get path of view file???
I'm not sure if this is a proper way but you can try this, just create a helper file i.e. my_helper.php
in your application/helper
folder and paste following function in this helper file
function get_view_path($view_name)
{
$target_file=APPPATH.'views/'.$view_name.'.php';
if(file_exists($target_file)) return $target_file;
}
To use it you have to load the helper file first and then call the function with the name of the view as the function's argument
$this->load->helper('my_helper');
$path_to_view = get_view_path('welcome'); // Will return the path if welcome.php exists in the view folder.
You can auto load it using config.php's $autoload['helper'] = array('functions_helper');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With