ricky spires Posted January 5, 2014 Share Posted January 5, 2014 (edited) Hello. I was doing a tutorial on how to build a layout manager for codeigniter and i have run in to a little trouble. In the welcome.php controller i have added $this->layouts->add_include('js/simple_js.js'); then in my default layout view i have added some code in the header to call the js file <head> <?php echo $this->layouts->print_includes(); ?> </head> then in the model i have this // Include js or css for specific pages private $includes = array(); // get the included js from the welcome controller public function add_include($path, $prepend_base_url = TRUE) { if ($prepend_base_url) { $this->CI->load->helper('url'); // Load this just to be sure $this->file_includes[] = base_url() . $path; } else { $this->file_includes[] = $path; } return $this; // This allows chain-methods } // load the array public function print_includes() { // Initialize a string that will hold all includes $final_includes = ''; foreach ($this->includes as $include) { // Check if it's a JS or a CSS file if (preg_match('/js$/', $include)) { // It's a JS file $final_includes .= '<script type="text/javascript" src="' . $include . '"></script>'; } elseif (preg_match('/css$/', $include)) { // It's a CSS file $final_includes .= '<link href="' . $include . '" rel="stylesheet" type="text/css" />'; } } return $final_includes; } if i add an echo inside the add_include() function i get the correct url to the file - http://my-site.com/js/simple_js.js if i do the below inside the print_includes() function i get an empty array. echo '<pre>'; print_r($this->includes); echo '<pre/>'; Array() so ... im guessing this is not getting the info from the add_include() function ??? why is the array empty ??? private $includes = array(); thanks Ricky Edited January 5, 2014 by ricky spires Quote Link to comment https://forums.phpfreaks.com/topic/285120-codeigniter-layout-manager-function-not-loading-array/ Share on other sites More sharing options...
sKunKbad Posted January 6, 2014 Share Posted January 6, 2014 Your add includes method is adding to file_includes, but it should be includes! because that's the name of your class member. Quote Link to comment https://forums.phpfreaks.com/topic/285120-codeigniter-layout-manager-function-not-loading-array/#findComment-1464003 Share on other sites More sharing options...
ricky spires Posted January 6, 2014 Author Share Posted January 6, 2014 perfect thanks Quote Link to comment https://forums.phpfreaks.com/topic/285120-codeigniter-layout-manager-function-not-loading-array/#findComment-1464056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.