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

[eluser]razerone[/eluser]
[quote author="Tpojka" date="1390210647"]What did the error say?[/quote]

It was on views.

I though I would try different way now.

for each of my common views I have made a controller.



Code:
controllers
common/header.php <-- Header View Loaded in there
common/column_left.php <-- Column_left View Loaded in there
common/column_right.php <-- Column_right View Loaded in there
common/content_top.php <-- Content_top View Loaded in there
common/content_bottom.php <-- Content_bottom View Loaded in there
common/footer.php <-- Footer View Loaded in there
common/home.php Default Route

view
common/header.tpl
common/column_left.tpl
common/column_right.tpl
common/content_top.tpl
common/content_bottom.tpl
common/footer.tpl

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

class Home extends CI_Controller {

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

public function index() {
  $this->children = array(
   'header',
   'column_left' ,
   'column_right',
   'content_top',
   'content_bottom',
   'footer'
  );

  $this->load->view('theme/default/template/common/home.tpl' , $this->children);

}
}


common/home.tpl Default Route

This is sample of opencart/ system/engine/controller
Code:
protected function render() {
foreach ($this->children as $child) {
$this->data[basename($child)] = $this->getChild($child);
}
if (file_exists(DIR_TEMPLATE . $this->template)) {
extract($this->data);
ob_start();
require(DIR_TEMPLATE . $this->template);
$this->output = ob_get_contents();
ob_end_clean();
return $this->output;
} else {
trigger_error('Error: Could not load template ' . DIR_TEMPLATE . $this->template . '!');
exit();    
}
}

Sample Of OpenCart Template Library

Code:
&lt;?php
class Template {
public $data = array();

public function fetch($filename) {
  $file = DIR_TEMPLATE . $filename;
    
  if (file_exists($file)) {
   extract($this->data);
  
        ob_start();
      
     include($file);
      
     $content = ob_get_contents();

        ob_end_clean();

        return $content;
     } else {
   trigger_error('Error: Could not load template ' . $file . '!');
   exit();    
     }
}
}
?&gt;


Messages In This Thread
How to make custom helper work. - by El Forum - 01-19-2014, 07:22 AM
How to make custom helper work. - by El Forum - 01-19-2014, 08:41 AM
How to make custom helper work. - by El Forum - 01-19-2014, 08:53 AM
How to make custom helper work. - by El Forum - 01-19-2014, 10:26 AM
How to make custom helper work. - by El Forum - 01-19-2014, 10:08 PM
How to make custom helper work. - by El Forum - 01-20-2014, 02:37 AM
How to make custom helper work. - by El Forum - 01-20-2014, 02:58 AM
How to make custom helper work. - by El Forum - 01-20-2014, 03:22 AM
How to make custom helper work. - by El Forum - 01-20-2014, 03:38 AM
How to make custom helper work. - by El Forum - 01-20-2014, 03:55 AM
How to make custom helper work. - by El Forum - 01-20-2014, 04:13 AM
How to make custom helper work. - by El Forum - 01-20-2014, 05:44 AM
How to make custom helper work. - by El Forum - 01-20-2014, 06:21 AM
How to make custom helper work. - by El Forum - 01-20-2014, 08:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB