コード例 #1
0
ファイル: Module.php プロジェクト: noikiy/public
 /**
  * 注册服务
  * @param type $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     $config = \TConfig::instance()->getModule($this->moduleId);
     if (php_sapi_name() == 'cli') {
         //处理CLI模式
         $di['dispatcher'] = function () use($config) {
             $dispatcher = new \Phalcon\Cli\Dispatcher();
             if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['task'])) {
                 $dispatcher->setDefaultNamespace($config['defaultNamespace']);
             }
             return $dispatcher;
         };
     } else {
         //处理WEB模式
         $di['dispatcher'] = function () use($config) {
             $dispatcher = new \Phalcon\Mvc\Dispatcher();
             if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['controller'])) {
                 $dispatcher->setDefaultNamespace($config['defaultNamespace']['controller']);
             }
             return $dispatcher;
         };
         //添加视图
         $di->set('view', function () use($config) {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir($config['autoloadDir']['view']);
             $view->registerEngines(array('.html' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
             return $view;
         });
     }
 }
コード例 #2
0
ファイル: Module.php プロジェクト: nicklos17/littlemall
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "options" => array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'", \PDO::ATTR_CASE => \PDO::CASE_LOWER, \PDO::ATTR_EMULATE_PREPARES => false)));
     };
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Mall\\Admin\\Controllers");
         return $dispatcher;
     });
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
 }
コード例 #3
0
ファイル: Module.php プロジェクト: quyquoc/rmt-studio.com
 public function registerServices($di)
 {
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Frontend\\Controllers");
         return $dispatcher;
     };
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
     /**
      * Register a component
      */
     $di->set('menu', function () {
         return new \Modules\Frontend\Elements\Menu();
     });
     $di->set('element', function () {
         return new \Modules\Frontend\Elements\Element();
     });
 }
コード例 #4
0
ファイル: Module.php プロジェクト: cengizcoskun/phonebook
 /**
  * Register specific services for the module
  *
  * @package     base-app
  * @version     2.0
  *
  * @param object $di dependency Injector
  *
  * @return void
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         //Create/Get an EventManager
         $eventsManager = new \Phalcon\Events\Manager();
         //Attach a listener
         $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(array('controller' => 'index', 'action' => 'notFound'));
                         return false;
                 }
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         //Set default namespace to documentation module
         $dispatcher->setDefaultNamespace("Baseapp\\Documentation\\Controllers");
         //Bind the EventsManager to the dispatcher
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     //Registering the view component
     $di->set('view', function () use($di) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di));
         return $view;
     });
 }
コード例 #5
0
 public function registerServices($di)
 {
     /** Read configuration */
     $config = (include __DIR__ . "/../configs/config.php");
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Admin\\Controllers");
         return $dispatcher;
     };
     /** Setting up the view component */
     $di['view'] = function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('../../common/layouts/');
         $view->setPartialsDir('../../common/partials/');
         return $view;
     };
     /** set config */
     $di->set('config', function () use($config) {
         return $config;
     }, true);
     /** Database connection is created based in the parameters defined in the configuration file */
     $di['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", "options" => array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")));
     };
 }
コード例 #6
0
ファイル: Module.php プロジェクト: abuelezz/mvc
 public function registerServices($di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Frontend\\Controllers");
         return $dispatcher;
     };
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('../../common/layouts/');
         $view->setTemplateAfter('main');
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['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));
     };
 }
