O'Reilly logo

Learning Phalcon PHP by Calin Rada

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modifying BaseController.php

Now, we should modify BaseController.php from the Frontend module to extend the core module and to assign categories globally to our views upon each request. Open modules/Frontend/Controllers/BaseController.php, clear its contents, and append this code:

<?php
namespace App\Frontend\Controllers;

class BaseController extends \App\Core\Controllers\BaseController
{
    public function afterExecuteRoute()
    {
        $this->view->categories = $this->apiGet('categories');
    }
}

We don't actually have a home page (but we can add one anytime we want), so we are going to forward the request to ArticlesController. Open modules/Frontend/Controllers/IndexController.php, remove indexAction(), and append the following code:

 public function indexAction() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required