本文整理汇总了PHP中Phalcon\Mvc\Url::setBaseUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::setBaseUri方法的具体用法?PHP Url::setBaseUri怎么用?PHP Url::setBaseUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Url
的用法示例。
在下文中一共展示了Url::setBaseUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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¶ms=one', $url->get('path', array('params' => 'one')));
}
示例2: setUrl
private function setUrl()
{
$url = new Url();
if (!$this->application->debug) {
$url->setBaseUri($this->application->production->baseUri);
$url->setStaticBaseUri($this->application->production->staticBaseUri);
} else {
$url->setBaseUri($this->application->development->baseUri);
$url->setStaticBaseUri($this->application->development->staticBaseUri);
}
return $url;
}
示例3: 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;
});
}
示例4: 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;
}
示例5: 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]);
});
}
示例6: 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;
});
}
示例7: 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);
}
示例8: attachUrlResolver
public function attachUrlResolver($baseUri = '/')
{
$this->_di->setShared('url', function () use($baseUri) {
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri($baseUri);
return $url;
});
return $this;
}
示例9: 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;
});
}
示例10: 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;
});
}
示例11: 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;
});
}
示例12: 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;
}
示例13: __construct
/**
* @param Router|null $router
* @param Url|null $url
*/
public function __construct(Router $router = null, Url $url = null)
{
$di = new DI();
$di->setShared('request', new PhalconRequest());
if ($router instanceof PhalconRouterInterface) {
$this->router = $router;
} elseif ($router === null) {
$this->router = new Router();
$this->router->clear();
} else {
throw new Exception\RuntimeException('Router has to be an instance of RouterInterface');
}
$this->router->setDI($di);
$di->setShared('router', $this->router);
if ($url instanceof UrlInterface) {
$this->url = $url;
} elseif ($url === null) {
$this->url = new Url();
$this->url->setBaseUri('/');
} else {
throw new Exception\RuntimeException('Url has to be an instance of UrlInterface');
}
$this->url->setDI($di);
}
示例14: 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;
}
示例15: 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;
}