Welcome Guest, Not a member yet? Register   Sign In
Help with planning a CI project
#3

[eluser]invision[/eluser]
Many thanks for the speedy reply eoinmcg!

Prepare yourself for the response Smile

Just to get me rolling....how does the following look:

Code:
// Page Controller
class Page extends Controller {
  function Page(){
    parent::Controller();
    session_start();
  }

  function index(){
    // say 'home' is the value of the slug in my sql table
    $data['page_data'] = $this->MPages->getPageBySlug('home');
    $data['title'] = "Welcome";
    $data['main'] = 'public_home';
    $this->load->vars($data);
    $this->load->view('template');  
  }
  
  function page($slug){
    $data['page_data'] = $this->MPages->getPageBySlug($slug);
    $data['title'] = $data['page']['title'];
    $data['main'] = 'public_page';
    $this->load->vars($data);
    $this->load->view('template');  
  }



// Vacancies Controller
class Vacancies extends Controller {
  function Vacancies(){
    parent::Controller();
    session_start();
  }

  function index(){
    $data['page_data'] = $this->MVacancies->getVacancies();
    $data['title'] = "Vacancies";
    $data['main'] = 'public_home';
    $this->load->vars($data);
    $this->load->view('template');  
  }
  
  function vacancy($slug){
    $data['page_data'] = $this->MVacancies->getVacancyBySlug($slug);
    $data['title'] = $data['page']['title'];
    $data['main'] = 'public_page';
    $this->load->vars($data);
    $this->load->view('template');  
  }



// News Controller
class Vacancies extends Controller {
  function Vacancies(){
    parent::Controller();
    session_start();
  }

  function index(){
    $data['page_data'] = $this->MNews->getNews();
    $data['title'] = "News";
    $data['main'] = 'public_home';
    $this->load->vars($data);
    $this->load->view('template');  
  }
  
  function news($slug){
    $data['page_data'] = $this->MNews->getNewsBySlug($slug);
    $data['title'] = $data['page']['title'];
    $data['main'] = 'public_page';
    $this->load->vars($data);
    $this->load->view('template');  
  }

Models

Code:
// Pages Model
class MPages extends Model{

function MPages(){
    parent::Model();
}

function getPage($id){
    $data = array();
    $this->db->where('id',$id);
    $this->db->limit(1);
    $Q = $this->db->get('pages');
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
}

function getPageBySlug($slug){
    $data = array();
    $this->db->where('slug',$slug);
    $this->db->limit(1);
    $Q = $this->db->get('pages');
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
}




// Vacancies Model
class MVacancies extends Model{

function MVacancies(){
    parent::Model();
}

function getVacancies(){
     $data = array();
     $Q = $this->db->get('vacancies');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data;
}




// News Model
class MNews extends Model{

function MNews(){
    parent::Model();
}

function getNews(){
     $data = array();
     $Q = $this->db->get('news');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data;
}

Views
Code:
// Vacancies View
if (count($posts)){
    foreach ($posts as $key => $list){
        echo "<h2>".$list['title']."</h2>\n";
        echo auto_typography(word_limiter($list['body'], 200));
        echo anchor('blog/page/'.$list['id'],'read more >>');
    }
    echo "<br/><br/>";
}



// News View
if (count($posts)){
    foreach ($posts as $key => $list){
        echo "<h2>".$list['title']."</h2>\n";
        echo auto_typography(word_limiter($list['body'], 200));
        echo anchor('blog/page/'.$list['id'],'read more >>');
    }
    echo "<br/><br/>";
}



// Page View
echo auto_typography($post['title']);
echo auto_typography($post['body']);

Template View would just be something like:
Code:
<div id="mainContent">
   &lt;?php $this->load->view($main);?&gt;
</div>


Does this look like a good start?

I realise it's a lot to take in at first, but am I heading in the right direction?

I really value any feedback for this. Very new to CodeIgniter but excited for the project.


Thank you.


Messages In This Thread
Help with planning a CI project - by El Forum - 02-26-2010, 11:58 AM
Help with planning a CI project - by El Forum - 02-26-2010, 12:55 PM
Help with planning a CI project - by El Forum - 02-26-2010, 01:21 PM
Help with planning a CI project - by El Forum - 02-26-2010, 01:49 PM
Help with planning a CI project - by El Forum - 02-26-2010, 01:52 PM
Help with planning a CI project - by El Forum - 02-27-2010, 12:22 PM
Help with planning a CI project - by El Forum - 02-28-2010, 02:10 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:12 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:14 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:18 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:30 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:32 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:35 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:35 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:37 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:40 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:43 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:44 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:46 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:48 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:54 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:56 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:56 AM
Help with planning a CI project - by El Forum - 02-28-2010, 02:59 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:03 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:04 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:07 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:08 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:09 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:12 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:15 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:16 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:17 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:19 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:22 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:27 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:27 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:30 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:35 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:41 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:44 AM
Help with planning a CI project - by El Forum - 02-28-2010, 03:49 AM
Help with planning a CI project - by El Forum - 03-02-2010, 05:45 AM
Help with planning a CI project - by El Forum - 05-17-2010, 06:52 AM
Help with planning a CI project - by El Forum - 05-17-2010, 07:56 AM
Help with planning a CI project - by El Forum - 05-17-2010, 07:59 AM
Help with planning a CI project - by El Forum - 05-17-2010, 08:10 AM
Help with planning a CI project - by El Forum - 05-17-2010, 08:24 AM
Help with planning a CI project - by El Forum - 05-17-2010, 08:26 AM
Help with planning a CI project - by El Forum - 05-17-2010, 08:30 AM
Help with planning a CI project - by El Forum - 05-17-2010, 08:32 AM
Help with planning a CI project - by El Forum - 05-17-2010, 08:47 AM
Help with planning a CI project - by El Forum - 05-17-2010, 08:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB