当前位置: 首页>>代码示例>>PHP>>正文


PHP Mvc\Url类代码示例

本文整理汇总了PHP中Phalcon\Mvc\Url的典型用法代码示例。如果您正苦于以下问题:PHP Url类的具体用法?PHP Url怎么用?PHP Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: registerServices

 /**
  * Registers the module-only services
  *
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices($di)
 {
     /**
      * Read application wide and module only configurations
      */
     $appConfig = $di->get('config');
     $moduleConfig = (include __DIR__ . '/config/config.php');
     $di->set('moduleConfig', $moduleConfig);
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($appConfig) {
         $url = new UrlResolver();
         $url->setBaseUri($appConfig->application->baseUri);
         return $url;
     });
     /**
      * Module specific dispatcher
      */
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($di->getShared('eventsManager'));
         $dispatcher->setDefaultNamespace('App\\Modules\\Oauth\\');
         return $dispatcher;
     });
     /**
      * Module specific database connection
      */
     $di->set('db', function () use($appConfig) {
         return new DbAdapter(['host' => $moduleConfig->database->host, 'username' => $moduleConfig->database->username, 'password' => $moduleConfig->database->password, 'dbname' => $moduleConfig->database->name]);
     });
 }
开发者ID:sarahsampan,项目名称:compare-api,代码行数:37,代码来源:Module.php

示例2: registerServices

 public function registerServices(DiInterface $di)
 {
     global $config;
     $di->setShared('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri($config->backend->baseUri);
         return $url;
     });
     $di->setShared('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers");
         return $dispatcher;
     });
     $di->setShared('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->backend->viewsDir);
         $view->setLayoutsDir('layouts/');
         $view->setPartialsDir('partials/');
         $view->registerEngines(array('.phtml' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->backend->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     });
 }
开发者ID:lnmtien,项目名称:phalcon-base,代码行数:26,代码来源:Module.php

示例3: setDi

function setDi()
{
    $di = new FactoryDefault();
    $di['router'] = function () use($di) {
        $router = new Router();
        $router->setDefaultModule('mobimall');
        return $router;
    };
    $di['url'] = function () {
        $url = new UrlResolver();
        $url->setBaseUri('/');
        return $url;
    };
    $di['session'] = function () {
        $session = new SessionAdapter();
        // $session->start();
        return $session;
    };
    $loader = new Loader();
    $loader->registerNamespaces(array('Mall\\Mdu' => __DIR__ . '/../apps/mdu'));
    $sysConfig = (include __DIR__ . '/../config/sysconfig.php');
    $di['sysconfig'] = function () use($sysConfig) {
        return $sysConfig;
    };
    $loader->register();
    return $di;
}
开发者ID:nicklos17,项目名称:littlemall,代码行数:27,代码来源:index.php

示例4: registerServices

 /**
  * Register the services here to make them general
  * or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(DiInterface $di)
 {
     //Read configuration
     $config = (include __DIR__ . "/config/config.php");
     // The URL component is used to generate all kind of urls in the application
     $di->set('url', function () use($config) {
         $url = new Url();
         $url->setBaseUri($config->application->baseUri);
         return $url;
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         //Create/Get an EventManager
         $eventsManager = new EventsManager();
         //Attach a listener
         $eventsManager->attach('dispatch', function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(['module' => 'backend', 'controller' => 'errors', 'action' => 'notFound']);
                         return false;
                 }
             }
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Phanbook\\Backend\\Controllers");
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->viewsDir);
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => 'volt']);
         // Create an event manager
         $eventsManager = new EventsManager();
         // Attach a listener for type 'view'
         $eventsManager->attach('view', function ($event, $view) {
             if ($event->getType() == 'notFoundView') {
                 throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')');
             }
         });
         // Bind the eventsManager to the view component
         $view->setEventsManager($eventsManager);
         return $view;
     });
     $configMenu = (include __DIR__ . "/config/config.menu.php");
     $di->setShared('menuStruct', function () use($configMenu) {
         // if structure received from db table instead getting from $config
         // we need to store it to cache for reducing db connections
         $struct = $configMenu->get('menuStruct')->toArray();
         return $struct;
     });
 }
开发者ID:kjmtrue,项目名称:phanbook,代码行数:63,代码来源:Module.php

示例5: register

 /**
  * {@inheritdoc}
  */
 public function register(DiInterface $di)
 {
     $di->set(self::SERVICE_NAME, function () use($di) {
         $url = new UrlResolver();
         $url->setBaseUri($di->get('config')->application->baseUri);
         return $url;
     }, true);
 }
