Beispiel #1
0
$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
 */
$di->setShared('assets', function () {
    $assets = new \Phalcon\Assets\Manager();
    $assets->collection('header-js')->addJs('js/jquery-1.11.3.min.js')->addJs('js/jquery-ui.min.js')->addJs('js/bootstrap.min.js')->addJs('js/mg.js');
    $assets->collection('header-css')->addCss('css/jquery-ui.min.css')->addCss('css/bootstrap.min.css')->addCss('css/style.css');
    return $assets;
});
/**
 * Register the flash service with custom CSS classes
 */
Beispiel #2
0
/**
 * Start the session the first time some component request the session service
 */
$di->set('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
/**
 * Register configurations
 */
$di->set('config', function () use($config) {
    return $config;
});
/**
 * Register router
 */
$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router();
    $router->removeExtraSlashes(true);
    $router->setDefaults(['controller' => 'index', 'action' => 'index']);
    /*$router->notFound([
          'controller'    => 'errors',
          'action'        => 'pageNotFound'
      ]);*/
    $router->addGet('/project/{profile:([a-zA-Z0-9-(.)]+)}', ['action' => 'profile', 'project' => 1]);
    $router->addPost('/filter', ['action' => 'filter'])->beforeMatch(function ($uri, $route) {
        return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
    });
    return $router;
});
<?php

