Welcome Guest, Not a member yet? Register   Sign In
Best way to pass function from MY_Controller to Controller
#6

(01-27-2016, 10:41 PM)wolfgang1983 Wrote:
(01-27-2016, 02:25 PM)kilishan Wrote: Since Welcome controller extends MY_Controller, the methods are available as part of the Welcome controller. Just call it like any other method.

In your example, it looks like you want to have the content_top() method overridden by the Welcome controller, so you would simply make a new method with the same name in the Welcome controller. You might look at making the content_top method an abstract method in MY_Controller, if all controllers should have that method.

I have though about this and is this more better if I create a render view in MY_Controller

PHP Code:
<?php

class MY_Controller extends CI_Controller {

 protected 
$data = array();

 public function 
__construct() {
 
parent::__construct();
 
$this->load->model('design/model_layout');
 
$this->load->model('extension/model_module');
 }

 public function 
_render_view($page '') {
 
$this->data['column_left'] = $this->column_left();
 
$this->data['column_right'] = $this->column_right();
 
$this->data['content_top'] = $this->content_top();
 
$this->data['content_bottom'] = $this->content_bottom();

 if (
file_exists(APPPATH 'views/theme/'$this->config->item('theme') .'/template/'$page '.php')) {
 
$this->load->view('theme/'$this->config->item('theme') .'/template/common/header'$this->data);
 
$this->load->view('theme/'$this->config->item('theme') .'/template/' $page$this->data);
 
$this->load->view('theme/'$this->config->item('theme') .'/template/common/footer' $page$this->data);
 } else {
 
$this->load->view('theme/default/template/common/header'$this->data);
 
$this->load->view('theme/default/template/'$page$this->data);
 
$this->load->view('theme/default/template/common/footer'$this->data);
 }
 }



And then

PHP Code:
<?php

class Welcome extends MY_Controller {

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

 public function 
index() {
 
$this->data['title'] = 'Home Page';
 
$this->_render_view('common/home');
 }

hello this is issue what i have been looking for , then i make documentation is here http://www.sidaurukfreddy.com/2016/01/lo...oller.html


but my code is really nasty, need some digging on it ?
anyone make blog for clean code load variable for all controller, thanks
Reply


Messages In This Thread
RE: Best way to pass function from MY_Controller to Controller - by freddy - 01-28-2016, 03:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB