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

Getting your IDE to work nicely with Phalcon


Most IDEs have some form of code completion as part of the program. To enable auto-completion for Phalcon's namespaces, we will need to help the IDE recognize those namespaces. We will also see how to enable Volt syntax highlighting and Phalcon API auto-completion for major IDEs.

Getting ready

To get started, we should have Git installed. To enable auto-completion in your IDE, you need to get the Phalcon stubs. For these purposes, clone the Phalcon Developer Tools repository:

git clone [email protected]:phalcon/phalcon-devtools.git

How to do it…

The following are the steps needed to complete this recipe.

Ways to enable Phalcon API autocompletion in major IDEs

PhpStorm
  1. Using the Project Tool window in PhpStorm, select External Libraries, right-click on the section, and select Configure PHP Include Paths... from the drop-down menu.

  2. Then, using the External Libraries dialog box, click the + button. Next, select the Specify Other... option in the drop-down menu and specify the location of the Phalcon stubs. The stubs are located in the phalcon-devtools repository you just cloned under the /ide subfolder. You should specify the path phalcon-devtools/ide/stubs/Phalcon and click on Apply.

NetBeans
  1. In NetBeans, you need to open the Projects window (Ctrl + F1) and select Include Path. Right-click on the section and select Properties from the drop-down menu.

  2. Then, open the Project Properties window and click on the Add Folder... button. Next, specify the location of the Phalcon stubs. The stubs are located in the phalcon-devtools repository you just cloned under the /ide subfolder. You should specify the path phalcon-devtools/ide/stubs/Phalcon and click on the OK button.

Ways to enable Volt syntax highlighting in major IDEs

Netbeans
  1. Click on the Tools menu entry and select Options.

  2. In the opened window, select Miscellaneous | Files.

  3. In the File Associations group box, click on the button New… next to the File Extensions option, enter the extension volt, and click on OK.

  4. Select TWIG (text/x-twig) in the Associated File Type (MIME) drop-down menu.

PhpStorm
  1. Open File | Settings. Next select Editor | File Types.

  2. In the Recognized File Types group box, select Twig and add the extension *.volt into the Registered Patterns group box by pressing the + button.

Syntax highlighting for Sublime Text or TextMate

Installation via Package Control

If you have Sublime Package Control, you know what to do. If not, well, it's a package manager for Sublime Text, and it's awesome!

After installing Sublime Package Control and restarting the editor:

  1. Open the Command Palette (Ctrl + Shift + P or Cmd + Shift + P).

  2. Type Install Package and press Enter.

  3. Find Volt and press Enter.

Manual installation

For manual installation, clone the Volt syntax highlight for the Sublime Text 2/Textmate repository:

[email protected]:phalcon/volt-sublime-textmate.git

Depending on your OS, copy the volt-sublime-textmate/Volt directory to any of the following locations:

  1. Sublime Text 2:

    1. Mac OS X:

      ~/Library/Application Support/Sublime Text 2/Packages
    2. Linux:

      ~/.Sublime Text 2/Packages
    3. Windows:

      %APPDATA%/Sublime Text 2/Packages/
  2. Sublime Text 3:

    1. Mac OS X:

      ~/Library/Application Support/Sublime Text 3/Packages
    2. Linux:

      ~/.Sublime Text 3/Packages
    3. Windows:

      %APPDATA%/Sublime Text 3/Packages/
  3. TextMate:

    /Library/Application Support/TextMate/Bundles

How it works…

Some IDEs need help understanding the framework syntax. To get the IDE to understand, we download a list of all the Phalcon stubs. Then, when we add it to the include path, NetBeans (or PhpStorm) will automatically check the file and show us the autocomplete options. To enable the Volt or Zephir syntax highlight, we have to configure our IDE or text editor accordingly.