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

[eluser]razerone[/eluser]
[quote author="Tpojka" date="1390152364"]You can try something such as CI native using of third parameter set to true in
$this->load->view('template', $arr, true);
function of your controller method.
Check documentation (last line).
Also, you can define it in APPPATH . '/core/' . MY_Controller.php.
After that you can use it in any controller that is extending MY_Controller:
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class MY_Controller extends CI_Controller
{

  public $header = '$this->load->view(\'theme/default/template/common/header.tpl\')';
  public $column_left = '$this->load->view(\'theme/default/template/common/column_left.tpl\')';

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

}

Now in your controller you can use variables $this->header and $this->column_left.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// extending MY_Controller instead native one is important
class Home extends MY_Controller
{

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

  public function index()
  {
    $this->children = array(
      $this->header,
      $this->column_left
    );

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

}
You have to define value of what you want to be output, somewhere.
You gave answer to yourself already: if you want to get some data(output, view, what else) typing header, you have to define somewhere in code what header should return.
PHP nor CI don't read minds (yet Tongue ).

edit: I fixed quote signs in MY_Controller.php code[/quote]

tried that way did not work. Only echoed out errors.


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