$router = new Phalcon\Mvc\Router(false);
$router->removeExtraSlashes(true);
$router->setDefaults(array('controller' => 'apireference', 'action' => 'index'));
$router->add('/error/404', array('controller' => 'error', 'action' => '_404'))->setName('404');
$router->notFound($router->getRouteByName('404')->getPaths());
// this only need to get URL to class reference by route name
$router->add('/{language:[A-Za-z]{2,2}}/{version:((\\d+\\.\\d+\\.\\d+)|latest)}/{class:(?i)phalcon(/[\\w/]+)?}', array('controller' => 'apireference', 'action' => 'showClass'))->setName('showClass');
// this only need to get URL by route name
$router->add('/{language:[A-Za-z]{2,2}}/{version:((\\d+\\.\\d+\\.\\d+)|latest)}/{type:(classes|namespaces|interfaces|changelog)}', array('controller' => 'apireference', 'action' => 'index'))->setName('showSummary');
$router->add('/?([A-Za-z]{2,2})?(/((\\d+\\.\\d+\\.\\d+)|latest))?(/(classes|namespaces|interfaces|changelog))?', array('controller' => 'apireference', 'action' => 'index', 'language' => 1, 'version' => 3, 'summary' => 6))->convert('language', function ($param) {
    return $param === 1 || !$param ? null : strtolower($param);
})->convert('version', function ($param) {
    return $param === 3 || !$param ? null : $param;
})->convert('summary', function ($param) {
    return $param === 6 || !$param ? 'classes' : $param;
});
$router->add('(/([A-Za-z]{2,2}))?(/((\\d+\\.\\d+\\.\\d+)|latest))?/((?i)phalcon(/[\\w/]+)?)', array('controller' => 'apireference', 'action' => 'showClass', 'language' => 2, 'version' => 4, 'class' => 6))->convert('language', function ($param) {
    return $param === 2 || !$param ? null : strtolower($param);
})->convert('version', function ($param) {
    return $param === 4 || !$param ? null : $param;
})->convert('class', function ($param) {
    return $param === 6 || !$param ? null : str_replace('/', '\\', strtolower($param));
});
return $router;
Beispiel #4
0
if (SERVER == 'dev' && isset($_GET['refreshAll'])) {
    Host\Object\ExtenderCore::SyncProjectFolder();
}
////////////////////////////
//  VIEW SETUP
$viewDirArray = array();
////////////////////////////
//  ROOT
$di->set('url', function () {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri('/');
    return $url;
});
////////////////////////////
//  ROUTER
$router->setDefaults(array('controller' => 'index', 'action' => 'index', 'namespace' => 'Host\\Controller'));
$router->add("/extender", array('controller' => 'extender', 'action' => 'index', 'path' => $_GET['path'], 'namespace' => 'Host\\Controller'));
$router->add("/extender/extend", array('controller' => 'extender', 'action' => 'index', 'path' => $_GET['path'], 'namespace' => 'Host\\Controller'));
$router->notFound(array('controller' => 'index', 'action' => 'notFound', 'namespace' => 'Host\\Controller'));
////////////////////////////
//  BIND VIEW
Twig_Autoloader::register();
$di['twigService'] = function ($view, $di) {
    Phalcon\Mvc\View\Engine\Twig::setOptions(array('debug' => true, 'charset' => 'UTF-8', 'base_template_class' => 'Twig_Template', 'strict_variables' => false, 'autoescape' => false, 'cache' => __DIR__ . '/../../cache/twig/', 'auto_reload' => null, 'optimizations' => -1));
    $twig = new View($view, $di);
    return $twig;
};
$di->set('twigService', function ($view, $di) use($config) {
    //  create twig object
    $option = array('cache' => '../cache/');
    $arrFolder = array('../views/');
Beispiel #5
0
    $session = new SessionAdapter();
    session_name('sessionIGO');
    $session->start();
    return $session;
});
/**
* Ajout du routing pour le navigateur construit, en utilisant les paramètres REST plutot que KVP.
*/
$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router();
    //Define a route
    $router->add("/contexte/{contexte}", array("controller" => "igo", "action" => "contexte", "contexteid" => 1));
    $router->add("/configuration/{configuration}", array("controller" => "igo", "action" => "configuration", "configuration" => 1));
    $router->add("/couche/{coucheId}", array("controller" => "igo", "action" => "couche", "coucheid" => 1));
    $router->add("/groupe/{groupeId}", array("controller" => "igo", "action" => "groupe", "coucheid" => 1));
    $router->setDefaults(array('controller' => 'index', 'action' => 'index'));
    return $router;
});
if (isset($config->application->authentification->module)) {
    $authentificationModule = new $config->application->authentification->module();
    if ($authentificationModule instanceof AuthentificationController) {
        $di->set("authentificationModule", $authentificationModule);
    } else {
        error_log("Le module d'authentificaiton n'est pas une instance d'AuthentificationController");
    }
} else {
    $di->set("authentificationModule", 'AuthentificationTest');
}
class igoView extends Phalcon\Mvc\View
{
    public $config = null;
Beispiel #6
0
 /**
  * 开始刷新任务
  *
  * @param   \Phalcon\DI\FactoryDefault  $di     Phalcon的DI类
  */
 private function handleTaskRefresh(&$di)
 {
     $router = new \Phalcon\Mvc\Router();
     $router->setDefaults(["namespace" => 'App\\Task', "controller" => 'Task', "action" => 'kernel']);
     $di->set('router', $router);
     $di->set('url', function () {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri(QP_ROOT_PATH);
         return $url;
     });
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(QP_VIEW_PATH);
         return $view;
     });
     Task\BaseTask::flushTask();
     Task\BaseTask::initData();
     (new \Phalcon\Mvc\Application($di))->handle();
     Task\BaseTask::handleTaskRefresh();
 }
