Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
applate [2009/10/08 16:09]
Joel Dare
applate [2009/10/08 16:09] (current)
Joel Dare
Line 1: Line 1:
 +====== Applate ======
  
 +**Note:** //I don't actually use this design myself, but putting it together helped me figure out a good method for [[php:Using PHP as a Template Engine]], specifically in a Model View Controller (MVC) paradigm. My interest in the iPhone and similar mobile platforms lead me to create a simple [[Mobile Web App Template]] that works equally well for mobile and small desktop-like apps.//
 +
 +Applate is a web template that serves as a basic starting point for web applications. It uses HTML, JavaScript, and PHP code to create a basic framework that can be used to build new applications.
 +
 +The finished applications can be used in various ways.  For example, they can be used as stand-alone applications that run in a browser window or as gadget or widgets embedded into other pages.
 +
 +The version published here didn't work real well for me, so I re-worked it quite a bit.  Reversed the order from loading the view and that including the logic to loading the logic and that including the view.  Except for the main view, which loads each of the other PHP files.
 +
 +I'm almost finished writing my first complete application with the new version. ​ Once I've got that done, I'll re-write the example app to use the new design. ​ That should be complete in a few days, so please check back.
 +
 +If you have questions about Applate, feel free to [[Contact Me]].
 +
 +Current Version 0.1
 +
 +[[http://​www.joeldare.com/​files/​applate.zip|Download]]
 +
 +[[http://​www.joeldare.com/​applate/​launch.php|Try Example]]
 +
 +===== Design Overview =====
 +
 +The Applate template is designed with an [[wp>​Model–view–controller|MVC]] pattern in order to separate business logic and GUI view.
 +
 +The following technologies are used to build a web application that starts with the Applate template.
 +
 +  * HTML
 +  * JavaScript
 +  * PHP
 +
 +It also uses the jQuery framework to make JavaScript development easier. ​ You are welcome to remove it, of course.
 +
 +===== Main Application =====
 +
 +Everything starts at the main application page.  This is simply the starting HTML file, typically //​index.html//​.  ​
 +
 +===== Panels =====
 +
 +I call the smaller parts of my overall design //​panels//​. ​ A panel is simply a small part of the overall page, typically an HTML DIV tag with content in it.
 +
 +Like any web page, each panel is broken up into several parts. ​ Those parts include:
 +
 +  * HTML Code (example.html)
 +  * PHP Code (example.php)
 +  * CSS Code (example.css)
 +  * JavaScript Code (example.js)
 +
 +Each of these is kept in a separate file and is included into the main file in the same way you would generally build a web page with linked styles and scripts.
 +
 +Each panel is then loaded into the main application using simple JavaScript AJAX calls. ​ The starting point for each panel is that panels PHP code (example.php).
 +
 +This design makes it easy to test an individual panel before it's integrated into the main application. ​ It also makes individual panels re-usable in multiple places.
 +
 +===== PHP Code =====
 +
 +PHP is used as the templating engine in Applate. ​ In order to keep the //View// and //Business Logic// separate only a few types of PHP code are allowed in the HTML (The View) of panels in an Applate project.
 +
 +  * Single functions
 +  * Alternate format //If// / //Else// / //ElseIf// blocks
 +  * Alternate format //For// loops
 +  * Alternate format //Foreach// loops
 +  * Alternate format //Switch// statements
 +
 +PHP offers an alternative syntax for some of its control structures; namely, //if//, //while//, //for//, //​foreach//,​ and //switch//. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to //endif;//, //​endwhile;//,​ //​endfor;//,​ //​endforeach;//,​ or //​endswitch;//,​ respectively. These alternate formats are the only formats that should be used in the view.
 +
 +I will concede that the alternate PHP syntax is slower (because the interpreter is jumping in and out of PHP tags). ​ But, this generally equates to milliseconds of processing time and makes little difference with today'​s servers in most environments.
 +
 +Finally, I prefer to use shorthand PHP tags in the view.  This is generally acknowledged as a bad idea because there is less server support. ​ But, I believe it improves readability slightly and I would generally avoid a web host where I couldn'​t control such things. ​ This only applies to code inside of HTML files and not to code inside of PHP files, where I use the full tags.
 +
 +==== Foreach Example ====
 +
 +<​code>​
 +<? foreach($users as $user): ?>
 +    <p>
 +        First: <? echo($user['​name'​]);​ ?><​br>​
 +        Last: <? echo($user['​last'​]);​ ?>
 +    </p>
 +<? endforeach; ?>
 +</​code>​
 +
 +==== If / ElseIf / Else Examples ====
 +
 +<​code>​
 +<? if ($a == 5): ?>
 +    <p>A is equal to 5.</​p>​
 +<? endif; ?>
 +</​code>​
 +
 +<​code>​
 +<? if ($a == 5): ?>
 +    <p>A is equal to 5</p>
 +<? elseif ($a == 6): ?>
 +    <p>A is equal to 6.</​p>​
 +<? endif; ?>
 +</​code>​
 +
 +===== Screen Shot =====
 +
 +This is how the finished web application looks when it's opened in a JavaScript pop-up window. You don't need to open it in a pop-up but it looks nice and clean.
 +
 +{{ :​applate_screenshot.jpg }}
 +
 +===== License =====
 +
 +Applate is distributed under a MIT style license with the requirement to distribute the license removed.
 +
 +Copyright (c) 2009 Joel Dare
 +
 +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "​Software"​),​ to deal in the Software without restriction,​ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.
 +
 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,​ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 

comments powered by Disqus
applate.txt · Last modified: 2009/10/08 16:09 by Joel Dare