Welcome Guest, Not a member yet? Register   Sign In
How to make custom helper work.
#11

[eluser]razerone[/eluser]
[quote author="noideawhattotypehere" date="1390215322"]application/core/MY_Loader.php
Code:
class MY_Loader extends CI_Loader {

    public function __construct() {
        parent::__construct();
    }
    
    function array_to_view($views) {
        foreach ($views as $single_view) {
            parent::view('theme/default/template/common/'.$single_view.'.tpl');
        }
    }

}

usage
Code:
$views = array('header', 'column_left', 'footer');
$this->load->array_to_view($views);
[/quote]

I have all ready one that just doesn't let me echo <?php echo $header in view;?>

I am looking in to some link like this now $data['header'] = $this->load->controller('common/header'); for controller
#12

[eluser]InsiteFX[/eluser]
View:
Code:
$this->load->view('header');
$this->load->view('main');
$this->load->view('footer');

Controller:
Code:
// Setup $data array

$this->load->vars($data);    // global to all views
$this->load->view('template');
#13

[eluser]razerone[/eluser]
[quote author="InsiteFX" date="1390221886"]View:
Code:
$this->load->view('header');
$this->load->view('main');
$this->load->view('footer');

Controller:
Code:
// Setup $data array

$this->load->vars($data);    // global to all views
$this->load->view('template');
[/quote]

Here is way I am working on my controller home. Just need a function in a library or my_controller to make this work

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends MY_Controller {

public function __construct(){
            parent::__construct();
             $this->load->helper('array');
       }

       public function index(){
  
  // Need It Setup Like This

  $data['column_left'] = $this->controllers->load('common/column_left');
  $data['column_right'] = $this->controllers->load('common/column_right');
  $data['content_top'] = $this->controllers->load('common/content_top');
  $data['content_bottom'] = $this->controllers->load('common/content_bottom');
  $data['footer'] = $this->controllers->load('common/footer');
  $data['header'] = $this->controllers->load('common/header');

  if ( ! file_exists('template/common/home.tpl')) {
      $this->load->view('template/common/home.tpl', $data);
  } else {
      $this->load->view('default/template/common/home.tpl', $data);
  }      
}
}

home.tpl

<-- Need to be able to echo like below in my home view

Code:
&lt;?php echo $header; ?&gt;&lt;?php echo $column_left; ?&gt;&lt;?php echo $column_right; ?&gt;
<div id="content">&lt;?php echo $content_top; ?&gt;
<h   none;">&lt;?php echo $heading_title; ?&gt;</h1>
&lt;?php echo $content_bottom; ?&gt;</div>
&lt;?php echo $footer; ?&gt;
#14

[eluser]razerone[/eluser]
Thank for all your help to be able to load controller with in controller I had to do a couple of thing with all the information I have revived

I worked it out working will be posting download version on github https://github.com/Carrara-Website-Solutions

First Create I Application Path Core/ MY Loader File
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Loader extends CI_Loader{

public function __construct(){
  parent::__construct();
}

public function controller($file_name){
   $CI = & get_instance();$file_path = APPPATH.'controllers/'.$file_name.'.php';
   $object_name = $file_name;
   $class_name = ucfirst($file_name);if(file_exists($file_path)){
   require $file_path;

   $CI->$object_name = new $class_name();
   }
   else{
   show_error('Unable to load the requested controller class: '.$class_name);
   }
}
}
Second In Your Selected Controller

Controller Test1 Sample

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test1 extends CI_Controller {

public function __construct() {
            parent::__construct();
    
            $this->load->controller('test2');
       }

public function index(){
  $data['header'] = $this->test2->header();
  $this->load->view('default/template/common/home.tpl', $data);
}
}

Controller Test2 Sample

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test2 extends CI_Controller {

public function index(){}

public function header() {
  $this->load->view('default/template/common/header.tpl');
}
}

Now from Test1 you can echo out the controller in the view
View file &lt;?php echo $header; ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB