Welcome Guest, Not a member yet? Register   Sign In
Detailed Explanation of a Controller & Model?
#8

(09-09-2015, 10:59 AM)Josh1985 Wrote: In the previous post you will see all the pieces of code that make up my home page. My question is this, if I have 4 pieces of different content views to insert into the template on different pages (home page->content_home, applications page->content_applications, faq page->content_faq, howto page->content_howto).... How does 'content_View' know which piece of content I am calling for on a certain page?

You would change which view you load into $data['contentView'] in the controller. How you do this depends on how you determine which view needs to be loaded. For example, if you have a different method in the controller for each view, you would probably just hard-code it or set it based on the name of the method. On the other hand, if you have a single method which loads multiple possible views, you would probably use a method argument or some other input to determine which view is used.

(09-09-2015, 10:59 AM)Josh1985 Wrote: As well as the content inside the <title></title> would change. Any thoughts there?

You would just set another variable inside the title element:
PHP Code:
<head>
<
title><?php echo $pageTitle?></title>
</head> 

Then, in the controller, you set that variable in the $data passed to your template view:
PHP Code:
// Change this to the name of whatever view needs to be loaded
$contentView 'contentView';

// Set any variables needed by the contentView
$contentData = array();

// Set any variables needed by the template, including the page title for the current page
$data = array('pageTitle' => 'XAMPP Dashboard');

// Load the contentView to be placed into the template view
$data['contentView'] = $this->load->view($contentView$contentDatatrue);

// Load the template.
$this->load->view('template'$data); 
Reply


Messages In This Thread
RE: Detailed Explanation of a Controller & Model? - by mwhitney - 09-09-2015, 12:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB