CODEIGNITER PARSER TABLEFIELD AND DATA!

In this example you have database of users table with email and username field and you will use those database table field as a variable in your template.

TEMPLATE VIEW (test_v3.php)

<html>

<head>

<title>{blog_title}</title>
</head>
<body>

<h3>{blog_heading}</h3>

{blog_entries}
<h5>{username}</h5>
<p>{email}</p>
{/blog_entries}
</body>
</html>

CONTROLLER (test.php)

<?php
class Test extends CI_Controller {

function index(){

$this->load->library(‘parser’);
$this->load->model(‘test_m’);
$UserItems = $this->test_m->get_all_user();

$data = array(
‘blog_title’ => ‘My Blog Title’,
‘blog_heading’ => ‘My Blog Heading’,
‘blog_entries’ => $UserItems
);

$this->parser->parse(‘test_v3’, $data);

}

}//

 

MODEL (test_m.php)

<?php

class Test_m extends CI_Model {

function get_all_user() {
$query = $this->db->query(“SELECT username, email FROM users”);
$result = $query->result_array();
return $result;
}

}

Read more..Template Parser Class

Advertisements
This entry was posted in CODE IGNITER. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s