Welcome Guest, Not a member yet? Register   Sign In
How do I load a view from outside the default views folder in this application?
#2

This is not tested.

Add this to index.php

PHP Code:
$theme_path 'themes';

if ((
$_temp realpath($theme_path)) !== FALSE)
{
    $theme_path $_temp.DIRECTORY_SEPARATOR;
}
else
{
    // Ensure there's a trailing slash
    $theme_path strtr(
        rtrim($theme_path'/\\'),
            '/\\',
        DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
    
).DIRECTORY_SEPARATOR;
}

// Path to the themes directory
define('THEMEPATH'$theme_path); 

The your code would be something like this.

PHP Code:
<?php

// application/core
class MY_Loader extends CI_Loader
{
    function ext_view($folder$view$vars = array(), $return FALSE)
    {
        $this->_ci_view_paths array_merge($this->_ci_view_paths, array(THEMEPATH $folder '/' => TRUE));
        return $this->_ci_load(array(
            '_ci_view' => $view,
            '_ci_vars' => $this->_ci_object_to_array($vars),
            '_ci_return' => $return
        
));
    }
}

$view_data = array('my_name' => 'dino');

// you may need to create a folder for the layout using this.
$this->load->ext_view('view_folder''my_new_view'$view_data); 

Give that a try.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: How do I load a view from outside the default views folder in this application? - by InsiteFX - 10-29-2020, 12:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB