Пример #1
0
 protected function registerAutoloaders()
 {
     $loader = new Phalcon\Loader();
     $loader->registerNamespaces(['api' => APP_DIR . 'api']);
     $loader->registerDirs([APP_DIR . 'model']);
     $loader->register();
 }
Пример #2
0
 /**
  * register Loader
  */
 protected function registerLoader()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($this->config->application->registerNamespaces->toArray());
     $loader->registerDirs($this->config->application->registerDirs->toArray());
     $loader->register();
     $this->di->set('loader', $loader);
 }
Пример #3
0
 /**
  * 注册命名空间
  */
 public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = NULL)
 {
     $config = \TConfig::instance()->getModule($this->moduleId);
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(isset($config['autoloadDir']) ? $config['autoloadDir'] : array());
     $loader->registerNamespaces(isset($config['autoloadNamespace']) ? $config['autoloadNamespace'] : array());
     $loader->register();
 }
Пример #4
0
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 protected function _registerServices()
 {
     $config = (include __DIR__ . "/../apps/config/config.php");
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array($config->application->libraryDir, $config->application->pluginDir))->register();
     //Registering a router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add("/cats/index", array('module' => 'frontend', 'controller' => 'categories', 'action' => 'index'));
         $router->add("/cat/:params", array('module' => 'frontend', 'controller' => 'categories', 'action' => 'cat', 'params' => 1));
         $router->add("/ask/:params", array('module' => 'frontend', 'controller' => 'ask', 'action' => 'ask', 'params' => 1));
         $router->add("/admin/:controller/:action/:params", array('module' => 'backend', 'controller' => 1, 'action' => 2, 'params' => 3));
         return $router;
     });
     $di->set('db', function () use($config) {
         $mysql = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
         $mysql->query("set names 'utf8'");
         return $mysql;
     });
     $di->set('volt', function ($view, $di) use($config) {
         $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
         $volt->setOptions(array('compiledPath' => $config->volt->path, 'compiledExtension' => $config->volt->extension, 'compiledSeparator' => $config->volt->separator, 'stat' => (bool) $config->volt->stat));
         return $volt;
     });
     //Set the views cache service
     $di->set('viewCache', function () {
         //Cache data for one day by default
         $frontCache = new Phalcon\Cache\Frontend\Output(array("lifetime" => 86400));
         //Memcached connection settings
         $cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => "../apps/caches/"));
         return $cache;
     });
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise
      */
     $di->set('modelsMetadata', function () use($config) {
         if (isset($config->models->metadata)) {
             $metaDataConfig = $config->models->metadata;
             $metadataAdapter = 'Phalcon\\Mvc\\Model\\Metadata\\' . $metaDataConfig->adapter;
             return new $metadataAdapter();
         } else {
             return new Phalcon\Mvc\Model\Metadata\Memory();
         }
     });
     //Start the session the first time some component request the session service
     $di->set('session', function () {
         $session = new Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->setDI($di);
 }
Пример #5
0
 public function run()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     // Config
     require_once APPLICATION_PATH . '/modules/Cms/Config.php';
     $config = \Cms\Config::get();
     $di->set('config', $config);
     // Registry
     $registry = new \Phalcon\Registry();
     $di->set('registry', $registry);
     // Loader
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces($config->loader->namespaces->toArray());
     $loader->registerDirs([APPLICATION_PATH . "/plugins/"]);
     $loader->register();
     require_once APPLICATION_PATH . '/../vendor/autoload.php';
     // Database
     $db = new \Phalcon\Db\Adapter\Pdo\Mysql(["host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset]);
     $di->set('db', $db);
     // View
     $this->initView($di);
     // URL
     $url = new \Phalcon\Mvc\Url();
     $url->setBasePath($config->base_path);
     $url->setBaseUri($config->base_path);
     $di->set('url', $url);
     // Cache
     $this->initCache($di);
     // CMS
     $cmsModel = new \Cms\Model\Configuration();
     $registry->cms = $cmsModel->getConfig();
     // Отправляем в Registry
     // Application
     $application = new \Phalcon\Mvc\Application();
     $application->registerModules($config->modules->toArray());
     // Events Manager, Dispatcher
     $this->initEventManager($di);
     // Session
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     $di->set('session', $session);
     $acl = new \Application\Acl\DefaultAcl();
     $di->set('acl', $acl);
     // JS Assets
     $this->initAssetsManager($di);
     // Flash helper
     $flash = new \Phalcon\Flash\Session(['error' => 'ui red inverted segment', 'success' => 'ui green inverted segment', 'notice' => 'ui blue inverted segment', 'warning' => 'ui orange inverted segment']);
     $di->set('flash', $flash);
     $di->set('helper', new \Application\Mvc\Helper());
     // Routing
     $this->initRouting($application, $di);
     $application->setDI($di);
     // Main dispatching process
     $this->dispatch($di);
 }
Пример #6
0
 public static function init($dirs = array(), $namespaces = array())
 {
     $commonDirs = array();
     $commonDirs[] = dirname(__FILE__);
     $commonDirs[] = realpath(dirname(dirname(__FILE__)) . '/_library');
     $commonNamespaces = array();
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array_merge($commonDirs, $dirs));
     $loader->registerNamespaces(array_merge($commonNamespaces, $namespaces));
     $loader->register();
 }
Пример #7
0
 public static function init()
 {
     try {
         $loader = new \Phalcon\Loader();
         $loader->registerDirs([__DIR__ . DS . 'controllers' . DS, __DIR__ . DS . 'views' . DS, __DIR__ . DS . 'models' . DS, __DIR__ . DS . 'lib' . DS])->registerNamespaces(['Phalway' => __DIR__])->register();
         context()->set('phalwayLoader', $loader);
         $di = new \Phalcon\DI\FactoryDefault();
         return new \Phalcon\Mvc\Application($di);
     } catch (\Phalcon\Exception $e) {
         dd($e);
     }
 }
Пример #8
0
 public function onWorkerStart()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array(ROOT_PATH . '/application/controller/', ROOT_PATH . '/application/model/'));
     $loader->register();
     $this->di = new \Phalcon\Di\FactoryDefault();
     //Registering the view component
     $this->di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(ROOT_PATH . '/application/views/');
         return $view;
     });
 }