开发者ID:arius86,项目名称:core,代码行数:11,代码来源:UrlServiceProvider.php

示例6: attachUrlResolver

 public function attachUrlResolver($baseUri = '/')
 {
     $this->_di->setShared('url', function () use($baseUri) {
         $url = new \Phalcon\Mvc\Url();
         $url->setBaseUri($baseUri);
         return $url;
     });
     return $this;
 }
开发者ID:kengos,项目名称:phalconCart,代码行数:9,代码来源:AbstractInitializer.php

示例7: registerServices

 /**
  * Register services used by the backend application
  *
  * @param $di
  */
 public function registerServices($di)
 {
     $config = $this->config();
     /**
      * register the dispatcher
      */
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         /*$eventManager = new Manager();
                     $eventManager->attach('dispatch', new \Acl('backend'));
         
                     $dispatcher->setEventsManager($eventManager);*/
         $dispatcher->setDefaultNamespace('app\\backend\\controllers');
         return $dispatcher;
     });
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri($config->application->baseUri);
         return $url;
     }, true);
     $di->setShared('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->viewsDir);
         $view->registerEngines(['.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(['compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_']);
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di->set('db', function () use($config) {
         return new MysqlAdapter($config->database->toArray());
     });
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise
      */
     $di->set('modelsMetadata', function () {
         return new MetaDataAdapter();
     });
     /**
      * Start the session the first time some component request the session service
      */
     $di->setShared('session', function () {
         $session = new SessionAdapter();
         $session->start();
         return $session;
     });
 }
开发者ID:adrianeavaz,项目名称:manager.io,代码行数:59,代码来源:Module.php

示例8: onBoot

 public function onBoot()
 {
     // TODO: Implement onBoot() method.
     $this->getDI()->setShared('url', function () {
         $protocol = stripos(server('SERVER_PROTOCOL'), 'https') === true ? 'https://' : 'http://';
         $hostname = server('HTTP_HOST');
         $url = new Url();
         $url->setStaticBaseUri(env('static_url', "{$protocol}{$hostname}/"));
         $url->setBaseUri(env('base_url', '/'));
         return $url;
     });
 }
开发者ID:dotronglong,项目名称:phalcon-engine,代码行数:12,代码来源:ServiceRegister.php

示例9: registerServices

 /**
  * Registers services related to the module
  *
  * @param DiInterface $di
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include APP_PATH . "/apps/backend/config/config.php");
     /**
      * Setting up the view component
      */
     $di['view'] = function () use($config) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => __DIR__ . '/cache/', 'compiledSeparator' => '_'));
             $compiler = $volt->getCompiler();
             // format number
             $compiler->addFilter('number', function ($resolvedArgs) {
                 return 'Helpers::number(' . $resolvedArgs . ');';
             });
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         $config = $config->database->toArray();
         $dbAdapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config['adapter'];
         unset($config['adapter']);
         return new $dbAdapter($config);
     };
     /**
      * Logger service
      */
     $di->set('logger', function ($filename = null, $format = null) use($config) {
         $format = $format ?: $config->get('logger')->format;
         $filename = trim($filename ?: $config->get('logger')->filename, '\\/');
         $path = rtrim($config->get('logger')->path, '\\/') . DIRECTORY_SEPARATOR;
         $formatter = new FormatterLine($format, $config->get('logger')->date);
         $logger = new FileLogger($path . $filename);
         $logger->setFormatter($formatter);
         $logger->setLogLevel($config->get('logger')->logLevel);
         return $logger;
     });
     $di->set('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri("/backend/");
         return $url;
     });
 }
开发者ID:vietdh85,项目名称:product-vh,代码行数:57,代码来源:Module.php

