I am currently developing a custom CMS being built on top of Codeigniter and was wondering if you can spot any flaws in my page fetching model code. The page fetching model is not entirely complete but the main functionality for retrieving a page is done, as well as retrieving modules assigned to a page (a module is really just a widget).
Can this model be better in some parts, perhaps in relation to the joins I am doing? although not really joins, but multiple queries to pull out bits of related info the pages like modules and media.
<?php
class Mpages extends CI_Model {
public function __construct()
{
parent::__construct();
}
public function fetch_page($page_slug = 'home')
{
$db = $this->db;
$query =
$db
->where('page_status', 1)
->where('page_slug', strtolower($page_slug))
->get('pages')
->result_array();
$page_id = $query[0]['id'];
$query['modules'] =
$db
->select('modules.module_name, modules.module_slug, modules.id moduleid')
->where('page_id', $page_id)
->join('pages_modules lpm', 'moduleid = lpm.module_id')
->order_by('module_order', 'asc')
->get('modules')
->result_array();
/*$query['media'] =
$db
->select('lucifer_media.media_file_name, lucifer_media.media_file_extension, lucifer_media.media_directory')
->join('lucifer_pages_media', 'lucifer_pages_media.page_id = '.$page_id.'')
->get('lucifer_media')
->result_array();*/
if ($query) {
return $query;
} else {
return false;
}
}
public function fetch_navigation()
{
$result = $this->db->order_by("nav_order", "asc")->where('published', 1)->get('navigation')->result_array();
return $result;
}
public function fetch_layout($id)
{
$result = $this->db->where('id', $id)->get('layouts')->result_array();
return $result[0];
}
}
?>