Пример #9
0
 public function testApplicationSingleModule()
 {
     // Creates the autoloader
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array(__DIR__ . '/controllers/'));
     $loader->register();
     $_GET['_url'] = '/test2';
     $di = new Phalcon\DI\FactoryDefault();
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     });
     $application = new Phalcon\Mvc\Application();
     $application->setDi($di);
     $this->assertEquals($application->handle()->getContent(), '<html>here</html>' . PHP_EOL);
     $loader->unregister();
 }
Пример #10
0
 /**
  * Register loader
  */
 protected function registerLoader()
 {
     $config =& $this->configuration;
     $loader = new \Phalcon\Loader();
     if (isset($config['application']['registerNamespaces'])) {
         $loadNamespaces = $config['application']['registerNamespaces'];
     } else {
         $loadNamespaces = array();
     }
     foreach ($config['application']['modules'] as $module => $enabled) {
         $moduleName = ucfirst($module);
         $loadNamespaces[$moduleName . '\\Model'] = APPLICATION_PATH . '/modules/' . $module . '/models/';
         $loadNamespaces[$moduleName . '\\Service'] = APPLICATION_PATH . '/modules/' . $module . '/services/';
     }
     if (isset($config['application']['registerDirs'])) {
         $loader->registerDirs($config['application']['registerDirs']);
     }
     $loader->registerNamespaces($loadNamespaces)->register();
 }
Пример #11
0
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 protected function _registerServices()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
     //Registering a router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add("/login", array('module' => 'backend', 'controller' => 'login', 'action' => 'index'));
         $router->add("/admin/products/:action", array('module' => 'backend', 'controller' => 'products', 'action' => 1));
         $router->add("/products/:action", array('module' => 'frontend', 'controller' => 'products', 'action' => 1));
         return $router;
     });
     $this->setDI($di);
 }
Пример #12
0
<?php

$loader = new \Phalcon\Loader();
// --------------------------------------------------------------------
// We're a registering a set of directories taken from the configuration file
// --------------------------------------------------------------------
$loader->registerDirs([$config->application->controllersDir, $config->application->modelsDir]);
$loader->registerNamespaces(['Admin' => __DIR__ . '/../controllers/admin']);
$loader->register();
// End of File
// --------------------------------------------------------------------
Пример #13
0
<?php

try {
    //Autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(['../app/controllers/', '../app/models/']);
    $loader->register();
    // Dependency Injection
    $di = new \Phalcon\DI\FactoryDefault();
    $di->set('view', function () {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views');
        return $view;
    });
    //Deploy the App
    $app = new \Phalcon\Mvc\Application($di);
    echo $app->handle()->getContent();
} catch (\Phalcon\Exception $e) {
    echo $e->getMessage();
}
Пример #14
0
<?php