コード例 #7
0
ファイル: Module.php プロジェクト: einstein95/FAOpen
 /**
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices(\Phalcon\DiInterface $di = null)
 {
     // Set up MVC dispatcher.
     $controller_class = 'Modules\\' . $this->_module_class_name . '\\Controllers';
     $di['dispatcher'] = function () use($controller_class) {
         $eventsManager = new \Phalcon\Events\Manager();
         $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) {
             // Set odd/even pairs as the key and value of parameters, respectively.
             $keyParams = array();
             $params = $dispatcher->getParams();
             foreach ($params as $position => $value) {
                 if (is_int($position)) {
                     if ($position & 1) {
                         $keyParams[$params[$position - 1]] = urldecode($value);
                     }
                 } else {
                     // The "name" parameter is internal to routes.
                     if ($position != 'name') {
                         $keyParams[$position] = urldecode($value);
                     }
                 }
             }
             $dispatcher->setParams($keyParams);
             // Detect filename in controller and convert to "format" parameter.
             $controller_name = $dispatcher->getControllerName();
             if (strstr($controller_name, '.') !== false) {
                 list($controller_clean, $format) = explode('.', $controller_name, 2);
                 $dispatcher->setControllerName($controller_clean);
                 $dispatcher->setParam('format', $format);
             }
             // Detect filename in action and convert to "format" parameter.
             $action_name = $dispatcher->getActionName();
             if (strstr($action_name, '.') !== false) {
                 list($action_clean, $format) = explode('.', $action_name, 2);
                 $dispatcher->setActionName($action_clean);
                 $dispatcher->setParam('format', $format);
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace($controller_class);
         return $dispatcher;
     };
     // Set up module-specific configuration.
     $module_base_name = strtolower($this->_module_class_name);
     $module_config = $di->get('module_config');
     $di->setShared('current_module_config', function () use($module_base_name, $module_config) {
         if (isset($module_config[$module_base_name])) {
             return $module_config[$module_base_name];
         } else {
             return null;
         }
     });
     // Set up the view component and shared templates.
     $views_dir = 'modules/' . $module_base_name . '/views/scripts/';
     $di['view'] = function () use($views_dir) {
         return \FA\Phalcon\View::getView(array('views_dir' => $views_dir));
     };
 }
コード例 #8
0
ファイル: Module.php プロジェクト: NAMEs/phyar-framework
 /**
  * Register specific services for the module
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("App\\Modules\\User\\Controllers");
         return $dispatcher;
     });
 }
コード例 #9
0
 public function attachDispatcher()
 {
     $this->_di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace('PhalconCart\\Controllers\\Frontend');
         return $dispatcher;
     });
     return $this;
 }
コード例 #10
0
ファイル: Module.php プロジェクト: luoshulin/falcon
 /**
  *
  * Register the services here to make them module-specific
  *
  */
 public function registerServices($di)
 {
     // get bootstrap obj
     $bootstrap = $di->get('bootstrap');
     // get config class name
     $confClass = $bootstrap->getConfClass();
     // module config
     $mConfPath = __DIR__ . '/confs/' . PHALCON_ENV . '.' . PHALCON_CONF_TYPE;
     if (!is_file($mConfPath)) {
         throw new \Phalcon\Config\Exception("Module config file not exist, file position: {$mConfPath}");
     }
     if (PHALCON_CONF_TYPE == 'ini') {
         $mConfig = new $confClass($mConfPath);
     } else {
         if (PHALCON_CONF_TYPE == 'php') {
             $mConfig = new $confClass(require_once $mConfPath);
         }
     }
     // global config
     $gConfig = $di->get('config');
     // merge module config and global config, module's will override global's
     $gConfig->merge($mConfig);
     // set config back
     $di->set('config', $gConfig);
     // registering a dispatcher
     $di->set('dispatcher', function () use($di) {
         $evtManager = $di->getShared('eventsManager');
         $evtManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(array('module' => 'sample', 'controller' => 'error', 'action' => 'show404'));
                     return false;
             }
         });
         $acl = new \BullSoft\Sample\Plugins\Acl($di, $evtManager);
         $evtManager->attach('dispatch', $acl);
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($evtManager);
         $dispatcher->setDefaultNamespace("BullSoft\\Sample\\Controllers\\");
         return $dispatcher;
     });
     // set view with volt
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array(".volt" => function ($view, $di) {
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array("compiledPath" => $di->get('config')->view->compiledPath, "compiledExtension" => $di->get('config')->view->compiledExtension, "compileAlways" => (bool) $di->get('config')->application->debug));
             $compiler = $volt->getCompiler();
             $compiler->addExtension(new \BullSoft\Volt\Extension\PhpFunction());
             return $volt;
         }));
         return $view;
     });
 }
コード例 #11
0
ファイル: Module.php プロジェクト: xsat/www.mail.com
 public function registerServices(\Phalcon\DiInterface $di)
 {
     $this->di = $di;
     $this->di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace($this->prefix . '\\Controllers');
         return $dispatcher;
     });
     $this->di->set('view', $this->setView(), true);
     $this->di->set('modelsMetadata', $this->setModelsMetadata());
 }
