View Object PHP5 |
[eluser]wiredesignz[/eluser]
Code is moved to wiki: http:///wiki/View_Object_PHP5/ Thanks for your interest.
[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(); Inside your master template Code: <?php echo $header; ?>
[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();
[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');
[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');
[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();
[eluser]Sam Dark[/eluser]
Seems like we are thinking the same way http://code-igniter.ru/forum/topic80.html
[eluser]wiredesignz[/eluser]
That's cool Sam I hope you try out the new View Object too.
[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; |
Welcome Guest, Not a member yet? Register Sign In |