Reputation: 43
I make a library that call the method to show some lastest news in the footer.
my library :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Footer
{
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
$this->ci->load->model('m_main');
}
public function news_footer()
{
return $data['news_footer'] = $this->m_main->last_news_footer()->result();
}
}
my controller :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('m_main');
$this->load->helper('text');
$this->load->library('footer');
}
public function index(){
$data['whychooseus'] = $this->m_main->data_whychooseus()->result();
$data['iklan'] = $this->m_main->last_iklan()->result();
$data['iklan2'] = $this->m_main->last2_iklan()->result();
$data['bannerx'] = $this->m_main->data_banner()->result();
$data['news'] = $this->m_main->data_news()->result();
$data['newslast'] = $this->m_main->last_news()->result();
$data['provinsi'] = $this->m_main->data_provinsi()->result();
$data['kota'] = $this->m_main->data_kota()->result();
$data['bengkel'] = $this->m_main->data_bengkel_kota()->result();
$data['harga'] = $this->m_main->data_harga()->result();
$data['plat'] = $this->m_main->data_plat()->result();
$data['news_footer'] = $this->m_main->last_news_footer()->result();
$this->footer->news_footer();
$this->load->view('index',$data);
}
and i got this error :
An uncaught Exception was encountered
Type: Error
Message: Call to undefined method CI_Loader::last_news_footer()
Filename: C:\xampp\htdocs\premi\application\libraries\footer.php
Line Number: 16
Can someone help me?
Upvotes: 0
Views: 46
Reputation:
Try using ci
$this->ci->m_main->last_news_footer()
If your trying to load controllers with in controllers you can use HMVC it good for widgets etc
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads/?tab=branches
Note there is a bug on latest version of HMVC add this https://pastebin.com/vNUhJCss
Upvotes: 3