In Phalcon you can register namespaces, prefixes, directories or classes by loader class. Below are sample usage for same.
Registering namespaces/prefixes in Phalcon
use Phalcon\Loader; $loader = new Loader(); // Register some namespaces $loader->registerNamespaces( [ "Example\Base" => "vendor/example/base/", "Example\Adapter" => "vendor/example/adapter/", "Example" => "vendor/example/", ] ); // Register autoloader $loader->register();
Registering directories in Phalcon
use Phalcon\Loader; // Creates the autoloader $loader = new Loader(); // Register some directories $loader->registerDirs( [ "library/MyComponent/", "library/OtherComponent/Other/", "vendor/example/adapters/", "vendor/example/", ] ); // Register autoloader $loader->register();
Registering classes in Phalcon
use Phalcon\Loader; // Creates the autoloader $loader = new Loader(); // Register some classes $loader->registerClasses( [ "Some" => "library/OtherComponent/Other/Some.php", "Example\Base" => "vendor/example/adapters/Example/BaseClass.php", ] ); // Register autoloader $loader->register();
Routing in Phalcon Framework is managed by its Router component. Router components allow you to
define routes that are mapped to controllers or handlers that should receive the request from your application.A router simply parses a URI to determine this information. The router has two modes: MVC mode and match-only mode. The first mode is ideal for working with MVC applications.
Phalcon uses an independent module “Phalcon\Validation” for validating users requests. This component can be used to implement validation rules on data objects that do not belong to a model or collection.
The loosely-coupled design of this component allows you to create your own validators along with the ones provided by the framework.
The following example shows basic usage of validations in Phalcon :
<?php use Phalcon\Forms\Element\Text; use Phalcon\Validation\Validator\PresenceOf; use Phalcon\Validation\Validator\StringLength; $name = new Text( "name" ); $name->addValidator( new PresenceOf( [ "message" => "The name is required", ] ) ); $name->addValidator( new StringLength( [ "min" => 10, "messageMinimum" => "The name is too short", ] ) ); $form->add($name);
Phalcon session component provides object-oriented wrappers to access session data.
Below is usage guide to Read, Write and Delete sessions in Phalcon
Writing or Creating session in Phalcon
Reading or Retrieving session in Phalcon
Deleting or Removing session in Phalcon
Phalcon offers the object-oriented classes, necessary to implement the Model, View, Controller architecture (often referred to as MVC) in your application. This design pattern is widely used by other web frameworks and desktop applications.
MVC benefits include:
If you decide to use MVC, every request to your application resources will be managed by the MVC architecture. Phalcon classes are written in C language, offering a high-performance approach to this pattern in a PHP based application.
Zephir – Ze(nd Engine) Ph(p) I(nt)r(mediate) – is a high-level language that eases the creation and maintainability of extensions for PHP. Zephir extensions are exported to C code that can be compiled and optimized by major C compilers such as gcc/clang/vc++. Functionality is exposed to the PHP language
Phalcon uses a powerful and fast templating engine called Volt.
Volt is an ultra-fast and designer-friendly templating language written in C for PHP. It provides you a set of helpers to write views in an easy way. Volt is highly integrated with other components of Phalcon, just as you can use it as a stand-alone component in your applications.
Also, Read Best Laravel 5 interview questions
Below is the list of Application Events in Phalcon.
|boot||Executed when the application handles its first request|
|beforeStartModule||Before initialize a module, only when modules are registered|
|afterStartModule||After initializing a module, only when modules are registered|
|beforeHandleRequest||Before execute the dispatch loop|
|afterHandleRequest||After execute the dispatch loop|
Never Miss an Articles from us.