コード例 #12
0
ファイル: Module.php プロジェクト: boiler256/mvc
 /**
  * Register the services here to make them module-specific
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Multiple\\Frontend\\Controllers\\");
         return $dispatcher;
     });
     $di->set('db', function () {
         return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "secret", "dbname" => "invo"));
     });
 }
コード例 #13
0
ファイル: Module.php プロジェクト: sharkodlak/pinek
 public function registerServices(\Phalcon\DiInterface $di)
 {
     // Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace('Bishop\\Shop\\Controllers');
         return $dispatcher;
     });
     // Registering the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(ROOT_DIR . '/app/shop/views/');
         return $view;
     });
 }
コード例 #14
0
ファイル: Module.php プロジェクト: quyquoc/rmt-studio.com
 public function registerServices($di)
 {
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Backend\\Controllers");
         return $dispatcher;
     };
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
 }
コード例 #15
0
ファイル: Module.php プロジェクト: viniciusilveira/pluton
 /**
  * Registra os serviços específicos para este módulo
  */
 public function registerServices($di)
 {
     //Registra o dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $eventManager = new \Phalcon\Events\Manager();
         $eventManager->attach('dispatch', new \Acl('backend'));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers\\");
         return $dispatcher;
     });
     //Registra os diretórios das views
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/backend/views/');
         return $view;
     });
 }
コード例 #16
0
ファイル: Module.php プロジェクト: nicklos17/appserver
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     /**
      * Read configuration
      */
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Appserver\\v2\\Controllers");
         return $dispatcher;
     });
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
 }
コード例 #17
0
ファイル: Module.php プロジェクト: viniciusilveira/pluton
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         //Attach a event listener to the dispatcher
         $eventManager = new \Phalcon\Events\Manager();
         $eventManager->attach('dispatch', new \Acl('frontend'));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace("Multiple\\Frontend\\Controllers\\");
         return $dispatcher;
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/frontend/views/');
         return $view;
     });
 }
コード例 #18
0
 private static function cgiRegister()
 {
     $di = get_app_di();
     $config = self::getConfig();
     self::registCommonService($di, $config);
     $di->setShared('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->removeExtraSlashes(true);
         $router->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
         return $router;
     });
     $di->setShared('dispatcher', function () {
         $eventsManager = new \Phalcon\Events\Manager();
         $eventsManager->attach('dispatch:beforeException', new NotFoundPlugin());
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace("App\\Controllers\\");
         return $dispatcher;
     });
     $di->setShared('view', function () use($config) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir($config->view->templatePath);
         $view->registerEngines(array('.html' => function ($view, $di) {
             $config = $di->get('config');
             $compiledPath = $config->view->compiledPath;
             if (!file_exists($compiledPath)) {
                 mkdir($compiledPath, 0744, true);
             }
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array('compiledPath' => $compiledPath, 'compiledExtension' => $config->view->compiledExtension, 'compileAlways' => isset($config->view->compileAlways) ?: false));
             $compiler = $volt->getCompiler();
             $compiler->addExtension(new VoltExtension());
             $autoEscape = isset($config->view->autoEscape) ?: true;
             ClassUtil::modifyPrivateProperties($compiler, array('_autoescape' => $autoEscape));
             return $volt;
         }));
         return $view;
     });
     $di->setShared('elements', function () {
         return new ElementsPlugin();
     });
 }
コード例 #19
0
ファイル: Module.php プロジェクト: ariborneo/phalcon-restful
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices($di)
 {
     $config = (include __DIR__ . "/../../config/constants.php");
     //Redefining Dispatcher
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("App\\Modules\\Frontend\\Controllers");
         return $dispatcher;
     };
     //Setting UP View component
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
     //Databse Connection
     $di['db'] = function () use($config) {
         return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')));
     };
 }
コード例 #20
0
ファイル: index.php プロジェクト: abuelezz/mvc
 /**
  * This methods registers the services to be used by the application
  */
 protected function _registerServices()
 {
     $di = new \Phalcon\DI();
     //Registering a router
     $di->set('router', function () {
         return new \Phalcon\Mvc\Router();
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace('Single\\Controllers\\');
         return $dispatcher;
     });
     //Registering a Http\Response
     $di->set('response', function () {
         return new \Phalcon\Http\Response();
     });
     //Registering a Http\Request
     $di->set('request', function () {
         return new \Phalcon\Http\Request();
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/views/');
         return $view;
     });
     $di->set('db', function () {
         return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "", "dbname" => "invo"));
     });
     //Registering the Models-Metadata
     $di->set('modelsMetadata', function () {
         return new \Phalcon\Mvc\Model\Metadata\Memory();
     });
     //Registering the Models Manager
     $di->set('modelsManager', function () {
         return new \Phalcon\Mvc\Model\Manager();
     });
     $this->setDI($di);
 }