Beispiel #7
0
     $transport->setUsername($hostInfo['username']);
     $transport->setPassword($hostInfo['password']);
     return Swift_Mailer::newInstance($transport);
 };
 //end nnluc073
 $di['router'] = function () {
     $router = new \Phalcon\Mvc\Router(true);
     ///////////// FONTEND ///////////////
     $router->add('/:params', array('module' => 'frontend', 'controller' => 'index', 'action' => 'index', "params" => 1));
     $router->add('/:controller/:params', array('module' => 'frontend', 'controller' => 1, 'action' => 'index', "params" => 2));
     $router->add('/:controller/:action/:params', array('module' => 'frontend', 'controller' => 1, 'action' => 2, "params" => 3));
     ///////////// BACKEND ///////////////
     $router->add('/admin/:params', array('module' => 'backend', 'controller' => 'index', 'action' => 'index', "params" => 1));
     $router->add('/admin/:controller/:params', array('module' => 'backend', 'controller' => 1, 'action' => 'index', "params" => 2));
     $router->add('/admin/:controller/:action/:params', array('module' => 'backend', 'controller' => 1, 'action' => 2, "params" => 3));
     $router->setDefaults(array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
     return $router;
 };
 $di->set('url', function () {
     $url = new \Phalcon\Mvc\Url();
     $url->setBaseUri('/');
     return $url;
 });
 $di->set('cookie', function () {
     $cookie = new \Phalcon\Http\Response\Cookies();
     $cookie->useEncryption(false);
     return $cookie;
 });
 $di->set('session', function () {
     $session = new \Phalcon\Session\Adapter\Files();
     $session->start();
Beispiel #8
0
<?php

$router = new Phalcon\Mvc\Router();
$router->setDefaults(['namespace' => 'Controller', 'controller' => 'index', 'action' => 'index']);
$router->add('/', ['controller' => 'index', 'action' => 'index'])->via(['POST', 'GET'])->setName('homepage');
return $router;
Beispiel #9
0
 /**
  * Set the static router service
  *
  * @package     las
  * @version     1.0
  *
  * @return void
  */
 protected function router()
 {
     $this->_di->set('router', function () {
         $router = new \Phalcon\Mvc\Router(false);
         $router->setDefaults(array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
         /*
          * All defined routes are traversed in reverse order until Phalcon\Mvc\Router
          * finds the one that matches the given URI and processes it, while ignoring the rest.
          */
         $frontend = new \Phalcon\Mvc\Router\Group(array('module' => 'frontend'));
         $frontend->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
         $frontend->add('/:controller/:int', array('controller' => 1, 'id' => 2));
         $frontend->add('/:controller[/]?', array('controller' => 1));
         $frontend->add('/{action:(buy|contact)}[/]?', array('controller' => 'static', 'action' => 'action'));
         $frontend->add('/');
         // Mount a group of routes for frontend
         $router->mount($frontend);
         /**
          * Define routes for each module
          */
         foreach (array('admin', 'doc') as $module) {
             $group = new \Phalcon\Mvc\Router\Group(array('module' => $module));
             $group->setPrefix('/' . $module);
             $group->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
             $group->add('/:controller/:int', array('controller' => 1, 'id' => 2));
             $group->add('/:controller[/]?', array('controller' => 1));
             $group->add('[/]?', array());
             // Mount a group of routes for some module
             $router->mount($group);
         }
         $router->notFound(array('controller' => 'index', 'action' => 'notFound'));
         return $router;
     });
 }
Beispiel #10
0
 /**
  * This methods registers the services to be used by the application
  */
 protected function _registerServices()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     // Registering a Config shared-service
     $di->setShared('config', function () {
         $config['main'] = (include ROOT_DIR . "/config/main.php");
         $config['db'] = (include ROOT_DIR . "/config/db.php");
         $config['router'] = (include ROOT_DIR . "/config/router.php");
         return new \Phalcon\Config($config);
     });
     $config = $di->get('config');
     // Change FactoryDefault default Router service
     $di->getService('router')->setDefinition(function () use($config) {
         $router = new \Phalcon\Mvc\Router();
         //Setup routes from /config/router.php
         foreach ($config->router->toArray() as $key => $value) {
             $router->add($key, $value);
         }
         // Mount each module routers
         $router->mount(new \App\Frontend\Router());
         $router->mount(new \App\Backend\Router());
         // URI_SOURCE_SERVER_REQUEST_URI
         $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
         // Remove trailing slashes automatically
         $router->removeExtraSlashes(true);
         // Setting a specific default using an array
         // DefaultModule
         // DefaultNamespace
         // DefaultController
         // DefaultAction
         $router->setDefaults(array('modul' => 'frontend', 'namespace' => 'App\\Frontend\\Controllers\\', 'controller' => 'index', 'action' => 'index'));
         // Set 404 paths
         $router->notFound(["controller" => "error", "action" => "error404"]);
         return $router;
     });
     // Registering a View shared-service
     $di->setShared('view', function () {
         return new \Phalcon\Mvc\View();
     });
     // Registering a Mysql shared-service
     $di->setShared('mysql', function () use($config) {
         return new \Phalcon\Db\Adapter\Pdo\Mysql($config->db->mysql->toArray());
     });
     // Registering a Db shared-service
     $di->setShared('db', function () use($di) {
         return $di->get('mysql');
     });
     // Registering a Url shared-service
     $di->setShared('url', function () {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri('/');
         return $url;
     });
     // Start the Session service
     $di->get('session')->start();
     // Setup the Crypt service
     $di->get('crypt')->setMode(MCRYPT_MODE_CFB)->setKey($config->main->crypt_key);
     // Setup the Security service
     $di->get('security')->setWorkFactor(12);
     // Registering a custom authentication shared-service
     $di->setShared('auth', function () {
         return new \App\Common\Libs\Auth();
     });
     $this->setDI($di);
 }
Beispiel #11
0
<?php

$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router(false);
    $router->removeExtraSlashes(true);
    $router->add("/", array("controller" => "Index", "action" => "index"));
    $router->setDefaults(array('controller' => 'Index', 'action' => 'error'));
    return $router;
});
Beispiel #12
0
 protected function router()
 {
     //Setting up the static router
     $this->_di->set('router', function () {
         $router = new \Phalcon\Mvc\Router(FALSE);
         $router->setDefaults(array('module' => 'home', 'controller' => 'Index', 'action' => 'index'));
         //前台
         $router->add('/', array('module' => 'home', 'controller' => 'Index', 'action' => 'index'));
         $router->add('/:controller[/]?', array('module' => 'home', 'controller' => 1, 'action' => 'index'));
         $router->add('/:controller/:action/:params', array('module' => 'home', 'controller' => 1, 'action' => 2, 'params' => 3));
         $router->add('/:int[/]?', array('module' => 'home', 'controller' => 'index', 'action' => 'index', 'node' => 1));
         $router->add('/:int/:controller[/]?', array('module' => 'home', 'controller' => 2, 'action' => 'index', 'node' => 1));
         $router->add('/:int/:controller/:action/:params', array('module' => 'home', 'controller' => 2, 'action' => 3, 'node' => 1, 'params' => 4));
         //后台
         $router->add('/admin[/]?', array('module' => 'admin', 'controller' => 'Index', 'action' => 'index'));
         $router->add('/admin/:controller[/]?', array('module' => 'admin', 'controller' => 1, 'action' => 'index'));
         $router->add('/admin/:controller/:action/:params', array('module' => 'admin', 'controller' => 1, 'action' => 2, 'params' => 3));
         $router->add('/:int/admin[/]?', array('module' => 'admin', 'controller' => 'Index', 'action' => 'index', 'node' => 1));
         $router->add('/:int/admin/:controller[/]?', array('module' => 'admin', 'controller' => 2, 'action' => 'index', 'node' => 1));
         $router->add('/:int/admin/:controller/:action/:params', array('module' => 'admin', 'controller' => 2, 'action' => 3, 'params' => 4, 'node' => 1));
         //任务
         $router->add('/backend[/]?', array('module' => 'backend', 'controller' => 'Index', 'action' => 'index'));
         $router->add('/backend/:controller[/]?', array('module' => 'backend', 'controller' => 1, 'action' => 'index'));
         $router->add('/backend/:controller/:action/:params', array('module' => 'backend', 'controller' => 1, 'action' => 2, 'params' => 3));
         $router->add('/:int/backend[/]?', array('module' => 'backend', 'controller' => 'Index', 'action' => 'index', 'node' => 1));
         $router->add('/:int/backend/:controller[/]?', array('module' => 'backend', 'controller' => 2, 'action' => 'index', 'node' => 1));
         $router->add('/:int/backend/:controller/:action/:params', array('module' => 'backend', 'controller' => 2, 'action' => 3, 'params' => 4, 'node' => 1));
         //404
         $router->notFound(array('controller' => 'index', 'action' => 'notFound'));
         return $router;
     });
 }