Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter load controller within a controller HMVC
    primarykey
    data
    text
    <p>I'm using <a href="http://github.com/philsturgeon/codeigniter-template/" rel="nofollow">http://github.com/philsturgeon/codeigniter-template/</a> for the templates and I trying to load other controller view to actual view as a partial. My main problem is that I cant append meta data (javascripts, css) from other controller to the main controller.</p> <p><strong>application/core/MY_Loader.php</strong> <pre><code>class MY_Loader extends CI_Loader { function __construct() { parent::__construct(); } function controller( $sController ) { global $RTR; // Parse the sController string ex: demo/index $aControllerData = explode( '/', $sController ); $sMethod = !empty( $aControllerData[1] ) ? $aControllerData[1] : 'index' ; $sController = !empty( $aControllerData[0] ) ? $aControllerData[0] : $RTR-&gt;default_controller ; $sClass = ucfirst( $sController ); $sPath = APPPATH . 'controllers/'; if ( !file_exists( $sPath . $sController . '.php' ) || class_exists( $sClass, FALSE ) ) { set_status_header( 503 ); exit( 'Unable to locate the specified class: '. ucfirst( $sController ).'.php' ); } $this-&gt;file( $sPath . $sController . '.php' ); $sClass = new $sClass; if ( !method_exists( $sClass, $sMethod ) ) { set_status_header( 503 ); exit( 'There is no Method: ' . $sMethod . ' in Class: '. ucfirst( $sController ).'.php' ); } $aArguments = func_get_args(); return call_user_func_array( array( $sClass, $sMethod ), array_slice( $aArguments, 1)); } } /* End of file MY_Loader.php */ /* Location: ./controllers/MY_Loader.php */ </code></pre> <p><strong>application/controllers/demo.php</strong></p> <pre><code>&lt;?php if ( !defined( 'BASEPATH' ) ) { exit( 'No direct script access allowed' ); } class Demo extends CI_Controller { function index() { $this-&gt;load-&gt;controller('welcome'); $this-&gt;template-&gt;set_partial('footer', 'partials/footer')-&gt;build('demo'); } } /* End of file welcome.php */ /* Location: ./controllers/demo.php */ </code></pre> <p><strong>application/controllers/welcome.php</strong></p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { public function index() { echo 'Loaded welcome controller'; $this-&gt;template-&gt;title('Welcome'); $this-&gt;template-&gt;append_metadata('&lt;script src="/js/jquery.js"&gt;&lt;/script&gt;'); $this-&gt;template-&gt;set_partial('footer', 'partials/footer')-&gt;build('welcome_message'); } } </code></pre> <p>After going to the url localhost/demo i got interface with partials and everything looks good, but I see that there are some libraries loaded too many times in my logs.</p> <pre><code>DEBUG - 2012-10-24 08:02:16 --&gt; Database Driver Class Initialized DEBUG - 2012-10-24 08:02:16 --&gt; User Agent Class Initialized DEBUG - 2012-10-24 08:02:16 --&gt; Template Class Initialized DEBUG - 2012-10-24 08:02:16 --&gt; Controller Class Initialized DEBUG - 2012-10-24 08:02:16 --&gt; File loaded: /home/www/application/controllers/welcome.php DEBUG - 2012-10-24 08:02:16 --&gt; Database Driver Class Initialized DEBUG - 2012-10-24 08:02:16 --&gt; User Agent Class Initialized DEBUG - 2012-10-24 08:02:16 --&gt; Template Class Initialized DEBUG - 2012-10-24 08:02:16 --&gt; Controller Class Initialized DEBUG - 2012-10-24 08:02:16 --&gt; File loaded: /home/www/application/themes/default/views/partials/footer.php DEBUG - 2012-10-24 08:02:16 --&gt; File loaded: /home/www/application/views/welcome_message.php DEBUG - 2012-10-24 08:02:16 --&gt; File loaded: /home/www/application/themes/default/views/layouts/main.php DEBUG - 2012-10-24 08:02:16 --&gt; Helper loaded: inflector_helper DEBUG - 2012-10-24 08:02:16 --&gt; File loaded: /home/www/application/themes/default/views/partials/footer.php DEBUG - 2012-10-24 08:02:16 --&gt; File loaded: /home/www/application/views/demo.php DEBUG - 2012-10-24 08:02:16 --&gt; File loaded: /home/www/application/themes/default/views/layouts/main.php DEBUG - 2012-10-24 08:02:16 --&gt; Final output sent to browser </code></pre> <p>I was trying to use HMVC but there was the same result.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload