Ejemplo n.º 1
0
$di = new \Phalcon\DI\FactoryDefault();
$di->set('view', function () {
    $view = new View();
    $view->setViewsDir('../app/views/');
    return $view;
});
$di->set('annotations', function () {
    return new \Phalcon\Annotations\Adapter\Memory();
});
$di->set('router', function () {
    $router = new \Phalcon\Mvc\Router\Annotations(false);
    $router->removeExtraSlashes(true);
    $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
    $router->addResource('Index', "/");
    $router->addResource('User', "/user");
    $router->addResource('OAuth', "/auth");
    $router->notFound(["controller" => "index", "action" => "page404"]);
    return $router;
});
$di->set('mongo', function () {
    $mongo = new MongoClient('mongodb://mongodb:27017');
    return $mongo->selectDB("socwiz");
}, true);
$di->set('collectionManager', function () {
    return new Phalcon\Mvc\Collection\Manager();
}, true);
$di->set('url', function () {
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri('/api/v1/');
    return $url;
});
Ejemplo n.º 2
0
<?php

use Phalcon\Mvc\Router\Annotations as RouterAnnotations;
use Phalcon\Mvc\Router;
$router = new RouterAnnotations(false);
$router->notFound(["controller" => "Error", "action" => "error404"]);
$router->add("/setlang/{lang}", array("controller" => "Manager", "action" => "setlanguage"));
$router->add("/error404", array("controller" => "Error", "action" => "error404"))->setName("error404");
$router->addResource('Apartment', '/apartment');
$router->addResource('Tower', '/tower');
$router->addResource('Login', '/login');
$router->addResource('Country', '/country');
$router->addResource('State', '/state');
$router->addResource('City', '/city');
$router->addResource('Township', '/township');
$router->addResource('Neighborhood', '/neighborhood');
$router->addResource('Index', '/index');
$router->addResource('Test', '/test');
$router->addResource('Address', '/address');
$router->addResource('Error', '/error');
$router->addResource('User', '/user');
$router->addResource('Role', '/role');
$router->addResource('Action', '/action');
$router->addResource('UserRole', '/userrole');
$router->addResource('ActionRole', '/actionrole');
$router->addResource('Language', '/language');
$router->addResource('Translation', '/translation');
$router->addResource('Address', '/address');
$router->addResource('File', '/file');
$router->addResource('Gallery', '/gallery');
$router->addResource('SystemParameter', '/systemparameter');
Ejemplo n.º 3
0
 public function boot(Container $container)
 {
     // Pails 不使用Phalcon的Module功能,通过Namespace组织Controllers.
     // 如果出现多级,比如AdminApi,则一定要以Namespace的形式组织 Admin\Api\xxxxController
     //
     // Note: from phalcon 3, closure bind di as $this by default. so no use($app) needed.
     //
     $container->setShared('router', function () {
         //
         $router = new Annotations(false);
         $router->removeExtraSlashes(true);
         $router->setEventsManager($this->get('eventsManager'));
         $router->setDefaultNamespace('App\\Controllers');
         $router->setDefaultController('application');
         $router->setDefaultAction('index');
         // Process /config/routes.php
         // Verb	        Path	            Action	Route Name
         // GET	        /photo	            index	photo.index
         // GET	        /photo/create	    create	photo.create
         // POST	        /photo	            store	photo.store
         // GET	        /photo/{photo}	    show	photo.show
         // GET	        /photo/{photo}/edit	edit	photo.edit
         // PUT/PATCH	/photo/{photo}	    update	photo.update
         // DELETE	    /photo/{photo}	    destroy	photo.destroy
         foreach ($this->getConfig('routes') as $url => $route) {
             //                $resourceDefaults = ['index', 'create', 'store', 'show', 'edit', 'update', 'destroy'];
             //
             //                // a RESTful resource
             //                if (isset($route['resource'])) {
             //                    if (!isset($route[''])) {}
             //                    foreach ($this->getResourceMethods($defaults, $options) as $m) {
             //                        $this->{'addResource'.ucfirst($m)}($url, $route, $options);
             //                    }
             //                } else {
             //                    if (count($route) !== count($route, COUNT_RECURSIVE)) {
             //                        if (isset($route['pattern']) && isset($route['paths'])) {
             //                            $method = isset($route['httpMethods']) ? $route['httpMethods'] : null;
             //                            $router->add($route['pattern'], $route['paths'], $method);
             //                        } else {
             //                            throw new \RuntimeException(sprintf('No route pattern and paths found by route %s', $url));
             //                        }
             //                    } else {
             //                        $router->add($url, $route);
             //                    }
             //                }
         }
         // 定义注解路由
         $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->path('Controllers')), \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($iterator as $item) {
             if (Text::endsWith($item, "Controller.php", false)) {
                 $name = str_replace([$this->path('Controllers') . DIRECTORY_SEPARATOR, "Controller.php"], "", $item);
                 $name = str_replace(DIRECTORY_SEPARATOR, "\\", $name);
                 $router->addResource('App\\Controllers\\' . $name);
             }
         }
         // 定义404路由
         $router->notFound(["controller" => "application", "action" => "notfound"]);
         //
         return $router;
     });
 }