Welcome Guest, Not a member yet? Register   Sign In
Multi-level views with variables [SOLVED]
#1

[eluser]karlis_i[/eluser]
Hi, I'm new to CodeIgniter and whole MVC thing, and I hope you can help me clarify some things.

I'm working on an application, that has one main view (header, footer, menu, etc), some content views (tables with clients, bills, etc), and some sub-views for content (info about specific client, etc).

HTML is divided this way so that user can load views with Ajax, but I want to make this work with JavaScript turned off too.

I know that it is possible to call a view from another view, but I want also to pass variables for view and sub view from controller.
For now it looks like this-
Controller

Code:
function something()
{
$data['include'] = 'clients'; // for main view to call the right content view
$data['clients'] = $this->model->get_clients(); // gets the client array from DB
$data['client_info'] = $this->model->get_client_info($client_id);

$this->load->view('main', $data);
}

Views/Main.php
Code:
...some html
<?php
$data['clients'] = $clients; // passing variables further..
$data['client_info'] = $client_info;

$this->load->view($include, $data); // calling content view
?>
some more html...

Views/Clients.php
Code:
...some html, using client variables like this: <?=$client->id?>
<?php
if(!empty($client_info)){
$data['client_info'] = $client_info; // passing variables even further
$this->load->view('client_info', $data); // calling sub content view
}
?>
some more html...

Views/Client_info.php is simple, just html and
Code:
<?=$client_info->name?>
etc.

I hope I made it clear.
So, the question is- is it ok to do so, and if not, how should I do it?
Thanks in advance,

k_i


Messages In This Thread
Multi-level views with variables [SOLVED] - by El Forum - 12-08-2009, 07:16 AM
Multi-level views with variables [SOLVED] - by El Forum - 12-08-2009, 12:45 PM
Multi-level views with variables [SOLVED] - by El Forum - 12-08-2009, 09:09 PM
Multi-level views with variables [SOLVED] - by El Forum - 12-09-2009, 06:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB