本文整理汇总了PHP中Request::initial方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::initial方法的具体用法?PHP Request::initial怎么用?PHP Request::initial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request::initial方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_registration
public function action_registration()
{
Request::initial()->is_ajax() || die;
$emailsignup = ORM::factory('User')->checkUser('email', $this->request->post('emailsignup'));
$usernamesignup = ORM::factory('User')->checkUser('username', $this->request->post('usernamesignup'));
if ($emailsignup->loaded() || $usernamesignup->loaded()) {
if ($emailsignup->loaded()) {
$message[0]['text'] = "User with this email is already exist!";
$message[0]['item'] = "emailsignup";
$message[0]['status'] = "error";
}
if ($usernamesignup->loaded()) {
$message[1]['text'] = "User with username email is already exist!";
$message[1]['item'] = "usernamesignup";
$message[1]['status'] = "error";
}
die(json_encode($message));
}
$token = md5(time() . $this->request->post('usernamesignup') . $this->request->post('emailsignup'));
$data = array('username' => $this->request->post('usernamesignup'), 'email' => $this->request->post('emailsignup'), 'password' => $this->request->post('passwordsignup'), 'password_confirm' => $this->request->post('passwordsignup_confirm'), 'token' => $token);
$user = ORM::factory('User')->create_user($data, array('username', 'email', 'password', 'token'));
$url = URL::site(NULL, TRUE) . 'approved?token=' . $token;
$config = Kohana::$config->load('email');
$from = $config['email'];
$to = $this->request->post('emailsignup');
$subject = "Registration approval";
$text = "Thank you for registration on our site! You must follow this link to activate your account: " . $url;
Email::connect($config['main']);
Email::send($to, $from, $subject, $text, $html = false);
$message[0]['text'] = "Link to activate your account sent for your email";
$message[0]['item'] = "emailsignup";
$message[0]['status'] = "ok";
die(json_encode($message));
}
示例2: before
public function before()
{
parent::before();
// detecting language, setting it
$this->detect_language();
$this->set('_language', $this->language);
// creating and attaching page metadata
$this->metadata = new Model_Metadata();
$this->metadata->title(__(Application::instance()->get('title')), false);
$this->set('_metadata', $this->metadata);
//TODO: token auth
/*
if ($this->request->method() == Request::POST && Arr::get($_POST, 'token', '') !== Security::token())
{
throw new HTTP_Exception_403('Wrong token data');
}
*/
$this->set('_token', Security::token());
// Handles return urls, cropping language out of it (will be appended by url.site at redirect time)
$rr = Request::initial()->uri();
$rr = trim($rr, '/');
$rr = explode('/', $rr);
if (in_array($rr[0], Application::instance()->get('language.list'))) {
array_shift($rr);
}
$rr = implode('/', $rr);
$this->set('_return', $rr);
// detecting if user is logged in
if (method_exists(Auth::instance(), 'auto_login')) {
Auth::instance()->auto_login();
}
$this->user = Auth::instance()->get_user();
$this->set('_user', $this->user);
}
示例3: run
/**
* Execute elFinder command and output result
*
* @return void
* @author Dmitry (dio) Levashov
**/
public function run()
{
$isPost = Request::initial()->method() === Request::POST;
$src = $_SERVER["REQUEST_METHOD"] == Request::POST ? Request::initial()->post() : Request::initial()->query();
$cmd = isset($src['cmd']) ? $src['cmd'] : '';
$args = array();
if (!function_exists('json_encode')) {
$error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON);
$this->output(array('error' => '{"error":["' . implode('","', $error) . '"]}', 'raw' => true));
}
if (!$this->elFinder->loaded()) {
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors));
}
// telepat_mode: on
if (!$cmd && $isPost) {
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html'));
}
// telepat_mode: off
if (!$this->elFinder->commandExists($cmd)) {
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)));
}
// collect required arguments to exec command
foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) {
$arg = $name == 'FILES' ? $_FILES : (isset($src[$name]) ? $src[$name] : '');
if (!is_array($arg)) {
$arg = trim($arg);
}
if ($req && (!isset($arg) || $arg === '')) {
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
}
$args[$name] = $arg;
}
$args['debug'] = isset($src['debug']) ? !!$src['debug'] : false;
$this->output($this->elFinder->exec($cmd, $this->input_filter($args)));
}
示例4: execute
public function execute($method, $url, array $post = array())
{
$redirects_count = 1;
\Request::$initial = NULL;
$this->_request = \Request::factory($url)->method($method)->post($post)->body(http_build_query($post));
if ($this->_previous_url) {
$this->_request->referrer($this->_previous_url);
}
$this->_previous_url = $this->current_url() . \URL::query($this->_request->query(), FALSE);
\Request::$initial = $this->_request;
$this->_response = $this->_request->execute();
while ($this->_response->status() >= 300 and $this->_response->status() < 400) {
$redirects_count++;
if ($redirects_count >= $this->max_redirects()) {
throw new Exception_Toomanyredirects('Maximum Number of redirects (5) for url :url', array(':url' => $url));
}
$url_parts = parse_url($this->_response->headers('location'));
$query = isset($url_parts['query']) ? $url_parts['query'] : '';
parse_str($query, $query);
$_GET = $query;
$url = $url_parts['path'];
\Request::$initial = NULL;
$this->_request = \Request::factory($url);
\Request::$initial = $this->_request;
$this->_response = $this->_request->execute();
}
return $this->_response->body();
}
示例5: action_index
public function action_index()
{
$data = array();
$category = new Model_Category('tree');
$category->checkTree(TRUE);
$data['categories'] = $category->getTree();
if ($this->isPressed('btnSubmitAdd')) {
$categoryName = Arr::get($_POST, 'categoryName', '');
$parentId = Arr::get($_POST, 'parentId', 0);
$res = $category->catInsert($parentId, array('name' => $categoryName));
if ($res) {
Request::initial()->redirect('admin/category');
}
$data['errors'] = $category->getErrors();
}
if ($this->isPressed('btnSubmitChange')) {
$categoryName = Arr::get($_POST, 'categoryName', '');
$parentId = Arr::get($_POST, 'parentId', 0);
if ($category->changeName($parentId, $categoryName)) {
Request::initial()->redirect('admin/category');
}
$data['errors'] = $category->getErrors();
}
if ($this->isPressed('btnSubmitDel')) {
$catDeleteId = Arr::get($_POST, 'catDeleteId', 0);
$category->catDelete($catDeleteId);
Request::initial()->redirect('admin/category');
}
$this->tpl->content = View::factory('admin/categoryeditview', $data);
}
示例6: init
/**
* init: check if user is logged in
*
* if not: redirect to login
*/
public function init()
{
// call parent before first
parent::init();
// only check if the controller is not auth
if (Request::initial()->controller() != 'Auth') {
// url to loginpage
$url = URL::to('Auth@login');
// init identity
$identity = Identity::instance();
//revert identity to original user (maybe assume was called somewhere else)
$identity->revert();
// check authentication
if (!$identity->authenticated()) {
// if user is not allready authenticated, redirect to login page
$this->redirect($url);
} else {
$website = Website::instance();
// else: initialise acl
Acl::init($identity, new Model_Rights($website->websites()));
// set current environment
Acl::environment($website->id());
// if user is not entitled to access backend
if (!Acl::instance()->allowed('Backend', 'access')) {
$this->redirect($url);
}
// if user is not entitled to access controller
if (!Acl::instance()->allowed(Request::initial()->controller(), 'access')) {
$this->redirect($url);
}
}
}
}
开发者ID:yubinchen18,项目名称:A-basic-website-project-for-a-company-using-the-MVC-pattern-in-Kohana-framework,代码行数:38,代码来源:Auth.php
示例7: getCommonColumns
public static function getCommonColumns()
{
$request = Request::initial();
$id = $request->param('primary');
$cart = ORM::factory('Orders', $id);
return ['user_id' => ['dont_select' => true, 'label' => 'Пользователь', 'type' => 'caption', 'get_current_value' => function () use($cart) {
$user = ORM::factory('User', $cart->user_id);
if (!empty($user->id)) {
return $user->username . ' <a href="/admin/dataEdit/Users/' . $user->id . '/?ref=' . urlencode(AdminHREF::getFullCurrentHREF()) . '">Просмотр пользователя</a>';
}
return 'Пользователь неопознан, его ID=' . $user->id;
}], 'date' => ['label' => 'Дата', 'type' => 'date'], 'time' => ['label' => 'Время', 'type' => 'time'], 'cart' => ['label' => 'Корзина', 'type' => 'caption', 'dont_select' => true, 'get_current_value' => function () use($cart) {
$cart = unserialize($cart->cart);
$render = '';
$sum = 0;
if (is_array($cart) && !empty($cart)) {
foreach ($cart as $good) {
$sum += $good['price'] * $good['count'];
$render .= "<div style='display:inline-block;padding: 5px;'><div><img class='previewAdminImage' src=\"/" . $good['image'] . "\"/> x " . $good['count'] . '</div>';
$render .= "<div> Артикул: " . ORM::factory('Articles', $good['article_id'])->article . "</div>";
$render .= "<div> Багет: " . $good['bag'] . "</div>";
$render .= "<div> Размер: " . $good['width'] . 'x' . $good['height'] . "</div></div>";
}
$render .= "<div> Сумма: " . $sum . " руб.</div>";
}
return $render;
}], 'completed' => ['label' => 'Выполнен', 'type' => 'bool']];
}
示例8: action_delete
public function action_delete()
{
$error = true;
$modelArticles = new Model_articles();
$id = (int) $this->request->param('id');
if ($id) {
$error = !$modelArticles->delete($id);
//Удаляем статью
}
if (Request::initial()->is_ajax()) {
// выполняем только если запрос был через Ajax
if ($error) {
$result = array('error' => true, 'message' => 'Ошибка при удалении');
// по умолчанию возвращаем код с ошибкой
} else {
$result['error'] = false;
// возвращаем код успеха!
}
header('Content-Type: text/json; charset=utf-8');
// Устанавоиваем правильный заголовок
echo json_encode($result);
// на выходе отдаем код в формате JSON
exit;
} else {
$this->redirect('/articles');
// если запрос был не Аяксом, то редиректим на страницу списка статей
}
}
示例9: paginate
public function paginate($page = null, $link = null, $count = null)
{
if ($page == null) {
$page = Arr::get($_GET, 'page', 1);
}
if (!empty($_GET['item_count'])) {
$this->count = (int) Arr::get($_GET, 'item_count');
$count = $this->count;
} else {
if ($count == null) {
$count = $this->count;
} else {
$this->count = (int) $count;
}
}
if ($link == null) {
$link = Request::initial()->uri();
}
$count = (int) $count;
$page = (int) $page;
$start = $page * $count - $count;
$max_page = $this->page_count();
if ($page < 1) {
$page = 1;
} else {
$page = min($page, $max_page);
}
$prev = $page == 1 ? false : true;
$next = $page == $max_page ? false : true;
$this->orm->limit($count)->offset($start);
$this->view_vars = array('page' => $page, 'max_page' => $max_page, 'key' => $this->config->get('key', 'page'), 'count' => $count, 'link' => Security::xss_clean(HTML::chars($link)), 'next' => $next, 'prev' => $prev);
return Security::xss_clean(HTML::chars($this));
}
示例10: action_set_delete
public function action_set_delete()
{
Request::initial()->is_ajax() || die;
$id = $this->request->post('id');
$status = $this->request->post('status');
ORM::factory('Message')->setDelOnce($id, $status);
}
示例11: action_add_article
public function action_add_article()
{
if (Request::initial()->is_ajax()) {
ORM::factory('Article')->add_article($this->request->post("name"), $this->request->post("seo"), $this->request->post("body"), 1);
//замість 1 буде вставлятися id домену з кук
die($data["status"] = "ok");
}
}
示例12: action_top
public function action_top()
{
if (Request::initial() === Request::current()) {
$this->forward_404();
}
$menu = ORM::factory('Menu')->get_parent_active_menus();
$this->template->menu = $menu;
}
示例13: testClientIp
/**
* @dataProvider clientIpKeyProvider
*/
public function testClientIp($key)
{
$ip = '1.2.3.4';
$_SERVER[$key] = $ip;
$actual = Request::initial();
$this->assertEquals($ip, $actual->clientIp());
unset($_SERVER[$key]);
}
示例14: __construct
/**
* Constructor
*
* @param Request $request
* @param Response $response
*/
public function __construct(Request $request, Response $response)
{
// Ajax-like request setting if HMVC call or POST request with param `is_ajax` == `true`
if ($request->is_ajax() or $request !== Request::initial() or $request->method() === HTTP_Request::POST and $request->post('is_ajax') === 'true') {
$request->requested_with('xmlhttprequest');
}
parent::__construct($request, $response);
}
示例15: getAllowedRoles
public function getAllowedRoles()
{
$primary = Request::initial()->param('primary');
if ($primary == Auth::instance()->get_user() || is_null($primary)) {
return ['admin', 'user'];
}
return ['admin'];
}