Using Phalcon Models, Views, and Controllers

Exclusive offer: get 50% off this eBook here
Getting Started with Phalcon

Getting Started with Phalcon — Save 50%

Design, implement, and deliver superior web applications using the most popular PHP framework available with this book and ebook

£11.99    £6.00
by Stephan A. Miller | January 2014 | Web Development

In this article, by Stephan A. Miller, the author of Getting Started with Phalcon, gives an introduction to using Phalcon to develop web applications.

(For more resources related to this topic, see here.)

Creating CRUD scaffolding

CRUD stands for create, read, update, and delete, which are the four basic functions our application should do with our blog post records. Phalcon web tools will also help us to get these built. Click on the Scaffold tab on the web tools page and you will see a page as shown in the following screenshot:

Select posts from the Table name list and volt from the Template engine list, and check Force this time, because we are going to force our new files to overwrite the old model and controller files that we just generated. Click on the Generate button and some magic should happen.

Browse to http://localhost/phalconBlog/posts and you will see a page like the following screenshot:

We finally have some functionality we can use. We have no posts, but we can create some. Click on the Create posts link and you will see a page similar to the one we were just at. The form will look nearly the same, but it will have a Create posts heading. Fill out the Title, Body, and Excerpt fields and click on the Save button. The form will post, and you will get a message stating that the post was created successfully.

This will take you back to the post's index page. Now you should be able to search for and find the post you just created. If you forgot what you posted, you can click on Search without entering anything in the fields, and you should see a page like the following screenshot:

This is not a very pretty or user-friendly blog application. But it got us started, and that's all we need. The next time we start a Phalcon project, it should only take a few minutes to go through these steps. Now we will look over our generated code, and as we do, modify it to make it more blog-like.

Summary

In this article, we worked on the model, view, and controller for the posts in our blog. To do this, we used Phalcon web tools to generate our CRUD scaffolding for us. Then, we modified this generated code so it would do what we need it to do. We can now add posts. We also learned about the Volt template engine.

Resources for Article:


Further resources on this subject:


Getting Started with Phalcon Design, implement, and deliver superior web applications using the most popular PHP framework available with this book and ebook
Published: January 2014
eBook Price: £11.99
Book Price: £18.99
See more
Select your format and quantity:

About the Author :


Stephan A. Miller

Stephan A. Miller is a web and app developer, SEO expert, and blogger who lives in Kansas City, Missouri. He was head developer at All About Doors and Windows in Kansas City for six years and was a freelance developer and SEO expert for eight years.

In his career, he has worked with Wordpress, Drupal, Magento, osCommerce, ZenCart, and many other online applications, as well as developing sites from scratch in PHP and MySQL or using the Lithium PHP framework. But this is not all. Because his business was at times a one man show, he knows Linux, Apache, and Nginx well and has developed desktop applications in Python where PHP just won't work. He also knows search engine optimization techniques, web analytics software, and search engine marketing which he uses to promote his own handful of sites. He blogs semi-regularly at http://www.stephanmiller.com about his work.

Books From Packt


Symfony 1.3 Web Application Development
Symfony 1.3 Web Application Development

RESTful PHP Web Services
RESTful PHP Web Services

WordPress Web Application Development
WordPress Web Application Development

Learning FuelPHP for Effective PHP Development
Learning FuelPHP for Effective PHP Development

Real-time Web Application Development using Vert.x 2.0
Real-time Web Application Development using Vert.x 2.0

Instant PhpStorm Starter
Instant PhpStorm Starter

HTML5 iPhone Web Application Development
HTML5 iPhone Web Application Development

Persistence in PHP with Doctrine ORM
Persistence in PHP with Doctrine ORM


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software