Welcome Guest, Not a member yet? Register   Sign In
View Object PHP5
#1

[eluser]wiredesignz[/eluser]
Code is moved to wiki: http:///wiki/View_Object_PHP5/

Thanks for your interest.
#2

[eluser]wiredesignz[/eluser]
This is a totally object oriented View library.

You can add a master template from which you can load View Objects as partials or you can use the View Object to render partials only. (ie: header, menu, content, sidebar, footer)

Load the View library from application/libraries.
Code:
$this->load->library('view');

Add a master layout (template) file
Code:
$this->view->layout = 'master_layout_file';    // or leave this empty to render partials only

Add data to the master template view
Code:
$this->view->set($site->data);

Add a partial file and (optional) $data
Code:
$header = $this->view->load('header', 'header_file', $data);

Partials are View objects too, so you can add partials to partials
Code:
$header->load('sub_header', 'sub_header_file', $data);

Add data to any partial
Code:
$header->set($data);

Render your View
Code:
$this->view->render();

// using __toString()

echo $this->view

Inside your master template
Code:
<?php echo $header; ?>
#3

[eluser]wiredesignz[/eluser]
The View Object can use other objects (including modules) to render a partial. Simply add a render() method to your object and load it like any partial.
Code:
$this->view->load('login', $this->object);

When the View Object is called to render it will in turn call your Object->render() method.
Code:
$login->render(); // = $this->object->render();

//using __toString()

<?php echo $login; ?>
#4

[eluser]wiredesignz[/eluser]
Content parts can be added to as you go, simply create a partial, and use the returned object to add as many sub-partials as are needed.
Code:
$content = $this->view->load('content');

foreach ($sub_contents as $part)
{
    $content->load($part->id, $part->partial, $part->data);
}
#5

[eluser]Adam Balachowski[/eluser]
This seems to be perfect. Thanks a lot Aswathy for your time and the solution. Regards Adam

$this->view->set('Thanks');
#6

[eluser]wiredesignz[/eluser]
Thanks Adam.

View Objects can also be created independently, they can have their own partials and then they can be added to the master view.
Code:
$content = new View();

$content->load('part1','partial_file',$article_1);
$content->load('part2','partial_file',$article_2);
$content->load('part3','partial_file',$article_3);

$this->view->load('content', $content);
#7

[eluser]Sam Dark[/eluser]
Seems like we are thinking the same way Smile
http://code-igniter.ru/forum/topic80.html
#8

[eluser]wiredesignz[/eluser]
That's cool Sam Wink

I hope you try out the new View Object too.
#9

[eluser]Sam Dark[/eluser]
Sure Wink
#10

[eluser]nmweb[/eluser]
wiredesignz: Why don't you map __set() to $this->view->set($site->data); You're using php5 anyway and it makes for a nice syntax. Also, __get() can be used for retrieval.

Code:
$this->view->articles=$articles;
$this->view->users=$users;




Theme © iAndrew 2016 - Forum software by © MyBB