本文整理汇总了PHP中Environment::getSession方法的典型用法代码示例。如果您正苦于以下问题:PHP Environment::getSession方法的具体用法?PHP Environment::getSession怎么用?PHP Environment::getSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::getSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createComponent
public function createComponent($name)
{
switch ($name) {
case 'searchForm':
$form = new AppForm($this, $name);
$form->addText('q', __('Query:'));
$form['q']->getControlPrototype()->onclick('if (this.value === "' . __('Input search keywords') . '") {
this._default = this.value;
this.value = "";
}');
$form['q']->getControlPrototype()->onblur('if (this.value === "" && this._default !== undefined) {
this.value = this._default;
}');
$form->setAction($this->link('Search:default'));
$form->setMethod('get');
if (isset(Environment::getSession(SESSION_SEARCH_NS)->last)) {
$form->setDefaults(array('q' => Environment::getSession(SESSION_SEARCH_NS)->last));
} else {
$form->setDefaults(array('q' => __('Input search keywords')));
}
break;
default:
return parent::createComponent($name);
}
}
示例2: increaseRead
public static function increaseRead($id)
{
$reader = Environment::getSession('reader');
if ($reader[$id] == NULL) {
dibi::query('UPDATE [works] SET [read] = [read] + 1 WHERE workId=%i', $id);
$reader[$id] = TRUE;
}
}
示例3: __construct
public function __construct($parent = NULL, $name = NULL)
{
parent::__construct($parent, $name);
$this->form = new AppForm($this, 'form');
$this->form->addSubmit('yes', _('Yes'))->onClick[] = array($this, 'confirmClicked');
$this->form->addSubmit('no', _('No'))->onClick[] = array($this, 'cancelClicked');
$this->form->addHidden('token');
$this->question = Html::el('p');
$this->session = Environment::getSession('ConfirmationDialog/tokens');
}
示例4: handleSubmit
public function handleSubmit($form)
{
$values = $form->getValues();
$query = $values['query'];
$data = $this->presenter->model('search')->search($query);
$session = Environment::getSession('search');
$session->query = $query;
$session->search_result = $data;
$this->getPresenter()->redirect('Search:search', array('query' => $query));
}
示例5: getService
/**
* Gets the service object of the specified type.
* @param string service name
* @param array options in case service is not singleton
* @return mixed
*/
public static function getService($name, array $options = NULL)
{
if (!is_string($name) || $name === '') {
throw new InvalidArgumentException("Service name must be a non-empty string, " . gettype($name) . " given.");
}
$session = Environment::getSession('MokujiServiceLocator');
$lower = strtolower($name);
if (isset($session->{$lower})) {
// instantiated singleton
if ($options) {
throw new InvalidArgumentException("Service named '{$name}' is singleton and therefore can not have options.");
}
return $session->{$lower};
} elseif (isset($session->factories[$lower])) {
list($factory, $singleton, $defOptions) = $session->factories[$lower];
if ($singleton && $options) {
throw new InvalidArgumentException("Service named '{$name}' is singleton and therefore can not have options.");
} elseif ($defOptions) {
$options = $options ? $options + $defOptions : $defOptions;
}
if (is_string($factory) && strpos($factory, ':') === FALSE) {
// class name
Framework::fixNamespace($factory);
if (!class_exists($factory)) {
throw new AmbiguousServiceException("Cannot instantiate service '{$name}', class '{$factory}' not found.");
}
$service = new $factory();
if ($options && method_exists($service, 'setOptions')) {
$service->setOptions($options);
// TODO: better!
}
} else {
// factory callback
$factory = callback($factory);
if (!$factory->isCallable()) {
throw new InvalidStateException("Cannot instantiate service '{$name}', handler '{$factory}' is not callable.");
}
$service = $factory->invoke($options);
if (!is_object($service)) {
throw new AmbiguousServiceException("Cannot instantiate service '{$name}', value returned by '{$factory}' is not object.");
}
}
if ($singleton) {
$session->{$lower} = $service;
unset($session->factories[$lower]);
}
return $service;
}
if ($this->parent !== NULL) {
return $this->parent->getService($name, $options);
} else {
throw new InvalidStateException("Service '{$name}' not found.");
}
}
示例6: actionSearch
public function actionSearch($query)
{
$session = Environment::getSession('search');
if ($session->query != $query) {
$data = $this->model('search')->search($query);
} else {
$data = $session->search_result;
}
$this->template->query = $query;
$this->template->data = $data;
$this->view = 'results';
}
示例7: createComponentTree
public function createComponentTree()
{
$tree = new TreeView();
$tree->useAjax = true;
$mode = null === $this->mode ? 1 : $this->mode;
$session = Environment::getSession();
$tree->mode = $mode;
$tree->rememberState = true;
$tree->addLink('default', 'name', 'id', true, $this->presenter);
$tree->dataSource = SitemapModel::findAll();
//$tree->enableSorting(array($this, 'move'));
//$tree->renderer->wrappers['link']['collapse'] = null;
//$tree->renderer->wrappers['link']['expand'] = null;
//$tree->renderer->wrappers['node']['icon'] = null;
$tree->renderer->wrappers['link']['collapse'] = 'a class="ui-icon ui-icon-circlesmall-minus" style="float: left"';
$tree->renderer->wrappers['link']['expand'] = 'a class="ui-icon ui-icon-circlesmall-plus" style="float: left"';
$tree->renderer->wrappers['node']['icon'] = 'span class="ui-icon ui-icon-document" style="float: left"';
return $tree;
}
示例8: renderDefault
public function renderDefault($q, $page = 1)
{
try {
$ids = array();
foreach (fulltext::index()->find($q) as $hit) {
$ids[] = $hit->getDocument()->id;
}
$this->template->paginator = new Paginator();
$this->template->paginator->setItemCount(count($ids));
$this->template->paginator->setItemsPerPage(Environment::getVariable('itemsPerPage', 30));
$this->template->paginator->setPage($page);
$this->template->products = mapper::products()->findByIds(array_slice($ids, $this->template->paginator->getOffset(), $this->template->paginator->getLength()));
$this->template->title = __('Search results for ``%s"', $q);
$this->template->q = $q;
Environment::getSession(SESSION_SEARCH_NS)->last = $q;
searchlog::log($q);
} catch (Exception $e) {
$this->template->products = array();
}
}
示例9: renderProduct
public function renderProduct()
{
// recent products
if (!isset(Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent)) {
Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent = array();
}
array_unshift(Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent, $this->template->product);
$already_in = array();
foreach (Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent as &$_) {
$id = $_->getId();
if (isset($already_in[$id])) {
$_ = FALSE;
}
$already_in[$id] = TRUE;
}
Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent = array_slice(array_filter(Environment::getSession(SESSION_RECENTPRODUCTS_NS)->recent), 0, 5);
// visited products
array_push(Environment::getSession(SESSION_ORDER_NS)->visited, array($this->template->product, time()));
// fill template
$this->template->nav = mapper::categories()->findForNavByProductId($this->template->product->getId());
}
示例10: editFormSubmitted
public function editFormSubmitted($form)
{
$func = 'save';
switch ($form->name) {
case 'studentsEditForm':
$model = 'students';
break;
case 'teachersEditForm':
$model = 'teachers';
break;
case 'coursesEditForm':
$model = 'courses';
break;
case 'roomsEditForm':
$model = 'school';
$func = 'saveNewRoom';
break;
case 'departmentsEditForm':
$model = 'school';
$func = 'saveNewDepartment';
break;
case 'learning_timesEditForm':
$model = 'school';
$func = 'saveNewLearningTime';
break;
}
$values = $form->getValues();
$this->model($model)->{$func}($values);
$namespace = Environment::getSession()->getNamespace('table');
$table = $namespace->table;
unset($namespace->table);
$this->redirect('default', array('table' => $table));
}
示例11: onDataFormSubmit
/**
* Data form
* @param string
*/
public function onDataFormSubmit(Form $form)
{
// check for validity
if (!$form->isValid()) {
return;
}
// get data
$order = Environment::getSession(SESSION_ORDER_NS);
$order->data = $form->getValues();
if ($order->data['same_delivery']) {
foreach ($order->data as $k => $v) {
if (strncmp($k, 'payer_', strlen('payer_')) === 0) {
$order->data['delivery_' . substr($k, strlen('payer_'))] = $v;
}
}
}
$this->redirect('complete');
}
示例12: Route
<?php
/**
* Nette TreeView example bootstrap file.
*
* @copyright Copyright (c) 2010 Roman Novák
* @package nette-treeview
*/
// Step 1: Load Nette Framework
// this allows load Nette Framework classes automatically so that
// you don't have to litter your code with 'require' statements
require LIBS_DIR . '/Nette/loader.php';
// Step 2: Configure environment
// 2a) enable Nette\Debug for better exception and error visualisation
Debug::enable(false);
Debug::enableProfiler();
// 2b) load configuration from config.ini file
Environment::loadConfig();
Environment::getSession()->start();
dibi::connect(Environment::getConfig('database'));
// Step 3: Configure application
// 3a) get and setup a front controller
$application = Environment::getApplication();
//$application->errorPresenter = 'Error';
$application->catchExceptions = false;
// Step 4: Setup application router
$router = $application->getRouter();
$router[] = new Route('index.php', array('presenter' => 'Homepage', 'action' => 'default'), Route::ONE_WAY);
$router[] = new Route('<presenter>/<action>/<id>', array('presenter' => 'Homepage', 'action' => 'default', 'id' => NULL));
// Step 5: Run the application!
$application->run();
示例13: Exception
//Environment::setMode(Environment::DEVELOPMENT, false);
// 2b) load configuration from config.ini file
//require LIBS_DIR . '/Custom/MultipleConfigurator.php';
//Environment::setConfigurator(new MultipleConfigurator());
//$config = Environment::loadConfig();
// 2c) check if cache, sessions and log directories are writable
if (@file_put_contents(Environment::expand('%tempDir%/_check'), '') === FALSE) {
throw new Exception("Make directory '" . Environment::getVariable('tempDir') . "' writable!");
}
if (@file_put_contents(Environment::expand('%sessionDir%/_check'), '') === FALSE) {
throw new Exception("Make directory '" . Environment::getVariable('sessionDir') . "' writable!");
}
if (@file_put_contents(Environment::expand('%logDir%/_check'), '') === FALSE) {
throw new Exception("Make directory '" . Environment::getVariable('logDir') . "' writable!");
}
$session = Environment::getSession();
$session->setSavePath(Environment::getVariable('sessionDir'));
//Environment::getHttpResponse()->cookiePath = '/'; // toto tu treba, aby fungovali cookie..v novsej verzii je to uz fixnute
$session->setExpiration($config['session']['lifetime']);
if (!$session->isStarted()) {
$session->start();
}
/**
* create new httpRequest for CLI
* @see http://wiki.nette.org/cs/cookbook/http-routovani-v-cli
*/
if (Environment::isConsole()) {
function createHttpRequestService()
{
$config = Environment::getConfig('httpRequest');
// params can be taken from config or command line if needed
示例14: getSession
/**
* @return Session
*/
protected function getSession($namespace = NULL)
{
return Environment::getSession($namespace);
}
示例15: getNodeSession
protected function getNodeSession()
{
return Environment::getSession()->getNamespace('Nette.Extras.TreeView/' . $this->getTreeView()->getName() . '/' . $this->getName());
}