Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 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. # Load the View File
  38. $data['content'] = $this->load->view('jobs/index',$content_data,TRUE);
  39.  
  40. # Load Mainpage
  41. $this->load->view('mainpage_view',$data);
  42.  
  43.  
  44. }
  45. ?>
  46.  
  47. // Model
  48. ////////
  49. <?php
  50.  
  51. function getJobs ()
  52. {
  53. $this->db->select('*'); //you missed this. you can specify individual tables in the string parameter
  54. $this->db->join('user_profile', 'jobs.author_id = user_profile.user_id');
  55.  
  56. $this->db->limit(4);
  57. $this->db->order_by('jobs.id','DESC');
  58. $this->db->where('status','1');
  59.  
  60. $query = $this->db->get('jobs');
  61. return $query->result_array();
  62. }
  63.  
  64. // if you use php5, u can can do this, just change the function name. read active record in userguide.
  65.  
  66. function getJobsPHP5 ()
  67. {
  68. $query = $this->db->select('*')->join('user_profile', 'jobs.author_id = user_profil.user_id')
  69. ->order_by('jobs.id', 'DESC')->get_where('jobs', array('status' => 1), 4, DESC);
  70.  
  71. return $query->result_array();
  72. }
  73. ?>
  74.  
  75.  
  76. // View
  77. ///////
  78.  
  79. <?php $this->load->view('mainpage/header_view'); /* set $title inside title tags in header */ ?>
  80. <body>
  81. <h1><?php echo $heading; ?></h1>
  82. <div id="table"><?php echo $table; ?></div>
  83. </body>
  84. <?php $this->load->view('mainpage/footer_view'); ?>
Add Comment
Please, Sign In to add comment