Phalcon PHP using a more practical example of the Micro application.
There is already a sample application created by the Phalcon team that uses the Micro class, but I found it to be a little more specific than I would like. It uses things like the Volt template engine, models, Database connections, and some other glossed over Bootstrapping.
My example application contains very little. It has enough to get you started creating a simple JSON-based application, or just serving a static site with a few cached views.
Just shows a simple GET route and serves a single view.
Simple
view engine)The templates use partials for the header and footer of the site.
You can pass parameters into the URL, and they will be rendered on the page.
An example of how to return JSON via a POST request. There is also a comment that tells you the jQuery test function to try.
This shows how you can serve a cached view, with an expiry. Good for those complicated pages that need to be refreshed every other day.
This one is really simple. It just shows how you can redirect one URL request to another.
I also included a simple grunt task that uses livereload
. This will refresh the browser when view files, or the app.php
file, changes.
You can find the repositry on Github. I will be updating and tweaking this project as I move along. It may become more feature-rich in the next few months. I would like to build a nice solid base for myself when using the Micro app.
There may be some need to add in some simple search examples, models, forms, validation, or even Database connections. But we will see if that is where it moved organically.
I'm a full-stack developer, co-organizer of PHP Vancouver meetup, and winner of a Canadian Developer 30 under 30 award. I'm a huge Open Source advocate and contributor to a lot of projects in my community. When I am not sitting at a computer, I'm trying to perfect some other skill.