$loader = new \Phalcon\Loader();
$loader->registerDirs(array(__DIR__ . '/../tasks', __DIR__ . '/../services', __DIR__ . '/../models'));
$loader->registerNamespaces(array('Phalcon' => '/../incubator/Library/Phalcon/'));
$loader->register();
Пример #15
0
<?php

//setting default time_zone
ini_set('error_reporting', E_ALL);
date_default_timezone_set('PRC');
try {
    // $config = new Phalcon\Config\Adapter\Ini('../app/config/config.ini');
    $config = (include __DIR__ . "/../app/config/config.php");
    //Register an autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(array($config->application->controllersDir, $config->application->pluginsDir, $config->application->libraryDir, $config->application->modelsDir))->register();
    //Create a DI
    $di = new Phalcon\DI\FactoryDefault();
    //Setup the database service
    $di->set('db', function () use($config) {
        return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, 'charset' => 'UTF8'));
    });
    //Setup the view component
    $di->set('view', function () use($config) {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir($config->application->viewsDir);
        $view->registerEngines(array(".phtml" => 'Phalcon\\Mvc\\View\\Engine\\Php', ".volt" => 'volt'));
        return $view;
    });
    //Setup a base URI so that all generated URIs include the "tutorial" folder
    $di->set('url', function () use($config) {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri($config->resource->baseUri);
        return $url;
    });
    //Start the session the first time when some component request the session service
Пример #16
0
<?php

/* =====================================================
 * โหลดอัตโนมัติ
 * ลงทะเบียนโฟล์เดอร์
 * ===================================================== */
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(APPLICATION_PATH . $this->config->application->componentsDir, APPLICATION_PATH . $this->config->application->componentsLibraryDir, APPLICATION_PATH . $this->config->application->modelsDir, APPLICATION_PATH . $this->config->application->libraryDir, APPLICATION_PATH . $this->config->application->pluginsDir))->register();
Пример #17
0
<?php

/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2015/1/19
 * Time: 11:01
 */
$loader = new \Phalcon\Loader();
/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs([$config->application->packDir])->registerNamespaces(['Pari\\Mobile\\Controllers' => $config->application->controllersDir, 'Pari' => $config->application->pariDir])->register();
Пример #18
0
<?php

$loader = new \Phalcon\Loader();
/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(array($config->application->controllersDir, $config->application->modelsDir, $config->application->configDir));
$loader->register();
Пример #19
0
<?php

$loader = new \Phalcon\Loader();
/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(array($config->application->controllersDir, $config->application->modelsDir, $config->application->viewsDir, $config->application->libraryDir, $config->application->pluginsDir, $config->application->langDir, $config->application->vendorDir));
$loader->registerNamespaces(array('Phalcon' => '/var/www/html/goldenlight/incubator/Phalcon/'));
$loader->register();
Пример #20
0
<?php

$loader = new \Phalcon\Loader();
/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(array(APP_PATH . $config->application->controllersDir, APP_PATH . $config->application->pluginsDir, APP_PATH . $config->application->libraryDir, APP_PATH . $config->application->modelsDir, APP_PATH . $config->application->formsDir))->registerNamespaces(array('App\\Models' => APP_PATH . $config->application->modelsDir, 'App\\Controllers' => APP_PATH . $config->application->controllersDir, 'App\\Forms' => APP_PATH . $config->application->formsDir, 'App\\Plugins' => APP_PATH . $config->application->pluginsDir, 'App\\Libary' => APP_PATH . $config->application->libraryDir))->register();
//require APP_PATH . "/vendor/autoload.php";
Пример #21
0
<?php

/**
 * Registering an autoloader
 */
$loader = new \Phalcon\Loader();
$loader->registerDirs(array($config->application->modelsDir))->register();
Пример #22
0
<?php

$loader = new \Phalcon\Loader();
/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(array($config->application->edition->fieldsDir, $config->application->edition->utilDir, $config->application->edition->servicesDir, $config->application->edition->exemplesServicesDir, $config->application->edition->customServicesDir, $config->application->services->controllersDir))->register();
Пример #23
0
  <?php 
use Phalcon\DI, Phalcon\DI\FactoryDefault;
ini_set('display_errors', 1);
error_reporting(E_ALL);
define('ROOT_PATH', __DIR__);
define('PATH_LIBRARY', __DIR__ . '/../app/library/');
define('PATH_SERVICES', __DIR__ . '/../app/services/');
define('PATH_RESOURCES', __DIR__ . '/../app/resources/');
set_include_path(ROOT_PATH . PATH_SEPARATOR . get_include_path());
// required for phalcon/incubator
include __DIR__ . "/../vendor/autoload.php";
// use the application autoloader to autoload the classes
// autoload the dependencies found in composer
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(ROOT_PATH));
$loader->register();
$di = new FactoryDefault();
DI::reset();
// add any needed services to the DI here
DI::setDefault($di);
Пример #24
0
<?php