コード例 #21
0
ファイル: BaseModule.php プロジェクト: Riu/kirocms
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     $config = $di->get('config');
     $di->set('dispatcher', function () use($di) {
         $eventsManager = $di->getShared('eventsManager');
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace($this->namespace . '\\Controllers\\');
         return $dispatcher;
     });
     if (file_exists('../' . $config->app->apps . $this->moduleName . '/config/routers.ini')) {
         $router = $di->get('router');
         $routers = new \Phalcon\Config\Adapter\Ini('../' . $config->app->apps . $this->moduleName . '/config/routers.ini');
         if (!empty($routers)) {
             foreach ($routers as $name => $rule) {
                 $rule->module = $this->moduleName;
                 $pattern = $rule->pattern;
                 unset($rule->pattern);
                 $router->add($pattern, $rule->toArray())->setName($name);
             }
         }
         $router->handle();
     }
     $di->set('view', function () use($config) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../' . $config->app->apps . $this->moduleName . '/' . $config->app->views);
         $view->registerEngines(array('.html' => function ($view, $di) use($config) {
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array('compiledPath' => '../' . $config->app->apps . $this->moduleName . '/cache/volt/', 'compiledExtension' => '.php', 'compileAlways' => true, 'compiledSeparator' => '_'));
             return $volt;
         }));
         return $view;
     });
     $di->set('flashSession', function () {
         return new \Phalcon\Flash\Session(array('error' => 'alert alert-warning alert-small', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
     });
     $di->set('flash', function () {
         return new \Phalcon\Flash\Direct(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
     });
 }
コード例 #22
0
 /**
  * Register specific services for the module
  */
 public function registerServices(\Phalcon\DiInterface $dependencyInjector)
 {
     /**
      * Read configuration
      */
     $config = (require_once MODULES_DIR . $this->module_name . DS . "config" . DS . "config.php");
     //Registering a dispatcher
     $dependencyInjector->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         //Attach a event listener to the dispatcher
         $eventManager = new \Phalcon\Events\Manager();
         //$eventManager->attach('dispatch', new \Acl($this->module_name));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace("Mod\\ModMan\\Controllers\\");
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $dependencyInjector->set('view', function () use($config) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir($config->module->viewsDir);
         $view->setViewsDir(MODULES_DIR . $this->module_name . DS . 'views' . DS);
         $view->setLayoutsDir(MODULES_DIR . $this->module_name . DS . 'layouts' . DS);
         //$view->setTemplateAfter('index');
         $view->registerEngines(array('.volt' => function ($view, $di) {
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array('compiledPath' => MODULES_DIR . $this->module_name . DS . 'views' . DS . '_compiled' . DS, 'stat' => true, 'compileAlways' => true));
             return $volt;
         }));
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      * http://stackoverflow.com/questions/22197678/how-to-connect-multiple-database-in-phalcon-framework
      */
     $dependencyInjector->set('db', function () use($config) {
         return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
     });
 }
コード例 #23
0
ファイル: Module.php プロジェクト: abuelezz/mvc
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         //Attach a event listener to the dispatcher
         $eventManager = new \Phalcon\Events\Manager();
         $eventManager->attach('dispatch', new \Acl('frontend'));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace("Multiple\\Frontend\\Controllers\\");
         return $dispatcher;
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/frontend/views/');
         return $view;
     });
     $di->set('db', function () {
         return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "secret", "dbname" => "invo"));
     });
 }
