Welcome Guest, Not a member yet? Register   Sign In
PHXView View Engine...

I just started playing with CI today and spent a bit of time writing a view engine to benefit a project I'm working on. It is very alpha-ish code, but I thought I would post it up and see what people thought of it.

The premise of this was to allow myself to have an overall layout view and to encapsulate portions of the pages in to components. I have written a short wiki article with some very very basic examples. I will try to write some more complicated examples in the near future.

Please let me know what you think of this implementation and if I am breaking any design rules with it. This is free for anyone to use in any form. If you modify it to make it better please contact me so I can incorporate the changes.

I made a templating library myself so i'm interested in other views on how to build it.

First i couldn't understand why you used $this->load in your controller code to use a method of your library but then i understood your methods call a view file. I obscure my page part view files, and in the latest version controllers, by referencing to them using the variable name of the base view file. But i can see were your way is easier to spot errors.

In the application/layouts/ directory come all the classes to get generated data into the view files, or am i wrong? If i'm right i'm wondering how you are going to get data from different controller methods?

Have you tested the library with views in subdirectories?

Well it appears that you can call $this->load->phxview or $this->phxview. I missed that piece in the user guide and was following the code of someone else that was loading the library. I guess I'm not sure which way is the "right way" other than what the docs say, so I have changed my controller code in the examples to use $this->phxview. Thanks for catching that inconsistency.

The application/layouts directory is where any layout classes exist. Creating a class here will allow you to seperate your programming so that only programming relevant to your particular action happen in your controller, while programming relevant to your layout happen in the layout class. The data from the controller methods is passed in to the render method just the same as you would pass it in to the load->view method of the base view engine. Once in the layout method if there is an external class the Render method of that class is called and passed the compiled data_array and reference to the view engine.

$this->phxview->RenderLayout('layout name', $data_array);

As for views in subdirectories, those should work fine using the RenderView method. This is because the RenderView method is little more than a wrapper of $this->load->view('view name', $data, true);. All it does is set the rendered view to a property on the class for later display. While layouts and components will definitely not work with subdirectories, but I could look @ adding that in the future. Should be easy enough.

Theme © iAndrew 2016 - Forum software by © MyBB