Sinsing analysis of commonly used dependency injection in Phalcon

Source: Internet
Author: User

Phalcon also uses dependency injection, and Phalcon in the process of booting, need to use a lot of classes, these classes are configured through dependency injection, and then loaded through the loader, the following describes the service often need to inject.

For router Router, it is responsible for parsing the URL parameters, the class file is \phalcon\mvc\router, its add parameter class configures a route, the following is an example of the addition:

$di->set (' Router ', function () {                $router = new \phalcon\mvc\router ();                $router->add ("/:module/:controller/:action/:p arams", Array (                  ' module ' = = 1,                  ' controller ' = 2,                  ' Action ' = 3,                  ' params ' = 4, '              );              $router->setdefaultmodule ("entrance");              $router->setdefaultcontroller ("index");              $router->setdefaultaction ("index");              $router->notfound (                  Array (                      "module" = "entrance",                      "Controller" = "index",                      "action" = > "index",                  )              );              return $router;   }  

For view views, the typical example of our general configuration is as follows:

$di->set (' View ', function () {              $view = new \phalcon\mvc\view ();              $view->setbasepath ('./entrance/');              $view->setviewsdir ('./views/');              $view->registerengines (Array (                  '. Volt ' = ' Phalcon\mvc\view\engine\volt ',                  ". phtml" = ' Phalcon\mvc \view\engine\php ',              ));              return $view;          

For URLs, we need to add that its main purpose is to avoid problems when jumping, general configuration:

$di->set (' url ', function () {              $url = new Phalcon\mvc\url ();              $url->setbaseuri ('/star/');              return $url;          

For the session, give an example:


$di->setshared (' Session ', function () {              $session = new Phalcon\session\adapter\files ();              $session->start ();              return $session;          });  





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Sinsing analysis of commonly used dependency injection in Phalcon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.