1

First just look at my code than i will explain my problem.

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

class Category extends CI_Controller {

function Category()
{
    parent::__construct();
    $this->load->model('category_model');
}
public function index()
{


}

public function _left()
{
    echo "side";
    $data['all_categories'] = $this->category_model->getallcategory();

    $this->load->view('include/left', $data);
}
}

this is my category controller, i have a left() function in which i listed all category in the left bar of my website.

I just want to know that how can i show left() function data in another php file ?

vascowhite
  • 18,120
  • 9
  • 61
  • 77

4 Answers4

3

You really shouldn't have a function you would call repeatedly or from another file in a controller... typically you would want to put them in a Helper library or as a Plugin...

For the function you have created, I am wondering if you know that you can have a view, that calls other views. For example, you have a template view that would load the header view, the view referenced in $data from your controller, and your left view, etc...

I would read more about MVC and how it's setup and how you lay out your files a bit more as it will save you a huge headache and some messy code.

Best of luck!

Ryan Kempt
  • 4,200
  • 6
  • 30
  • 41
0

DISCLAIMER: THIS IS A RANT

I know everyone is trying to be "helpful" but please, please, please stop using "helper" classes and "helper" files. Models get there own data, they persist their own data, in short, they do the helping!!

Ex:

DO NOT create a file called "userhelper.php", just put the methods in a file called "user.php". This is called a model. You might say at this point, "What if I need to share the model with another part of my project or just somewhere else but make it look different or something or whatever??" That's where you would use a viewmodel. The viewmodel has no persistence information in it, in fact it should be significantly different from the model enough to justify its own existence.

To wrap up, just put the CRUD into the model itself. Don't build "managers" or "helpers' or whatever the hell you want to call them.

And I don't care if CodeIgniter encourages this with it's "helper" framework. It's still WRONG and is not OOP. You will end up writing messy code and duplicating effort all over the place.

Joseph Hamilton
  • 435
  • 2
  • 7
0

you call create one function and call many view from this. or create one main view and other top,left ,right,center view and load from main view

rash111
  • 1,307
  • 4
  • 19
  • 35
0

I would consider writing a helper and autoloading it in your config file

For more information about creating helpers go here CodeIgniter: Create new helper? or check CodeIgniter's user guide.

Community
  • 1
  • 1
Miso
  • 49
  • 6