Setup Routing

Navigate to my-project/app/config/services.php:

phpCopy code<?php

use Phalcon\Mvc\View;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Url as UrlResolver;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;

$di->setShared('config', function () {
    return include APP_PATH . "/config/config.php";
});

$di->setShared('db', function () use ($config) {
    return new DbAdapter([
        'host'     => $config->database->host,
        'username' => $config->database->username,
        'password' => $config->database->password,
        'dbname'   => $config->database->dbname,
    ]);
});

$di->setShared('url', function () use ($config) {
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});

$di->setShared('view', function () use ($config) {
    $view = new View();
    $view->setViewsDir($config->application->viewsDir);
    return $view;
});

$di->setShared('dispatcher', function () {
    $dispatcher = new Dispatcher();
    return $dispatcher;
});

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *