Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Controller
- /////////////
- function index()
- {
- // Don't use Nested Views. They complicate debugging. You wont know which view the trouble is
- //Title info. If you load header_view in the view for this controller. Its get this data too.
- //Just echo the variable $title between the title tags. i.e. <title><?php echo $title; ?>
- $data['title'] = 'All Joboffers';
- $data['heading'] = 'Our Job Offers';
- $this->load->model('job_model'); //load model. its better to do it in the constructor.
- $this->load->library('table'); //load the table library
- $jobs = $this->job_model->getJobs(); //get the jobs through the model.
- $fieldnames = array();
- foreach ($jobs as $val) {
- foreach ($val as $key => $value) {
- $fieldnames[] = $key;
- }
- }
- $this->table->set_heading(array_unique($fieldnames)); //set table heading useing fieldnames.
- $data['table'] = $this->table->generate($jobs);
- # Content Information
- $content_data = array(
- 'heading' => 'Our Job Offers',
- #'display_jobs' => $this->jobs_model->getJobs()
- $query = $this->jobs_model->getJobs()
- );
- # Load the View File
- $data['content'] = $this->load->view('jobs/index',$content_data,TRUE);
- # Load Mainpage
- $this->load->view('mainpage_view',$data);
- }
- ?>
- // Model
- ////////
- <?php
- function getJobs ()
- {
- $this->db->select('*'); //you missed this. you can specify individual tables in the string parameter
- $this->db->join('user_profile', 'jobs.author_id = user_profile.user_id');
- $this->db->limit(4);
- $this->db->order_by('jobs.id','DESC');
- $this->db->where('status','1');
- $query = $this->db->get('jobs');
- return $query->result_array();
- }
- // if you use php5, u can can do this, just change the function name. read active record in userguide.
- function getJobsPHP5 ()
- {
- $query = $this->db->select('*')->join('user_profile', 'jobs.author_id = user_profil.user_id')
- ->order_by('jobs.id', 'DESC')->get_where('jobs', array('status' => 1), 4, DESC);
- return $query->result_array();
- }
- ?>
- // View
- ///////
- <?php $this->load->view('mainpage/header_view'); /* set $title inside title tags in header */ ?>
- <body>
- <h1><?php echo $heading; ?></h1>
- <div id="table"><?php echo $table; ?></div>
- </body>
- <?php $this->load->view('mainpage/footer_view'); ?>
Add Comment
Please, Sign In to add comment