Welcome Guest, Not a member yet? Register   Sign In
static page -> dynamic page in 5 minutes
#2

[eluser]jjDeveloper[/eluser]
Not too sure why you are declaring your data object as an integer then a string but as it states in the CI documentation when you load the view whatever "array" you pass to the load call will iterate and you will have variables named by their key value.

So to get data out of the database and make this template dynamic you would set the $data['content']['html'] object to the HTML you receive from your db query.

if you notice you would be able to have multiple html snippets added to this array as it iterates through them and echo's out each element.

I didn't try this example so sorry if its bugged but it should give you a better idea how to proceed.

controllers/pages.php

Code:
<?php
class Pages extends CI_Controller {
  public function __construct() {
    parent::__construct();
    $dbContentResult = array();
    $dbContentResult[] = '<h1>Testing This Template</h1>';
    $dbContentResult[] = '<p>Here goes a paragraph</p>';
    $data['content']['html'] = $dbContentResult;
  }

  public function Index() {
    $this->load->view('template, $data);
  }
}

views/template.php

Code:
&lt;?php
$this->load->view('template/header');
$this->load->view('template/content', $content);
$this->load->view('templates/footer');

template/content.php

Code:
&lt;?php
if(isset($html)) {
    foreach ($html as $htmlData) {
        echo $htmlData;
    }
}


Messages In This Thread
static page -> dynamic page in 5 minutes - by El Forum - 01-23-2012, 08:20 AM
static page -> dynamic page in 5 minutes - by El Forum - 01-24-2012, 11:21 PM
static page -> dynamic page in 5 minutes - by El Forum - 01-26-2012, 08:35 AM
static page -> dynamic page in 5 minutes - by El Forum - 01-29-2012, 03:01 PM
static page -> dynamic page in 5 minutes - by El Forum - 01-29-2012, 03:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB