Welcome Guest, Not a member yet? Register   Sign In
Opinions on how far to take MVC
#1

[eluser]jamie young[/eluser]
I have just started using CI and find myself questioning what is the 'right' way to do things, which I think is really deciding how far to take the MVC methodology. This is basically an example of using a custom config of a 'site title' to generate a page title to put on a page. Any feedback you can offer on which method you prefer is appreciated. I am only including the most minimal of code to show these examples.

Example 1
Config
Code:
$config['site_title'] = 'Generic Site Title';

View
Code:
<title><?= $this->config->item('site_title'); ?> - Page</title>


Example 2
Config
Code:
$config['site_title'] = 'Generic Site Title';

Controller
Code:
$data['page_title'] = "{$this->config->item('site_title')} - Page";

View
Code:
<title><?= $page_title; ?></title>


Example 3
Config
Code:
$config['site_title'] = 'Generic Site Title';

Controller
Code:
$data['page_title'] = "{$this->Page_model->getSiteTitle()} - Page";

Model
Code:
function getSiteTitle()
{
    return $this->config->item('site_title')
}

View
Code:
<title><?= $page_title; ?></title>
#2

[eluser]OES[/eluser]
Example 1 is not really the MVC as you are calling a config value in the view.

Example 2 & 3 Will both work.

Now if you are into SEO then you would know that you should have different page titles for each page. So depending on how many pages you will be loading how about adding your pages to a database and calling them from within the controller to load into your view. You can then add meta descriptions, keywords etc.

A very basic example.

Model
Code:
function select_page($path){
  $this->db->where('path', $path);
  $query = $this->db->get('ci_pages');
  return $query->row_array();
}

Controller
Code:
function services(){
  $data['page'] = $this->my_model->select_page($this->uri->segment(1));
}

View
Code:
<title><?= $page.page_title; ?></title>

This is just food for thought for you.

Good Luck




Theme © iAndrew 2016 - Forum software by © MyBB