Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
FuelPHP Application Development Blueprints
FuelPHP Application Development Blueprints

FuelPHP Application Development Blueprints: Supercharge your projects by designing and implementing web applications with FuelPHP

eBook
$26.09 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

FuelPHP Application Development Blueprints

Chapter 2. Building a To-do List Application

We saw in the last chapter a few basics of the FuelPHP framework, but there is still a lot to learn to be comfortable with it. We will create here our first real-world application to dive a little bit deeper into the main FuelPHP features. We will create a to-do list application, a common training example when introducing frameworks. Again, it won't be a very complicated application, but this project will be used as a basis to introduce essential FuelPHP components.

By the end of this chapter, you should know the following:

  • What is a Entity Relationship (ER) diagram
  • What is an profiler and how to use it
  • How to use the Debug class
  • What is an Object Relational Mapper (ORM) and how to use it in your project
  • How to use the basic operations of Model_Crud and Model_Orm
  • The ORM relations
  • What are observers and how to use them
  • How to handle Ajax requests

We will assume here, that you have read Chapter 1, Building Your First FuelPHP Application,...

Specifications

First of all, let's define what should be expected in our final application as follows:

  • A to-do list is created to monitor the progress of a project. A project is described by a name and has many tasks (the to-do list). We will assume here that a user could have many simultaneous projects and, therefore, can create and manage as many projects as he/she wants. Each project can also be deleted.
  • A task is described by a name and has a Boolean status ("done" or "not done").
  • Tasks are ordered in the project and the user should be able to easily move items in the list using drag and drop.

This is still a simple application, and we won't support any privacy feature such as authentication (this will be addressed in Chapters 3, Building a Blog Application and Chapter 5, Building Your Own Restful API).

Conception

This step should be pretty straightforward from the specification phase. We will generate the following two models:

  • Project: This model will only have a name property.
  • Task: This model will have a name, a status, and a rank property. A project contains many tasks, and each task is related to a project, so we will add an additional column here, named project_id. This column will contain the ID of the project each task is associated with.

We can represent our models by the following ER diagram:

Conception

Entity Relationship diagram (Min-Max notation)

An ER diagram allows you to describe the data structure of your application. As you noticed, almost everything we wrote earlier can be found in the diagram:

  • The models (called entities in ER diagrams), represented by rectangles
  • The model's properties (called attributes), represented by ellipses (primary keys are underlined) and linked to models using lines
  • The relationships between models, represented by a line from a model to another

We used the...

FuelPHP installation and configuration

You first need to:

  • Install a new FuelPHP instance
  • Configure Apache and your host file to handle it: in this chapter, we will access our application by requesting the URL http://mytodolists.app
  • Update Composer if necessary
  • Create a new database for your application
  • And configure FuelPHP in order to allow your application to access this database

These steps have been covered in Chapter 1, Building Your First FuelPHP Application, so you might want to take a look at it.

This project will also need the ORM package, and since it is already installed, we just need to enable it. For doing this, simply open the APPPATH/config/config.php file and insert the following at the end of the returned array:

  'always_load'  => array(
    'packages'  => array(
      'orm',
    ),
  ),

Or you can uncomment the appropriate lines. This will load the ORM package every time the FuelPHP instance is loaded.

Note

You can also load a package in an ad...

Scaffolding

We will now generate, as in Chapter 1, Building Your First FuelPHP Application, the necessary code to handle our objects.

Let's first generate the scaffold of the project model:

php oil generate scaffold/orm project name:string

The command should print the following output:

Creating migration: APPPATH/migrations/001_create_projects.php
Creating model: APPPATH/classes/model/project.php
Creating controller: APPPATH/classes/controller/project.php
Creating view: APPPATH/views/project/index.php
Creating view: APPPATH/views/project/view.php
Creating view: APPPATH/views/project/create.php
Creating view: APPPATH/views/project/edit.php
Creating view: APPPATH/views/project/_form.php
Creating view: APPPATH/views/template.php

Note that we used scaffold/orm instead of scaffold/crud in Chapter 1, Building Your First FuelPHP Application: this way, oil will generate code files that use the ORM package. For instance, we will see later that the generated model will extend Orm\Model instead...

Routes configuration

You can now manage your project by requesting the URL http://mytodolists.app/project.

