Guest User

Untitled

a guest
Jun 22nd, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <?php
  2. // Controller
  3. /////////////
  4.  
  5. function index()
  6. {
  7. // Don't use Nested Views. They complicate debugging. You wont know which view the trouble is
  8.  
  9. //Title info. If you load header_view in the view for this controller. Its get this data too.
  10. //Just echo the variable $title between the title tags. i.e. <title><?php echo $title; ?>
  11. $data['title'] = 'All Joboffers';
  12.  
  13.  
  14.  
  15. $data['heading'] = 'Our Job Offers';
  16.  
  17. $this->load->model('job_model'); //load model. its better to do it in the constructor.
  18. $this->load->library('table'); //load the table library
  19.  
  20. $jobs = $this->job_model->getJobs(); //get the jobs through the model.
  21. $fieldnames = array();
  22. foreach ($jobs as $val) {
  23. foreach ($val as $key => $value) {
  24. $fieldnames[] = $key;
  25. }
  26. }
  27. $this->table->set_heading(array_unique($fieldnames)); //set table heading useing fieldnames.
  28. $data['table'] = $this->table->generate($jobs);
  29.  
  30. # Content Information
  31. $content_data = array(
  32. 'heading' => 'Our Job Offers',
  33. #'display_jobs' => $this->jobs_model->getJobs()
  34. $query = $this->jobs_model->getJobs()
  35.  
  36. );
  37.  
  38.  
  39. $this->load->view('jobs/index_view', $data);
  40.  
  41.  
  42. }
  43. ?>
  44. // Model
  45. ////////
  46. <?php
  47.  
  48. function getJobs ()
  49. {
  50. $this->db->select('*'); //you missed this. you can specify individual tables in the string parameter
  51. $this->db->join('user_profile', 'jobs.author_id = user_profile.user_id');
  52.  
  53. $this->db->limit(4);
  54. $this->db->order_by('jobs.id','DESC');
  55. $this->db->where('status','1');
  56.  
  57. $query = $this->db->get('jobs');
  58. return $query->result_array();
  59. }
  60.  
  61. // if you use php5, u can can do this, just change the function name. read active record in userguide.
  62.  
  63. function getJobsPHP5 ()
  64. {
  65. $query = $this->db->select('*')->join('user_profile', 'jobs.author_id = user_profil.user_id')
  66. ->order_by('jobs.id', 'DESC')->get_where('jobs', array('status' => 1), 4, DESC);
  67.  
  68. return $query->result_array();
  69. }
  70. ?>
  71. // View
  72. /////// This should be jobs/index_view.php
  73.  
  74. <?php $this->load->view('mainpage/header_view'); /* set $title inside title tags in header */ ?>
  75. <body>
  76. <h1><?php echo $heading; ?></h1>
  77. <div id="table"><?php echo $table; ?></div>
  78. </body>
  79. <?php $this->load->view('mainpage/footer_view'); ?>
Add Comment
Please, Sign In to add comment