Welcome Guest, Not a member yet? Register   Sign In
Dynamic page
#13

[eluser]jdfwarrior[/eluser]
This is an example of loading the data in the controller:

Code:
<?php

if ( ! defined('BASEPATH') )
    exit( 'No direct script access allowed' );

/**
* Country Controller
*
* @uses
* @created    4/22/2009
*
**/

class Country extends Controller
{

    /**
     * Default Function
     * - Executed in the case of no function specified
     *
     * @param None
     * @returns None
     *
     **/

    function index()
    {
        //Load Generic Country View
        $places = array('France', 'Switzerland', 'Germany', 'Austria', 'China');
        
        $page_data = array(
            'page_title'=>'This is the page title',
            'page_author'=>'I am the page author',
            'list_items'=>$places
        );

        $this->load->view('template', $page_data);
        
        
    }

}

This would be an example of the view file named template.php that is loaded from the controller, and displaying the data that was set in the controller.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;

&lt;head&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /&gt;
    &lt;meta name="author" content="&lt;?=$page_author?&gt;" /&gt;

    &lt;title&gt;&lt;?=$page_title?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<ul>
&lt;? foreach ($list_items as $place): ?&gt;

    <li>&lt;?=$place?&gt;</li>

&lt;? endforeach; ?&gt;
</ul>

&lt;/body&gt;
&lt;/html&gt;

You load data into an array variable in the controller and then pass that variable to the view. Each item is then accessible within the view file.


Messages In This Thread
Dynamic page - by El Forum - 04-21-2009, 07:43 AM
Dynamic page - by El Forum - 04-21-2009, 07:51 AM
Dynamic page - by El Forum - 04-21-2009, 07:59 AM
Dynamic page - by El Forum - 04-21-2009, 08:49 AM
Dynamic page - by El Forum - 04-21-2009, 10:54 AM
Dynamic page - by El Forum - 04-21-2009, 11:48 AM
Dynamic page - by El Forum - 04-21-2009, 11:54 AM
Dynamic page - by El Forum - 04-22-2009, 03:51 AM
Dynamic page - by El Forum - 04-22-2009, 05:44 AM
Dynamic page - by El Forum - 04-22-2009, 07:24 AM
Dynamic page - by El Forum - 04-22-2009, 08:01 AM
Dynamic page - by El Forum - 04-22-2009, 08:44 AM
Dynamic page - by El Forum - 04-22-2009, 08:53 AM
Dynamic page - by El Forum - 04-22-2009, 09:16 AM
Dynamic page - by El Forum - 04-22-2009, 09:22 AM
Dynamic page - by El Forum - 04-22-2009, 09:32 AM
Dynamic page - by El Forum - 04-22-2009, 11:47 AM
Dynamic page - by El Forum - 04-22-2009, 12:00 PM
Dynamic page - by El Forum - 04-22-2009, 12:04 PM
Dynamic page - by El Forum - 04-22-2009, 12:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB