kristovaher / Wave-Framework

Open Source API-centric PHP Framework
https://github.com/kristovaher/Wave-Framework
GNU Lesser General Public License v3.0
2 stars 0 forks source link

Templating for views #10

Closed hampsterx closed 11 years ago

hampsterx commented 11 years ago

hi there, what would you suggest for templating the views? I do not want to write classical view pages that pull in header and footer. Something along Zend renderer would be nice.

like the framework so far, well the HMVC, API centric approach, not so much the db or view stuff. And not really clear at all on the ajax or javascript/jquery integration yet, docs seem a bit incomplete..

thanks,

TiM

hampsterx commented 11 years ago

"View Controller behavior can be altered in any way you find suitable for your project. View Controller can load multiple View components from other Views and return the output to client browser, or it can render and return part of the HTML frame by itself. Default View Controller in Wave Framework renders the main HTML frame by itself, while loading the body content from a View file."

ahah, maybe you have templating nailed already? (well... layouts,partials)

time for more coffee~

kristovaher commented 11 years ago

Wave Framework itself is technically an API-centric framework that has no Views in itself, but it has a core foundation built within that supports them as well as a URL and View Controllers for that purpose. The Views technically are templates, but ones that have the entire functionality of PHP itself, without requiring a separate 'language'. Reason for this is that PHP itself is technically also a templating language in itself and this does not need to be complicated further.

At the same time you can do anything with your Views that are loaded through the View Controller - or you can change how View Controller itself works.

The good design for Views is to have Views only call various other controllers and make API requests that are only reading data. For example when you wish to generate a list of products, you'd have your View make an 'products-list' API call, or something similar, and then render out the results.

I highly recommend you take a look at both of the tutorials, they cover Views pretty thorougly :)

hampsterx commented 11 years ago

yep I get the API centric approach but you have built controllers to allow regular web pages and partials to be built using view classes so this is what people are going to compare your framework to with the next. Lets see..

PHP Zend - Two Step rendering process. views can inject content into templates, partials, etc

Python Jinja - Filters, macros, blocks, template inheritance, etc

Ruby Liquid - Similar to above


Your example shows html inside a class as well as duplicated blocks (navigation) of content. I know this is just a demo but this is simply not what developers are expecting today. Web Designers are much more comfortable editing template files than actual PHP classes!

At the same time you can do anything with your Views that are loaded through the View Controller - or you can change how View Controller itself works.

Yes I understand that, and I will figure out a solution once I get my head around your concepts a bit better.

The good design for Views is to have Views only call various other controllers and make API requests that are only reading data.

Agreed

I highly recommend you take a look at both of the tutorials, they cover Views pretty thorougly :)

The Web service one is great, the web page one left me underwhelmed :(

Many thanks, I am glimpsing the power of your framework and can see how it could be quite beneficial for my current project but having said that there are certain expectations I have regarding frameworks, One is regarding the view side (mentioned above), the other is database (if the framework includes db rather than using external library which you have done) but will talk about that in another time!~

kristovaher commented 11 years ago

You make some really good points, I'll look into some templating options that might be beneficial. I agree that designers would rather change templates and not PHP Classes. Maybe this could be made optional in some way, I'll certainly look into what you have suggested. You do make some good points.

hampsterx commented 11 years ago

FYI this is what I have chosen for templating and DB

Twig

http://twig.sensiolabs.org https://github.com/justjohn/twig.js/

Templating for both js and PHP side :)

Idiorm

http://j4mie.github.io/idiormandparis/

Clean/Simple DB Layer


Obviously db and templating are two very opinionated parts of a framework so this won't suit other peoples tastes but if you could add support so it's easy to add your own db or template library such as those above that would be great and would also help sway a few more people towards your framework if you had some examples of this in the docs :)

hampsterx commented 11 years ago

one more thing, sorry.. might be stating the obvious, not sure.

A framework should do it's hardest to avoid developers having to extend the core. In this example..

controller.view.php

.. // HTML frame is generated with meta data and resource files ... content follows.. ...

controller.view.php is doing lots of great stuff but should ship off to the template and that template should then be using some built in helpers to output the style/js scripts, content etc.


Similarly

controller.url.php

// USER PERMISSIONS CHECKS // This is the best place to build your authentication module for web views ...

There should be a hook here so the user can plug in authentication without breaking core.


I know these two files are "examples" of how to do the html aspect and the strength of this framework is in the API but the problem is when you release updates, developers are going to have to merge in those changes which could be problematic and they very much should be part of the core to avoid hacking.

kristovaher commented 11 years ago

I agree with what you're saying, but reality is that the controller.view.php and controller.url.php are not technically Core. They are just ways that you can build a website on top of Wave, so these files are freely editable for a project. These classes are built the same way that other classes for a project are intended to be built. And especially the controller.view.php is intended to be edited per project, since it loads other views and sets headers for HTML and more.

But I will think about how to achieve something similar for developers who do not at all want to edit these files and instead want to edit something smaller, without figuring out how it works. This is a good point.

hampsterx commented 11 years ago

Agreed not part of core, I think I realize this now as I learn more. Still, gotta make it easy out of the box, and definitely out of the box/example wise should follow developer expectations so if you could improve here somehow that would be great. Good luck..