示例10: getResponseObject

 /**
  * Initializes the response object and returns it
  *
  * @author Nikolaos Dimopoulos <nikos@phalconphp.com>
  * @since  2014-10-05
  *
  * @return PhTResponse
  */
 protected function getResponseObject()
 {
     PhDI::reset();
     $di = new PhDI();
     $di->set('url', function () {
         $url = new PhUrl();
         $url->setBaseUri('/');
         return $url;
     });
     $response = new PhTResponse();
     $response->setDI($di);
     return $response;
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:21,代码来源:HttpBase.php

示例11: setUrlService

 /**
  * Set url service when module start
  * @param Di $di
  * @param Config $config
  * @param string $name Module name
  * @return \Phalex\Events\Listener\Application
  */
 private function setUrlService(Di $di, Config $config, $name)
 {
     $base = $static = '/';
     if (isset($config['url'])) {
         $default = isset($config['url']['default']) ? $config['url']['default'] : '/';
         if (isset($config['url'][$name])) {
             $base = isset($config['url'][$name]['uri']) ? $config['url'][$name]['uri'] : $default;
             $static = isset($config['url'][$name]['static']) ? $config['url'][$name]['static'] : $default;
         }
     }
     $url = new UrlService();
     $url->setBaseUri($base);
     $url->setStaticBaseUri($static);
     $di->set('url', $url, true);
     return $this;
 }
开发者ID:tmquang6805,项目名称:phalex,代码行数:23,代码来源:Application.php

示例12: setUp

 /**
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->checkExtension('phalcon');
     // Reset the DI container
     Di::reset();
     // Instantiate a new DI container
     $di = new Di();
     // Set the URL
     $di->set('url', function () {
         $url = new Url();
         $url->setBaseUri('/');
         return $url;
     });
     $di->set('escaper', function () {
         return new Escaper();
     });
     $this->di = $di;
 }
开发者ID:lisong,项目名称:incubator,代码行数:21,代码来源:UnitTestCase.php

示例13: testGet

 public function testGet()
 {
     $url = new Url();
     $url->setBaseUri('http://www.test.com');
     $this->assertEquals('http://www.test.com', $url->get(''));
     $this->assertEquals('http://www.test.com/', $url->get('/'));
     $this->assertEquals('http://www.test.com/path', $url->get('/path'));
     $url->setBaseUri('http://www.test.com/?_url=/');
     $this->assertEquals('http://www.test.com/?_url=/path&params=one', $url->get('path', array('params' => 'one')));
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:10,代码来源:UrlTest.php

示例14: registerServices

 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     /**
      * Setting up the view component
      */
     // The URL component is used to generate all kind of urls in the application
     $di->set('url', function () {
         $url = new Url();
         $url->setBaseUri('/');
         return $url;
     });
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->view->viewsDir);
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => function () use($view, $config) {
             $volt = new Volt($view);
             $volt->setOptions(['compiledPath' => $config->application->view->compiledPath, 'compiledSeparator' => $config->application->view->compiledSeparator, 'compiledExtension' => $config->application->view->compiledExtension, 'compileAlways' => true]);
             return $volt;
         }]);
         // Create an event manager
         $eventsManager = new EventsManager();
         // Attach a listener for type 'view'
         $eventsManager->attach('view', function ($event, $view) {
             if ($event->getType() == 'notFoundView') {
                 throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')');
             }
         });
         // Bind the eventsManager to the view component
         $view->setEventsManager($eventsManager);
         return $view;
     });
 }
开发者ID:vikilaboy,项目名称:digitalkrikits,代码行数:43,代码来源:Module.php

示例15: setUp

 /**
  * Sets the test up by loading the DI container and other stuff
  *
  * @author Nikos Dimopoulos <nikos@phalconphp.com>
  * @since  2012-09-30
  * @param  \Phalcon\DiInterface $di
  * @param  \Phalcon\Config      $config
  * @return void
  */
 protected function setUp(DiInterface $di = null, Config $config = null)
 {
     $this->checkExtension('phalcon');
     if (!is_null($config)) {
         $this->config = $config;
     }
     if (is_null($di)) {
         // Reset the DI container
         DI::reset();
         // Instantiate a new DI container
         $di = new FactoryDefault();
         // Set the URL
         $di->set('url', function () {
             $url = new Url();
             $url->setBaseUri('/');
             return $url;
         });
         $di->set('escaper', function () {
             return new \Phalcon\Escaper();
         });
     }
     $this->di = $di;
 }
开发者ID:nineeshk,项目名称:incubator,代码行数:32,代码来源:UnitTestCase.php


注:本文中的Phalcon\Mvc\Url类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。