5 min read

The milkshake shop

Our application will be designed for a fictitious milkshake shop. The functional requirements for our shop are:

  • Display of the menu, job vacancies, and locations; these details will be updated from the back office
  • Sign up to a newsletter, where users can submit their details
  • Search facility for the menu
  • Secure backend for staff to update the site
  • The site must be responsive
  • Option for the users to view our vacancies in three languages

Creating the skeleton folder structure

Symfony has many ways in which it can help the developer create applications with less efforts—one way is by using the Symfony tasks available on the Command Line Interface (CLI). These Symfony tasks do the following:

  • Generate the folder structure for your project, modules, applications, and tasks
  • Clear the generated cache and rotate log files
  • Create controllers to enable and disable an application and set permissions
  • Interact with the ORM layer to build models and forms
  • Interact with SQL to insert data into the database
  • Generate initial tests and execute them
  • Search for text in your templates that need i18N dictionaries and create them

If you’d like to see all the tasks that are available with Symfony, just type the following on your command line:
symfony

Let’s begin with using one of the Symfony tasks to generate the file structure for our project. Our project will reside in the milkshake folder. In your terminal window, change your folder path to the path that will hold your project and create this milkshake folder. My folder will reside in workspace folder. Therefore, I would type this:

$mkdir ~/workspace/milkshake && cd ~/workspace/milkshake

Now that I have the project folder and have changed the path to within the milkshake folder, let’s use a Symfony task to generate the project file structure. In your terminal window, type the following:

$/home/timmy/workspace/milkshake>symfony generate:project -orm=Propel milkshake

We can generate our project we can also specify which ORM we would like to use. Our application is going to use the Propel ORM, but you can also opt for Doctrine ORM. By default, Doctrine ORM is enabled.

After pressing the Enter key, the task goes into action. Now you will see output like the one in the following screenshot on your terminal window. This screenshot shows the folder structure being created:

Symfony 1.3 Web Application Development

Let’s have a look at the top-level folders that have been created in our project folder:

Folders

Description

apps

This folder contains our frontend application and any other applications that we will create

batch

If there are any batch scripts, they are placed here

cache

This folder is the location for cached files and/or scaffolded modules

config

This folder holds all the main configuration files and the database schema definitions

data

This folder holds data files such as test or fixture data

doc

All our documentation should be stored in this folder; this includes briefs, PhpDoc for API, Entity Relationship Diagrams, and so on

lib

Our models and classes are located in this folder so that all applications can access them

log

This folder holds the development controllers log files and our Apache log

plugins

All installed plugins are located in this folder

test

All unit and functional tests should be placed in this folder; Symfony will create and place stubs in this folder when we create our modules

web

This is the web root folder that contains all web resources such as images, CSS, JavaScript, and so on

There are three folders that must be writable by the web server. These are the cache, log, and web/uploads/. If these are not writable to your web server, then the server itself will either produce warnings at startup or fail to start. The files permissions are usually set during the generation process, but sometimes this can fail. You can use the following task to set the permissions:
$/home/timmy/workspace/milkshake>symfony project:permissions

With the initial project skeleton built, next we must create an application. Symfony defines an application as operations that are grouped logically and that can run independent of one another. For example, many sites have a frontend and back office/admin area. The admin area is where a user logs in and updates areas on the frontend. Of course, our application will also provide this functionality. We will call these areas frontend and backend. Our first application is going to be the frontend. Again, let’s use a Symfony task to generate the frontend application folder structure. Enter the following task in your terminal window:

$/home/timmy/workspace/milkshake>symfony generate:app frontend

Again, after executing this task, you will see the following in your terminal window:

Symfony 1.3 Web Application Development

Let’s have a look at the top-level folders that have just been created in the apps folder:

Directory

Description

config

This folder will have all configuration files for our application

i18N

This folder will contain all Internationalization files

lib

This folder will hold all application-specific classes

modules

All our modules will be built in this folder

templates

The default layout template is created in this folder, and any other global templates that will be created will also be placed in this folder

These steps will generate our project and frontend application folder structure, and we can now view our project in a web browser. Open your web browser and go to http://milkshake/frontend_dev.php and you will see the following default Symfony page:

Symfony 1.3 Web Application Development

Now we can see the default project page along with the instructions on what to do next. The frontend_dev.php file is our index file while developing the frontend application, and adheres to the naming convention of <application>_<environment>.php. This controller is the development controller and is rather helpful while developing. Before we continue though, I urge you to also have a look at the web debug toolbar.

LEAVE A REPLY

Please enter your comment!
Please enter your name here