This is example of management books in library, with UI (twitter bootstrap) and API.
ZF2 advanced structure:
- single action per controller (easy to manage, easy to test) complies with SOLID principles
- /api/library/books[/:id]
Filtering:
- special commands:
- $fields (ie: /api/library/books?$fields=id,title,price)
- $sort (ie: /api/library/books?$sort=-year,price) will sort by year [desc] and price [asc]
- $limit (ie: /api/library/books?$limit=5)
- $page (ie: /api/library/books?$page=3)
- criteria commands:
- $between(x, y) (ie: /api/library/books?year=$between(1999,2014))
- $startswith(x) (ie: /api/library/books?publisher=$startswith("o're"))
- $endswith(x) (ie: /api/library/books?title=$endswith(sql))
- $min(x) (ie: /api/library/books?price=$min(37.99))
- $max(x) (ie: /api/library/books?price=$max(40.44))
- in array option:
- ie: /api/library/books?year=2004,2008,2014
- ie: /api/library/books?publisher=O'Reilly Media,Packt Publishing
- equal option:
- ie: /api/library/books?title="Software, Development"
- two options on the same column
- ie: /api/library/books?title[]=$startswith("clean")&title[]=$endswith("ship")
We can also combine all commands:
- ie: /api/library/books?year=$between(2000,2014)&price[]=$min(32)&price[]=$max(40)&$sort=-year&$limit=5&$page=2
We can also do this on books list:
- ie. /library/books?year=$between(2000,2014)&price[]=$min(32)&price[]=$max(40)&$sort=-year&$limit=5&$page=2
With the new structure (Single Action Per Controller) we have also the possibility to restrict access for API by user (ie. CREATE, PUT, DELETE only for admin).
-
if parameter $config['language']['should_redirect_to_recognized_language'] is disabled
- if your default language is "en"
- all URLS in your application for that default language will not have LANG parameter
- "/" will be recognized as language EN
- "/tw" (not available language) will be redirect to "/" automatically
- "/en" will be redirect to "/" automatically
- all URLS in your application for that default language will not have LANG parameter
- for other available languages URLS will have LANG parameter:
- ie. '/de/auth/login', '/pl/auth/login'
- if your default language is "en"
-
if parameter $config['language']['should_redirect_to_recognized_language'] is enabled
- then default language will be your local browser language if it is available
- "/" will be redirected to "en" if your local browser language is "en"
- "/" will be redirected to "pl" if your local browser language is "pl"
- "/tw" (not available) will be redirected to "de" if your local browser language is "de"
- then default language will be your local browser language if it is available
With the new feature, now we have possibility to have default language, ie. "en", and all urls without that LANG parameter, ie.: "/auth/login", "/library/books"
Clone the repository and manually invoke composer
using the shipped
composer.phar
:
cd my/project/dir
git clone --depth=1 git://github.com/harpcio/zf2-demo.git
cd zf2-demo
php composer.phar self-update
php composer.phar install
(The self-update
directive is to ensure you have an up-to-date composer.phar
available.)
To setup apache, setup a virtual host to point to the public/ directory of the project and you should be ready to go! It should look something like below:
<VirtualHost *:80>
ServerName local.zf2-demo
DocumentRoot /path/to/zf2-demo/public
SetEnv APPLICATION_ENV "development" #remove this on production
<Directory /path/to/zf2-demo/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
write the rest of testsimplement logsimplement cache (doctrine: [proxy, metadata, query, result], zf2 [app-config, module-map])implement authorizationimplement acl- implement admin panel
transfer updating/creating/deleting privileges of books to administratorimplement query filtering in API with multiple options and special commandsimplement navigation with acl filteringpagination, sorting, filtering on listsimplement lang && locale support- implement hexagonal structure (Business Logic, Data Access, Application as Framework)
- implement one page application (based on AngularJS)