error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
ini_set('display_errors', 1);
require dirname(__FILE__) . '/../app/bootstrap.php';
define('VERSION', '1.0.0');
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(FA_INCLUDE_MODULES . '/cli/tasks'));
$loader->register();
// Create a console application
$console = new \Phalcon\CLI\Console();
$console->setDI($di);
// Process the console arguments
$arguments = array();
foreach ($argv as $k => $arg) {
    if ($k == 1) {
        $task_parts = explode(':', $arg);
        $arguments['task'] = $task_parts[0];
        $arguments['action'] = isset($task_parts[1]) ? $task_parts[1] : 'index';
    } elseif ($k > 1) {
        $arguments['params'][] = $arg;
    }
}
// define global constants for the current task and action
define('CURRENT_TASK', $arguments['task']);
define('CURRENT_ACTION', $arguments['action']);
try {
    // handle incoming arguments
    $console->handle($arguments);
} catch (\Phalcon\Exception $e) {
    echo $e->getMessage();
Пример #25
0
<?php

try {
    $config = new Phalcon\Config\Adapter\Ini('../app/config/configuration.ini');
    //Register an autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(array('../app/controllers/', '../app/models/', '../app/forms/', '../app/views/', '../app/plugins/', '../app/wrappers/'));
    $loader->registerNamespaces(array('Silar\\Misc' => '../app/misc/'), true);
    $loader->register();
    //Create a DI
    $di = new Phalcon\DI\FactoryDefault();
    //Registering Volt as template engine
    $di->set('view', function () {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views/');
        $view->registerEngines(array(".volt" => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
        return $view;
    });
    //Setup a base URI so that all generated URIs include the "tutorial" folder
    $di->set('url', function () {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/silar/');
        return $url;
    });
    $di->setShared('session', function () {
        $session = new Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });
    $di->set('router', function () {
        $router = new \Phalcon\Mvc\Router\Annotations();
Пример #26
0
<?php

use Phalcon\DI\FactoryDefault\CLI as CliDI, Phalcon\CLI\Console as ConsoleApp;
define('VERSION', '1.0.0');
// Using the CLI factory default services container
$di = new CliDI();
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__)));
/**
 * Register the autoloader and tell it to register the tasks directory
 */
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(APPLICATION_PATH . '/tasks', APPLICATION_PATH . '/models', APPLICATION_PATH . '/classes'));
$loader->register();
// Load the configuration file (if any)
if (is_readable(APPLICATION_PATH . '/config/config.php')) {
    $config = (include APPLICATION_PATH . '/config/config.php');
    $di->set('config', $config);
}
// Create a console application
$console = new ConsoleApp();
$console->setDI($di);
//Setup the database service
$di->set('db', function () use($config) {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
});
/**
 * Process the console arguments
 */
$arguments = array();
foreach ($argv as $k => $arg) {
Пример #27
0
 /**
  * Execute Phalcon Developer Tools
  *
  * @param  string             $path The path to the Phalcon Developer Tools
  * @param  string             $ip   Optional IP address for securing Developer Tools
  * @return void
  * @throws \Exception         if Phalcon extension is not installed
  * @throws \Exception         if Phalcon version is not compatible Developer Tools
  * @throws \Phalcon\Exception if Application config could not be loaded
  */
 public static function main($path, $ip = null)
 {
     if (!extension_loaded('phalcon')) {
         throw new \Exception('Phalcon extension is not installed, follow these instructions to install it: http://phalconphp.com/documentation/install');
     }
     if ($ip !== null) {
         self::$ip = $ip;
     }
     if (!defined('TEMPLATE_PATH')) {
         define('TEMPLATE_PATH', $path . '/templates');
     }
     chdir('..');
     // Read configuration
     $configPaths = array('config', 'app/config', 'apps/frontend/config');
     $readed = false;
     foreach ($configPaths as $configPath) {
         $cpath = $configPath . '/config.ini';
         if (file_exists($cpath)) {
             $config = new \Phalcon\Config\Adapter\Ini($cpath);
             $readed = true;
             break;
         } else {
             $cpath = $configPath . '/config.php';
             if (file_exists($cpath)) {
                 $config = (require $cpath);
                 $readed = true;
                 break;
             }
         }
     }
     if ($readed === false) {
         throw new \Phalcon\Exception('Configuration file could not be loaded!');
     }
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array($path . '/scripts/', $path . '/scripts/Phalcon/Web/Tools/controllers/'));
     $loader->registerNamespaces(array('Phalcon' => $path . '/scripts/'));
     $loader->register();
     if (Version::getId() < Script::COMPATIBLE_VERSION) {
         throw new \Exception('Your Phalcon version is not compatible with Developer Tools, download the latest at: http://phalconphp.com/download');
     }
     try {
         $di = new FactoryDefault();
         $di->set('view', function () use($path) {
             $view = new View();
             $view->setViewsDir($path . '/scripts/Phalcon/Web/Tools/views/');
             return $view;
         });
         $di->set('config', $config);
         $di->set('url', function () use($config) {
             $url = new \Phalcon\Mvc\Url();
             $url->setBaseUri($config->application->baseUri);
             return $url;
         });
         $di->set('flash', function () {
             return new \Phalcon\Flash\Direct(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
         });
         $di->set('db', function () use($config) {
             if (isset($config->database->adapter)) {
                 $adapter = $config->database->adapter;
             } else {
                 $adapter = 'Mysql';
             }
             if (is_object($config->database)) {
                 $configArray = $config->database->toArray();
             } else {
                 $configArray = $config->database;
             }
             $className = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
             unset($configArray['adapter']);
             return new $className($configArray);
         });
         self::$di = $di;
         $app = new \Phalcon\Mvc\Application();
         $app->setDi($di);
         echo $app->handle()->getContent();
     } catch (\Phalcon\Exception $e) {
         echo get_class($e), ': ', $e->getMessage(), "<br>";
         echo nl2br($e->getTraceAsString());
     } catch (\PDOException $e) {
         echo get_class($e), ': ', $e->getMessage(), "<br>";
         echo nl2br($e->getTraceAsString());
     }
 }
Пример #28
0
<?php

/**
 * Created by PhpStorm.
 * User: ashmjn
 * Date: 19/09/2015
 * Time: 6:30 PM
 */
$loader = new \Phalcon\Loader();
/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(array(APP_PATH . $config->application->controllersDir, APP_PATH . $config->application->pluginsDir, APP_PATH . $config->application->libraryDir, APP_PATH . $config->application->modelsDir, APP_PATH . $config->application->formsDir))->register();
Пример #29
0
<?php

try {
    // Регистрация автозагрузчика
    $loader = new Phalcon\Loader();
    $loader->registerDirs(array('../app/controllers/', '../app/models/'))->register();
    // Создание DI
    $di = new Phalcon\DI\FactoryDefault();
    // Настраиваем сервис для работы с БД
    $di->set('db', function () {
        return new Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "root", "dbname" => "phalcon"));
    });
    // Настраиваем компонент View
    $di->set('view', function () {
        $view = new Phalcon\Mvc\View();
        $view->setViewsDir('../app/views/');
        return $view;
    });
    // Обработка запроса
    $application = new Phalcon\Mvc\Application($di);
    echo $application->handle()->getContent();
} catch (Phalcon\Exception $e) {
    echo "PhalconException: ", $e->getMessage();
}
Пример #30
-1
 protected function _registerServices()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array(FOLDER_PROJECT . '/apps/library/', FOLDER_PROJECT . '/apps/backend/models', FOLDER_PROJECT . '/apps/frontend/models'))->register();
     //usando autoloader do composer para carregar as depêndencias instaladas via composer
     require_once FOLDER_PROJECT . 'vendor/autoload.php';
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add('/:controller/:action', array('module' => 'backend', 'controller' => 1, 'action' => 2));
         $router->add("/admin", array('module' => 'backend', 'controller' => 'index', 'action' => 'index'));
         $router->add("/editor", array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
         $router->add("/index/:action", array('controller' => 'index', 'action' => 1));
         return $router;
     });
     $di->set("libMail", function () {
         return new Multiple\Library\Mail();
     });
     /**
      * Caso exista o arquivo de configuração config.ini coleta os dados existentes nele e
      * conecta com o banco de dados
      */
     if (file_exists('../apps/config/config.ini')) {
         $config = new \Phalcon\Config\Adapter\Ini('../apps/config/config.ini');
         //Seta a conexão com o banco de dados
         $di->set('db', function () use($config) {
             $dbclass = 'Phalcon\\Db\\Adapter\\Pdo\\' . $config->database->adapter;
             return new $dbclass(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, "charset" => 'utf8'));
         });
     }
     $this->setDI($di);
 }