Phalcon Interview Questions and Answers
Most Frequently Asked Phalcon Interview Questions
There are 2 ways to inject services into Volt -
- Define the function in the dependency injection container. Access the service in the template with its name. Example - <input name="‘counter’" value="‘{{maxproduct.getCounter()" }}>
- When Volt is used as a stand-alone component, create a compiler as $compiler = new VoltCompiler(); and compile the template by passing different return parameters.
You can use setVar() or setVars() in the controller’s showAction() method to pass single or multiple variables respectively, directly to the view.
- $this->view->setVar('productId', $productId);
- $this->view->setVars( ['username' => $user->username, 'phone' => $contact->phone,] );
Instead of using the above methods, you can also set the variables as $this->view->username = $user->username;
There are 3 database engines supported by Phalcon – Mysql, Postgresql, and SQLite.
S.no | PHALCON | LARAVEL |
---|---|---|
1. | is a php extension written in C, which is injected into the php core at runtime | is a source base on which web developers build their applications |
2. | offers high performance and fast execution | is slower and can process fewer requests compared to Phalcon |
3. | uses ODM which is fast and has a simple, understandable syntax | relies on ORM which supports almost all the databases |
4. | uses the Volt template engine | uses Blade template engine |
5. | requires root access to be installed | doesn’t need root access |
6. | has fewer forum exchanges and documentation compared to Laravel | has a more significant community and more support documentation |
There are two types of views in Phalcon –
- Volt – used when the template engine is written in C and compiled in php, can be used as a stand-alone component.
- Phtml – used when the template engine is in php itself.
- .volt files are written in C language and later compiled to php code. These can be used as a stand-alone component and includes a set of highly integrated elements.
- .phtml files should be created when php is used as a template engine. The view is the default rendering component and is called to execute a particular action. .phtml cannot be used as a stand-alone component.
No need to declare a variable in Phalcon; the variable is created when its value is assigned. Example - $name = “user1”;
Single module applications have only one module. This application does not mandate a namespace. It has a structure as –
single/
app/
controllers/
models/
views/
public/
css/
img/
js/
Multi-module uses the same document root for all the modules. Each directory in apps has an MVC structure of its own. Module-specific settings are configured using Module.php present in each module. The structure is like –
multiple/
apps/
frontend/
controllers/
models/
views/
Module.php backend/
controllers/
models/
views/
Module.php public/
css/
img/
js/