Since this is our point of entry, we would like to access this page when requesting the root URL http://mytodolists.app/.

As we saw in Chapter 1, Building Your First FuelPHP Application, you just need to edit the APPPATH/config/routes.php configuration file. Replace '_root_' => 'welcome/index' with '_root_' => 'project/index'.

Specifications


First of all, let's define what should be expected in our final application as follows:

  • A to-do list is created to monitor the progress of a project. A project is described by a name and has many tasks (the to-do list). We will assume here that a user could have many simultaneous projects and, therefore, can create and manage as many projects as he/she wants. Each project can also be deleted.

  • A task is described by a name and has a Boolean status ("done" or "not done").

  • Tasks are ordered in the project and the user should be able to easily move items in the list using drag and drop.

This is still a simple application, and we won't support any privacy feature such as authentication (this will be addressed in Chapters 3, Building a Blog Application and Chapter 5, Building Your Own Restful API).

Conception


This step should be pretty straightforward from the specification phase. We will generate the following two models:

  • Project: This model will only have a name property.

  • Task: This model will have a name, a status, and a rank property. A project contains many tasks, and each task is related to a project, so we will add an additional column here, named project_id. This column will contain the ID of the project each task is associated with.

We can represent our models by the following ER diagram:

Entity Relationship diagram (Min-Max notation)

An ER diagram allows you to describe the data structure of your application. As you noticed, almost everything we wrote earlier can be found in the diagram:

  • The models (called entities in ER diagrams), represented by rectangles

  • The model's properties (called attributes), represented by ellipses (primary keys are underlined) and linked to models using lines

  • The relationships between models, represented by a line from a model to another

We used the Min...

FuelPHP installation and configuration


You first need to:

  • Install a new FuelPHP instance

  • Configure Apache and your host file to handle it: in this chapter, we will access our application by requesting the URL http://mytodolists.app

  • Update Composer if necessary

  • Create a new database for your application

  • And configure FuelPHP in order to allow your application to access this database

These steps have been covered in Chapter 1, Building Your First FuelPHP Application, so you might want to take a look at it.

This project will also need the ORM package, and since it is already installed, we just need to enable it. For doing this, simply open the APPPATH/config/config.php file and insert the following at the end of the returned array:

  'always_load'  => array(
    'packages'  => array(
      'orm',
    ),
  ),

Or you can uncomment the appropriate lines. This will load the ORM package every time the FuelPHP instance is loaded.

Note

You can also load a package in an ad hoc manner, using the Package...

Scaffolding


We will now generate, as in Chapter 1, Building Your First FuelPHP Application, the necessary code to handle our objects.

Let's first generate the scaffold of the project model:

php oil generate scaffold/orm project name:string

The command should print the following output:

Creating migration: APPPATH/migrations/001_create_projects.php
Creating model: APPPATH/classes/model/project.php
Creating controller: APPPATH/classes/controller/project.php
Creating view: APPPATH/views/project/index.php
Creating view: APPPATH/views/project/view.php
Creating view: APPPATH/views/project/create.php
Creating view: APPPATH/views/project/edit.php
Creating view: APPPATH/views/project/_form.php
Creating view: APPPATH/views/template.php

Note that we used scaffold/orm instead of scaffold/crud in Chapter 1, Building Your First FuelPHP Application: this way, oil will generate code files that use the ORM package. For instance, we will see later that the generated model will extend Orm\Model instead of Model_Crud...

Left arrow icon Right arrow icon

Description

This book is for intermediary to seasoned web developers who want to learn how to use the FuelPHP framework and build complex projects using it. You should be familiar with PHP, HTML, CSS, and JavaScript, but no prior knowledge about MVC frameworks is required.

Who is this book for?

This book is for intermediary to seasoned web developers who want to learn how to use the FuelPHP framework and build complex projects using it. You should be familiar with PHP, HTML, CSS, and JavaScript, but no prior knowledge about MVC frameworks is required.
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 27, 2015
Length: 284 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985401
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Feb 27, 2015
Length: 284 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985401
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 97.98
Learning C++ by creating games with UE4
$48.99
FuelPHP Application Development Blueprints
$48.99
Total $ 97.98 Stars icon

Table of Contents