コード例 #24
0
ファイル: index.php プロジェクト: chyro/Lifestyle
 //Create a DI
 $config["di"] = new \Phalcon\DI\FactoryDefault();
 $config["di"]->set('session', function () {
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
     return $session;
 });
 //Setup the view component
 $config["di"]->set('view', function () use($config) {
     $view = new \Phalcon\Mvc\View();
     $view->setViewsDir(BASE_DIR . '/' . $config->application->viewsDir);
     return $view;
 });
 $config["di"]->set('dispatcher', function () {
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     $dispatcher->setDefaultNamespace('Watchlist\\Controllers');
     return $dispatcher;
 });
 //Setup the flash service
 $config["di"]->set('flash', function () {
     return new \Phalcon\Flash\Direct();
 });
 //Route Settings
 include "../app/config/routes.php";
 //DB Settings
 $config["di"]->set('mongo', function () use($config) {
     $mongo = new MongoClient();
     return $mongo->selectDB($config->database->name);
 }, true);
 $config["di"]->set('collectionManager', function () {
     return new \Phalcon\Mvc\Collection\Manager();
コード例 #25
0
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use Phalcon\Session\Adapter\Files as SessionAdapter;
/**
 * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
 */
$di = new FactoryDefault();
/**
 * Register config
 */
$di->setShared('config', $config);
/**
 * Registering a dispatcher
 */
$di->set('dispatcher', function () {
    $dispatcher = new \Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace('Tools\\Controllers');
    return $dispatcher;
});
/**
 * Register routers
 */
$di->setShared('router', function () use($config) {
    $router = new \Phalcon\Mvc\Router();
    $router->removeExtraSlashes(true);
    $router->setDefaults(array('namespace' => 'Tools\\Controllers', 'controller' => 'index', 'action' => 'index'));
    $router->add('/:controller/:action/:params', array('namespace' => 'Tools\\Controllers', 'controller' => 1, 'action' => 2, 'params' => 3));
    return $router;
});
/**
 *  Register assets that will be loaded in every page
 */
コード例 #26
0
 public function testIssues2270()
 {
     Phalcon\DI::reset();
     $di = new \Phalcon\DI();
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     $dispatcher->setDI($di);
     $dispatcher->setDefaultNamespace('A\\B\\C');
     $dispatcher->setControllerName('Test');
     $dispatcher->setActionName('index');
     $this->assertEquals('A\\B\\C\\TestController', $dispatcher->getHandlerClass());
 }
コード例 #27
0
$di->setShared('modelsMetadata', function () {
    return new MetaDataAdapter();
});
/**
 * Register the session flash service with the Twitter Bootstrap classes
 */
$di->set('flash', function () {
    return new Flash(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
});
/**
 * Start the session the first time some component request the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
/**
 * Set namespace
 */
$di->set('dispatcher', function () {
    $dispatcher = new Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace(ucfirst(BASE_NAME) . '\\Controllers');
    return $dispatcher;
});
/**
 * Custom tag
 */
$di->set('tag', function () use($config) {
    return new Tag();
}, true);
コード例 #28
0
ファイル: services.php プロジェクト: xw716825/work
    $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
    return new $class($dbConfig);
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->setShared('modelsMetadata', function () {
    return new MetaDataAdapter();
});
/**
 * Starts the session the first time some component requests the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
/**
 * Register the session flash service with the Twitter Bootstrap classes
 */
$di->set('flash', function () {
    return new Flash(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning'));
});
/**
* Set the default namespace for dispatcher
*/
$di->setShared('dispatcher', function () use($di) {
    $dispatcher = new Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace('@@namespace@@\\Frontend\\Controllers');
    return $dispatcher;
});
コード例 #29
0
ファイル: services.php プロジェクト: kavalanche/test
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->setShared('db', function () use($config) {
    $dbConfig = $config->database->toArray();
    $adapter = $dbConfig['adapter'];
    unset($dbConfig['adapter']);
    $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
    return new $class($dbConfig);
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->setShared('modelsMetadata', function () {
    return new MetaDataAdapter();
});
/**
 * Starts the session the first time some component requests the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
/**
* Set the default namespace for dispatcher
*/
$di->setShared('dispatcher', function () use($di) {
    $dispatcher = new Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace('Test\\Frontend\\Controller');
    return $dispatcher;
});
コード例 #30
0
ファイル: services.php プロジェクト: Oscailte/phlame
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->setShared('db', function () use($config) {
    $dbConfig = $config->database->toArray();
    $adapter = $dbConfig['adapter'];
    unset($dbConfig['adapter']);
    $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
    return new $class($dbConfig);
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->setShared('modelsMetadata', function () {
    return new MetaDataAdapter();
});
/**
 * Starts the session the first time some component requests the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
/**
* Set the default namespace for dispatcher
*/
$di->setShared('dispatcher', function () use($di) {
    $dispatcher = new Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace('Phlame\\Core\\Controllers');
    return $dispatcher;
});