本文整理汇总了PHP中Session::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getInstance方法的具体用法?PHP Session::getInstance怎么用?PHP Session::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run method with main page logic
*
* Read in list of albums and the latest photos for each album. Pagination enabled.
* Populate template with data and display results in the page.
* @access public
*/
public function run()
{
$PAGINATION_LIMIT = 10;
$session = Session::getInstance();
$user = $session->getUser();
$albumDAO = AlbumDAO::getInstance();
$photoDAO = PhotoDAO::getInstance();
$page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? intval($_GET["page"]) : 1;
if ($page < 1) {
$page = 1;
}
$count = $paginator = $paginator_page = null;
$album = $photo_info_array = null;
$title = "";
$count = $albumDAO->count();
$paginator = new Paginator($count, $PAGINATION_LIMIT);
$paginator_page = $paginator->getPage($page);
$album_array = $albumDAO->all(array("limit" => $paginator_page));
$photo_info_array = array();
foreach ($album_array as $album) {
$count = $photoDAO->countByAlbum($album);
if ($count > 0) {
$tmp_paginator = new Paginator($count, 1);
$tmp_paginator_page = $paginator->getPage($page);
// Only get latest item
list($latest_photo) = $photoDAO->allByAlbum($album, array("order" => "id DESC", "limit" => $tmp_paginator_page));
$photo_info_array[] = array($count, $latest_photo);
}
}
$this->template->render(array("title" => "Album List", "main_page" => "album_list_tpl.php", "session" => $session, "album_array" => $album_array, "photo_info_array" => $photo_info_array, "paginator_page" => $paginator_page));
}
示例2: __construct
final function __construct()
{
$this->request = Request::getInstance();
$this->response = Response::getInstance();
$this->session = Session::getInstance();
$this->onConstruct();
}
示例3: addNewRecordPermissions
/**
* Add access permission for a record to the backend user
*
* @param int $id
* @param string $accessField
* @param string $permissionField
*
* @return bool If current record in a new record
*/
protected function addNewRecordPermissions($id, $accessField, $permissionField)
{
/** @type \BackendUser|object $user */
$user = \BackendUser::getInstance();
$session = \Session::getInstance();
$db = \Database::getInstance();
$groups = deserialize($user->groups);
$newRecords = $session->get('new_records');
if (is_array($newRecords['tl_iso_group']) && in_array($id, $newRecords['tl_iso_group'])) {
if ($user->inherit == 'custom' || empty($groups)) {
// Add permissions on user level
$objUser = $db->prepare("SELECT id, {$accessField}, {$permissionField} FROM tl_user WHERE id=?")->execute($user->id);
$this->addCreatePermission($id, $permissionField, $accessField, 'tl_user', $objUser);
} elseif (!empty($groups) && is_array($groups)) {
// Add permissions on group level
$objGroups = $db->execute("\n SELECT id, {$accessField}, {$permissionField}\n FROM tl_user_group\n WHERE " . $db->findInSet('id', $groups));
while ($objGroups->next()) {
if ($this->addCreatePermission($id, $permissionField, $accessField, 'tl_user_group', $objGroups)) {
break;
}
}
}
return true;
}
return false;
}
示例4: run
/**
* Run method with main page logic
*
* Populate template and display form for creating a new album entry. For POST request,
* validate form data and save information to database. Available to admins only
* @access public
*/
public function run()
{
$session = Session::getInstance();
$user = $session->getUser();
if (!$user || !$user->isAdmin()) {
$session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
header("Location: " . BASE_URL);
return;
}
$albumDAO = AlbumDAO::getInstance();
$album = null;
$form_errors = array();
$form_values = array("title" => "");
if (!empty($_POST)) {
$form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
if (empty($form_values["title"])) {
$form_errors["title"] = "No title specified";
}
if (empty($form_errors)) {
$album = new Album();
$album->setTitle($form_values["title"]);
if ($albumDAO->insert($album)) {
$session->setMessage("Album saved");
header("Location: edit_album.php?id={$album->id}");
return;
} else {
$session->setMessage("Album not saved");
}
}
}
$this->template->render(array("title" => "Create Album", "session" => $session, "main_page" => "create_album_tpl.php", "album" => $album, "form_values" => $form_values, "form_errors" => $form_errors));
}
示例5: __construct
public function __construct()
{
$this->session = Session::getInstance();
$this->user = User::getInstance();
$this->user->auth('tenant@appwerk.de', 'tenant');
$this->vu = VoteUtils::getInstance();
}
示例6: generate
/**
* Generate the module
* @return string
*/
public function generate()
{
$this->arrModules = array();
// enable collapsing legends
$session = \Session::getInstance()->get('fieldset_states');
foreach ($this->getModules() as $k => $arrGroup) {
list($k, $hide) = explode(':', $k, 2);
if (isset($session['iso_be_overview_legend'][$k])) {
$arrGroup['collapse'] = !$session['iso_be_overview_legend'][$k];
} elseif ($hide == 'hide') {
$arrGroup['collapse'] = true;
}
$this->arrModules[$k] = $arrGroup;
}
// Open module
if (\Input::get('mod') != '') {
return $this->getModule(\Input::get('mod'));
} elseif (\Input::get('table') != '') {
foreach ($this->arrModules as $arrGroup) {
if (isset($arrGroup['modules'])) {
foreach ($arrGroup['modules'] as $strModule => $arrConfig) {
if (is_array($arrConfig['tables']) && in_array(\Input::get('table'), $arrConfig['tables'])) {
\Controller::redirect($this->addToUrl('mod=' . $strModule));
}
}
}
}
}
return parent::generate();
}
示例7: login
/** Performs actual login with login object **/
function login($contractor)
{
$contractor->Password = "";
$session = Session::getInstance();
// Set session login object
$session->setUserLogin($contractor);
}
示例8: isValid
public function isValid()
{
global $cfg;
$db = Database::getInstance($cfg['MVC']['dsn']);
$rules = $db->getAll("SELECT vrclassname, description, fieldname, \r\n\t\t\tfieldvalidators.modulename FROM fieldvalidators, formfields \r\n\t\t\tWHERE formfields.ruleid = fieldvalidators.ruleid\r\n\t\t\tAND formname = '{$this->formName}'");
//This statement has been removed from the where clause:
//modulename = '{$this->fieldData['moduleName']}' AND
$invalidFields = array();
$sess = Session::getInstance();
// Validate the submitted fields
foreach ($rules as $rule) {
MVCUtils::includeValidator($rule['vrclassname'], $rule['modulename']);
eval("\$validatorObj = new {$rule['vrclassname']}(\$this->fieldData);");
$vResult = $validatorObj->isValid($this->fieldData[$rule['fieldname']]);
if ($vResult !== true) {
//Put the errors:
// a) straight into the errors array for backwards compatibility
// b) into a sub array, whose key is the submitted value for
// errorFormName, otherwise use the form name
$invalidFields[$rule['fieldname']] = $vResult;
if (!$this->errorFormName) {
$invalidFields[$this->formName][$rule['fieldname']] = $vResult;
} else {
$invalidFields[$this->errorFormName][$rule['fieldname']] = $vResult;
}
}
if ($sess->keyExists('auth_user')) {
BasicLogger::logMessage($sess->getValue('auth_user'), self::module, "debug");
}
}
if (!checkdate($this->fieldData['month'], $this->fieldData['day'], $this->fieldData['year']) || !is_numeric($this->fieldData['month']) || !is_numeric($this->fieldData['day']) || !is_numeric($this->fieldData['year'])) {
$invalidFields[$this->formName]['form'] = "Invalid Date";
}
return $invalidFields;
}
示例9: __construct
function __construct()
{
parent::__construct();
$this->session = Session::getInstance();
$this->project = $this->session->getProject();
$this->menu = array(Messages::getString('General.Logout') => "logout.php") + $this->menu;
}
示例10: __construct
public function __construct($options)
{
$this->options = array_merge($this->options, $options);
$this->Session = Session::getInstance();
$this->db = Orm::loadModel('Users');
$this->options['salt'] = Configure::get('globals.salt');
}
示例11: indexAction
/**
* Вывод каптчи:
*/
public function indexAction(Application $application, Template $template)
{
$kvs = KVS::getInstance();
/*
if ($kvs -> exists(__CLASS__, 'captcha_ban', $_SERVER['REMOTE_ADDR']))
return false;
$kvs -> set(__CLASS__, 'captcha', $_SERVER['REMOTE_ADDR'], $kvs -> get(__CLASS__, 'captcha', $_SERVER['REMOTE_ADDR']) + 1);
$kvs -> expire(__CLASS__, 'captcha', $_SERVER['REMOTE_ADDR'], 5);
if ($kvs -> get(__CLASS__, 'captcha', $_SERVER['REMOTE_ADDR']) > 10) {
$kvs -> set(__CLASS__, 'captcha_ban', $_SERVER['REMOTE_ADDR'], true);
$kvs -> expire(__CLASS__, 'captcha_ban', $_SERVER['REMOTE_ADDR'], 60 * 15);
return false;
}
*/
if (!isset($_GET['key'])) {
return false;
}
/*
if (!preg_match('~^http://1chan\.ru/~i', $_SERVER['HTTP_REFERER']))
return false;
*/
$session = Session::getInstance();
if ($session->instantGet('captcha_' . $_GET['key'], false)) {
$captcha = new KCAPTCHA();
$session->instantSet('captcha_' . $_GET['key'], $captcha->getKeyString());
}
return false;
}
示例12: Clear
static function Clear()
{
$session = Session::getInstance();
$session->set('_PROMPT_', false);
echo "Setting Avy to Stop Listening!\n";
// Set Avy to Listening mode
}
示例13: run
/**
* Run method with main page logic
*
* Read in the specified event from the database.
* Populate template and display event details in the page. Allow admin preview of un-approved event
* @access public
*/
public function run()
{
$session = Session::getInstance();
$user = $session->getUser();
$eventDAO = EventDAO::getInstance();
$attendDAO = AttendanceDAO::getInstance();
$title = "";
$event = $attending = $attend_array = null;
$attend_count = null;
if (!empty($_GET["id"]) && is_numeric($_GET["id"])) {
$id = intval($_GET["id"]);
$event = $eventDAO->load($id, array("joins" => true));
// Check if event is approved
if ($event && $event->status == Event::APPROVED_STATUS) {
$title .= " - {$event->title}";
if ($user) {
$attending = $attendDAO->loadExists($event, $user);
}
$attend_count = $attendDAO->countByEvent($event);
$attend_array = $attendDAO->allByEvent($event, array("joins" => true, "order" => "id DESC"));
} else {
if ($event && $session->getUser() && $session->getUser()->isAdmin()) {
$title .= " - {$event->title}";
$attending = $attendDAO->loadExists($event, $user);
$attend_count = $attendDAO->countByEvent($event);
$attend_array = $attendDAO->allByEvent($event, array("joins" => true, "order" => "id DESC"));
} else {
$event = null;
}
}
}
$this->template->render(array("title" => "Event Details" . $title, "main_page" => "view_event_tpl.php", "session" => $session, "event" => $event, "attending" => $attending, "attend_array" => $attend_array, "attend_count" => $attend_count));
}
示例14: init
private function init()
{
$this->session = Session::getInstance();
$this->request = Request::getInstance();
$this->router = Router::getInstance();
$this->view = View::getInstance();
}
示例15: build
public function build()
{
$sessio = Session::getInstance()->get('my_name');
if (!empty($sessio)) {
$this->setLayout('error/errorlogin.tpl');
} else {
$info = $this->getParams();
if (isset($info['url_arguments'][0])) {
$this->setLayout('error/error404.tpl');
} else {
$s = Session::getInstance()->get('email');
if (empty($s)) {
$this->setLayout('error/error404.tpl');
} else {
$this->setLayout('project/welcome.tpl');
$u = Session::getInstance()->get('username');
$b = Session::getInstance()->get('birth');
$e = Session::getInstance()->get('email');
$p = Session::getInstance()->get('password');
$obj = $this->getClass('MainModel');
$obj->insertar($u, $b, $e, $p);
$this->assign('username', $u);
Session::getInstance()->delete('username');
Session::getInstance()->delete('birth');
Session::getInstance()->delete('email');
Session::getInstance()->delete('password');
}
}
}
}