7 Chapters
1. Building Your First FuelPHP Application Chevron down icon Chevron up icon
2. Building a To-do List Application Chevron down icon Chevron up icon
3. Building a Blog Application Chevron down icon Chevron up icon
4. Creating and Using Packages Chevron down icon Chevron up icon
5. Building Your Own Restful API Chevron down icon Chevron up icon
6. Building a Website Using Novius OS Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(5 Ratings)
5 star 60%
4 star 20%
3 star 20%
2 star 0%
1 star 0%
Christopher M Jun 03, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I found this book to be clear and concise, and I was pleased that it covered a wide range of topics with only 5 chapters. I was especially glad to see one of those chapters devoted to implementing a REST API complete with a section on unit testing. I have some experience with PHP frameworks (specifically Kohana) and this book got me up to speed with FuelPHP in no time.
Amazon Verified review Amazon
Rich & Nowsh May 28, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
An excellent introduction to FuelPHP.If you're new to Fuel then this is the book for you. For me, it bridged the gap from being totally new to Fuel, and fairly new to MVC in general, to being at a place where I can use the excellent FuelPHP documentation to further my understanding of the framework.The author takes you through building several web applications, demonstrating different aspects of the framework, as well as how to use third party libraries, and create your own extensions (called packages in FuelPHP).
Amazon Verified review Amazon
A. Zubarev May 10, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
You will not come across many robust HMVC web frameworks and especially those built on top of the excellent and now in its rebirth PHP. To not to reiterate over the things how HMVC is much more advanced than the vanilla MVC you can read a nice blog post dedicated to this topic. If you do not bother visiting it I will not be lazy to state it is the familiar MVC, but logically structured. FuelPHP is exactly such an HMVC implementation. So if you ask why HMVC, well, here I offer two choices, ether get a free chapter of the FuelPHP Application Development Blueprints book, or listen to me, well read rather: it allows what not so-web developers call “design by contract” (DbC). But this is what I say after I read this book.So the book, it belongs to the “blueprints” Packt’s category of publications which means it guides you through building an implementation end-to-end and “starting” as its difficulty level. Sébastien has delivered both. Even more, you’ll actually build several apps, different in difficulty levels.I suggest a prospective reader be familiar with the concepts of the web development and web application principals, better yet has already done some basic, static web pages, and having some PHP knowledge is not going to harm.The book starts with mere basics, but by page 200 or so you are in very advanced areas as coding your own APIs. In short, all the major development aspects as project code maintenance and organization, unit testing are covered. Even creating your own REST service received a dedicated chapter which I liked the most. Even though the book does not boast with many graphics or any web page examples you are building the reader must be enjoying the fruits of her or his work regardless, after all Web apps are so graphical on any computer.You will not need much to go through this book and practice FuelPHP. It is freely available to download. The framework incorporates powerful tools as oil (utility and console) which facilitates creation of the building blocks of a web application. It is really powerful and if I am not mistaken saves developer a ton of time (think more money).The last chapter of the book is covering Novius OS. Novius is a Content Management web based solution. With Novius OS it is easy to start or when you do not have much time it might be the answer, deliver the complex content later! Why CMS? Because it is based on FuelPHP, and CMS’ are quite hard to make right. You can go and see a demo (highly recommend) and/or real businesses using it. It is just inspirational. You shall be convinced HMVC rocks, if not give it a pass and leave me a comment please why so. I found it attractive, yet, I discovered there is a web-hosting proposition that includes Novius. It is not free, but hey there is no free lunches, well, at the price advertised I deem it is quite economical for such an implementation.To sum-up, in my view this is a 4.5 out of 5 work as a book, but PHP, HMVC and FuelPHP all sassy!Disclaimer: I am not affiliated with anything FuelPHP and I intended this post does not serve as a promotion of any kind.
Amazon Verified review Amazon
Vinay Jun 05, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I found the book to be very helpful in what all development activities I was looking forward to. I would recommend the book to those looking forward to learning this book.
Amazon Verified review Amazon
Joan Fusté May 18, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
No se si el entorno de (mi) trabajo es muy diferente, pero desde luego este libro no me ha servido de mucha ayuda. Esperaba más, y más con su precio, nada económico.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
Modal Close icon
Modal Close icon