-
Ajax30 Member
  
-
Posts: 71
Threads: 46
Joined: Aug 2017
Reputation:
0
I am working on a CMS with [b]CodeIgniter 3.1.8[/b] and Bootstrap 4. I have decided to add themes to it.
The [i]themes[/i] directory is outside [i]application[/i] as can be see in the image below:
[color=var(--blue-700)]![[Image: syL0A.jpg]](https://i.stack.imgur.com/syL0A.jpg)
Inside [i]themes[/i] I have the theme directory (of course) which contains the "master view", layout.php:
[/color] [color=var(--blue-700)]![[Image: gOGzZ.jpg]](https://i.stack.imgur.com/gOGzZ.jpg)
In application/core [/color] I have added a Loader.php file with the following contents:
Code: <?php defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH."../system/core/Loader.php";
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(APPPATH . $folder . '/' => TRUE));
return $this->_ci_load(array(
'_ci_view' => $view,
'_ci_vars' => $this->_ci_prepare_view_vars($vars),
'_ci_return' => $return
));
}
}?>
In my Posts controller's index() method, I load the view passing it the data:
Code: public function index() {
//more code here
$this->load->ext_view('third_party', 'themes/caminar/layout', $data);
}
I get this error message:
Code: Call to undefined method CI_Loader::ext_view()
[b]NOTE:[/b] the application is [b]not HMVC[/b], only MVC.
What am I doing wrong?
-
InsiteFX Super Moderator
     
-
Posts: 6,727
Threads: 344
Joined: Oct 2014
Reputation:
246
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 )
-
Ajax30 Member
  
-
Posts: 71
Threads: 46
Joined: Aug 2017
Reputation:
0
(10-29-2020, 12:47 PM)InsiteFX Wrote: 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.
Thanks!
I solved it. Have a look here if you're curios.
|