Book Image

Phalcon Cookbook

By : Serghei Iakovlev, David Schissler
1 (2)
Book Image

Phalcon Cookbook

1 (2)
By: Serghei Iakovlev, David Schissler

Overview of this book

Phalcon is a high-performance PHP framework delivered as a PHP extension. This provides new opportunities for speed and application design, which until recently have been unrealized in the PHP ecosystem. Packed with simple learning exercises, technology prototypes, and real-world usable code, this book will guide you from the beginner and setup stage all the way to advanced usage. You will learn how to avoid niche pitfalls, how to use the command-line developer tools, how to integrate with new web standards, as well as how to set up and customize the MVC application structure. You will see how Phalcon can be used to quickly set up a single file web application as well as a complex multi-module application suitable for long-term projects. Some of the recipes focus on abstract concepts that are vital to get a deep comprehension of Phalcon and others are designed as a vehicle to deliver real-world usable classes and code snippets to solve advanced problems. You’ll start out with basic setup and application structure and then move onto the Phalcon MVC and routing implementation, the power of the ORM and Phalcon Query Language, and Phalcon’s own Volt templating system. Finally, you will move on to caching, security, and optimization.
Table of Contents (17 chapters)
Phalcon Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Creating the application directory structure


In this recipe, we will take a brief look at the commonly used directory structure of a single module application. A structure of this type is aimed at providing a great starting point for different applications.

Getting ready

We don't need any special means to implement this recipe. We will create the project structure on site, at the development stage. Important points of this recipe are the names of directories and their location.

How to do it…

Follow these steps to complete this recipe:

  1. Create a root directory for your project, where myprojectname is the name of your project:

    /var/www/myprojectname
  2. Create three second-level directories in the root directory:

    /var/www/myprojectname/app
    /var/www/myprojectname/public
    /var/www/myprojectname/.phalcon
  3. Create the following subdirectories in the public directory:

    /var/www/myprojectname/public/css
    /var/www/myprojectname/public/img
    /var/www/myprojectname/public/js
  4. Create the following subdirectories in the app directory:

    /var/www/myprojectname/app/cache
    /var/www/myprojectname/app/config
    /var/www/myprojectname/app/controllers
    /var/www/myprojectname/app/library
    /var/www/myprojectname/app/logs
    /var/www/myprojectname/app/models
    /var/www/myprojectname/app/tasks
    /var/www/myprojectname/app/views
  5. Create the following subdirectories in the cache directory:

    /var/www/myprojectname/app/cache/annotations
    /var/www/myprojectname/app/cache/data
    /var/www/myprojectname/app/cache/metadata
    /var/www/myprojectname/app/cache/volt
  6. Make sure that the just created structure eventually appears as follows:

    myprojectname
    ├── app

    │   │── cache
    │   │   ├── annotations
    │   │   ├── data
    │   │   ├── metadata
    │   │   └── volt
    │   ├── config
    │   ├── controllers
    │   ├── library
    │   ├── logs
    │   ├── models
    │   ├── tasks
    │   └── views
    ├── .phalcon
    └── public
        ├── css
        ├── img
        └── js

How it works…

The project root directory contains the following directories: app, public, and .phalcon (note that the last one has a point at the beginning of its name).

In the app directory, there will be, as you would expect, the main application code. We will describe this folder in detail shortly.

The public directory will contain the entry point of your application and directories for various static assets (JavaScript files, images, and CSS files).

The .phalcon directory will be used by the Phalcon developer tools for internal purposes (migration creation, code generation, and so on). This is the Phalcon system directory. There is no need to create something in it.

The app directory contains a subdirectory for controllers as well as their views and models. Additionally, there is the tasks directory, which is intended for cli tasks, the library directory for the general application components (plug-ins, helpers, and other custom classes), the logs directory, where we will store our log files, and the cache directory for storing cached data of different application components.

In the cache directory, there are the following directories: annotations to store the file cache of model annotations, data to store common file cache, metadata to store the model structure cache, and volt to store the view cache.

Note that we have created different directories to store screenshots. These directories are utilized when we are using the File Cache. If you will be using a cache adapter other than the File one, you don't need to create the directory structure here.