Answer the question
In order to leave comments, you need to log in
How to make an initialization function in Phalcon?
The question is, there are some actions that should occur when any controller is triggered, for example, setting the default page title. The developers in the documentation suggest using the following scheme:
<?php
use Phalcon\Mvc\Controller;
class ControllerBase extends Controller
{
protected function initialize()
{
$this->tag->setTitle('INVO');
}
// ...
}
<?php
class ProductsController extends ControllerBase
{
public function initialize()
{
parent::initialize();
$this->tag->prependTitle('Управление типами ваших продуктов | ');
}
// ...
}
<?php
public function initialize()
{
parent::initialize();
}
Answer the question
In order to leave comments, you need to log in
Yes, it is possible in different ways, for example, to make the AwarePageMetainfo interface, with a method, for example, getTitle (). Then implement this interface in the controllers you need, then write the "beforeExecuteRoute" dispatch event listener, in it you get the active controller, check the implementation of the desired interface, and then set the page meta-information.
And then OOP enters in each controller will have its own implementation of the interface. Well, I think the idea is clear)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question