本文整理汇总了PHP中App::request方法的典型用法代码示例。如果您正苦于以下问题:PHP App::request方法的具体用法?PHP App::request怎么用?PHP App::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App
的用法示例。
在下文中一共展示了App::request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFilters
/**
* Get the user filters
*
* @return array The user filters
*/
public function getFilters()
{
if (App::request()->getHeaders('X-List-Filter')) {
App::session()->getUser()->setOption('admin.user-filter', App::request()->getHeaders('X-List-Filter'));
}
return json_decode(App::session()->getUser()->getOptions('admin.user-filter'), true);
}
示例2: edit
/**
* Edit a role
*/
public function edit()
{
$param = array('id' => 'edit-role-form', 'model' => 'Role', 'reference' => array('id' => $this->roleId), 'fieldsets' => array('form' => array('nofieldset' => true, new HiddenInput(array('field' => 'removable', 'default' => 1, 'readonly' => true)), new TextInput(array('field' => 'name', 'maxlength' => 32, 'label' => Lang::get('roles.form-name-label'), 'required' => true)), new ColorInput(array('field' => 'color', 'label' => Lang::get('roles.form-color-label'), 'default' => '#000'))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new DeleteInput(array('name' => 'delete', 'value' => Lang::get('main.delete-button'), 'notDisplayed' => $this->roleId == -1)), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.load(app.getUri("list-roles"), {selector : "#admin-roles-tab"});');
foreach (Language::getAll() as $language) {
$param['fieldsets']['form'][] = new TextInput(array('name' => "translation[{$language->tag}]", "independant" => true, 'required' => $language->tag == LANGUAGE, "label" => Lang::get("roles.role-label-label", array('lang' => $language->tag)), "default" => Lang::exists("roles.role-" . $this->roleId . "-label") ? Lang::get("roles.role-" . $this->roleId . "-label", array(), 0, $language->tag) : ''));
}
$form = new Form($param);
if (!$form->submitted()) {
return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('icon' => 'user', 'title' => Lang::get('roles.form-title'), 'page' => $form));
} else {
if ($form->submitted() == "delete") {
$form->delete(Form::NO_EXIT);
if ($key) {
$key->delete();
}
return $form->response(Form::STATUS_SUCCESS);
} else {
if ($form->check()) {
try {
$roleId = $form->register(Form::NO_EXIT);
// Create the language key for the translations of the role name
foreach (App::request()->getBody('translation') as $tag => $translation) {
Language::getByTag($tag)->saveTranslations(array('roles' => array("role-{$roleId}-label" => $translation)));
}
return $form->response(Form::STATUS_SUCCESS);
} catch (Exception $e) {
return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : "");
}
}
}
}
}
示例3: formAction
protected function formAction()
{
$form = new UrlForm();
if (App::request()->isPost()) {
$form->setValue('url', App::request()->getPostVar('url'));
if ($form->isValid()) {
// if URL is valid
// find or generate short URL
$existsUrlRecord = UrlModel::findOneByLongurl($form->getValue('url'));
if (false !== $existsUrlRecord) {
// alredy exists - use it
$shortURI = App::alphaid()->toAlpha($existsUrlRecord->id);
} else {
// not exists - create new
$urlRecord = new UrlModel();
$urlRecord->longurl = $form->getValue('url');
$urlRecord->save();
$shortURI = App::alphaid()->toAlpha($urlRecord->id);
}
$shortURL = App::router()->createUrl('Redirector', 'redirect', array('url' => $shortURI));
$form->setValue('shortUrl', $shortURL);
}
}
if (App::request()->isAjaxRequest()) {
$this->setLayout('ajax');
$this->view->form = $form->getData();
} else {
$this->view->form = $form;
$this->render();
}
}
示例4: s003
/**
* POST /principal
*
*/
public function s003()
{
$error;
try {
$req = App::request();
if ($req->isPost()) {
$post = $req->post();
if (!empty($post["nama"])) {
$attributes = array("nama" => $post["nama"], "aktif" => isset($post["aktif"]) ? 1 : 0);
$table = Principal::table();
if (is_null($post["gen_id"]) || $post["gen_id"] == "") {
$table->insert($attributes);
} else {
$where = "nama = '" . $post["gen_id"] . "'";
$table->update($attributes, $where);
}
}
}
} catch (Exception $e) {
$error = $e->getMessage();
ZiUtil::unique_error($error);
App::flash('error', $post["nama"] . ' ' . ZiUtil::unique_error($error));
// App::flash('error', 'Terjadi kesalahan pada inputan anda.');
App::redirect('principal.a001');
}
App::flash('info', 'Data Tersimpan.');
App::redirect('principal.index');
}
示例5: s003
/**
* POST /uom
*
*/
public function s003()
{
$error;
try {
$req = App::request();
if ($req->isPost()) {
$post = $req->post();
$attributes = array("uom_nama" => $post["uom_nama"], "aktif" => isset($post["aktif"]) ? 1 : 0);
$table = UOM::table();
if (is_null($post["gen_id"]) || $post["gen_id"] == "") {
$table->insert($attributes);
} else {
$where = "uom_nama = '" . $post["gen_id"] . "'";
$table->update($attributes, $where);
}
}
} catch (Exception $e) {
$error = $e->getMessage();
ZiUtil::unique_error($error);
App::flash('error', $post["uom_nama"] . ' ' . ZiUtil::unique_error($error));
App::redirect('unitOM.a001');
}
App::flash('info', 'Data Tersimpan : ' . $post["uom_nama"]);
App::redirect('unitOM.index');
}
示例6: __construct
/**
* 构造方法
*
* @param App $app
*/
public function __construct($app)
{
$this->app = $app;
$this->appConfig = $app->config();
$this->request = $app->request();
$this->response = $app->response();
$app->controller = $this;
}
示例7: __construct
public function __construct()
{
$parse = parse_url(\App::request()->getPathInfo());
$this->path = isset($parse['path']) ? array_map('trim', array_filter(explode('/', trim($parse['path'], '/')))) : [];
$this->config = (new Routes())->routesMap;
$this->module = $this->getModule();
$this->dir = $this->config[$this->module];
}
示例8: __construct
/**
* Constructor
*
* @param string $url The not found URL
* @param array $details The exception details
*/
public function __construct($url = '', $details = array())
{
if (!$url) {
$url = App::request()->getFullUrl();
}
$details['url'] = $url;
$message = Lang::get('main.http-error-404-message', $details);
parent::__construct($message, $details);
}
示例9: settings
/**
* Install the application
*/
public function settings()
{
$form = new Form(array('id' => 'install-settings-form', 'labelWidth' => '30em', 'fieldsets' => array('global' => array('legend' => Lang::get('install.settings-global-legend', null, null, $this->language), new TextInput(array('name' => 'title', 'required' => true, 'label' => Lang::get('install.settings-title-label', null, null, $this->language), 'default' => DEFAULT_HTML_TITLE)), new TextInput(array('name' => 'rooturl', 'required' => true, 'label' => Lang::get('install.settings-rooturl-label', null, null, $this->language), 'placeholder' => 'http://', 'default' => getenv('REQUEST_SCHEME') . '://' . getenv('SERVER_NAME'))), new SelectInput(array('name' => 'timezone', 'required' => true, 'options' => array_combine(\DateTimeZone::listIdentifiers(), \DateTimeZone::listIdentifiers()), 'default' => DEFAULT_TIMEZONE, 'label' => Lang::get('install.settings-timezone-label')))), 'database' => array('legend' => Lang::get('install.settings-database-legend', null, null, $this->language), new TextInput(array('name' => 'db[host]', 'required' => true, 'label' => Lang::get('install.settings-db-host-label', null, null, $this->language), 'default' => 'localhost')), new TextInput(array('name' => 'db[username]', 'required' => true, 'label' => Lang::get('install.settings-db-username-label', null, null, $this->language))), new PasswordInput(array('name' => 'db[password]', 'required' => true, 'label' => Lang::get('install.settings-db-password-label', null, null, $this->language), 'pattern' => '/^.*$/')), new TextInput(array('name' => 'db[dbname]', 'required' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-db-dbname-label', null, null, $this->language))), new TextInput(array('name' => 'db[prefix]', 'default' => 'Hawk', 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-db-prefix-label', null, null, $this->language)))), 'admin' => array('legend' => Lang::get('install.settings-admin-legend', null, null, $this->language), new TextInput(array('name' => 'admin[login]', 'required' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-admin-login-label', null, null, $this->language))), new EmailInput(array('name' => 'admin[email]', 'required' => true, 'label' => Lang::get('install.settings-admin-email-label', null, null, $this->language))), new PasswordInput(array('name' => 'admin[password]', 'required' => true, 'label' => Lang::get('install.settings-admin-password-label', null, null, $this->language))), new PasswordInput(array('name' => 'admin[passagain]', 'required' => true, 'compare' => 'admin[password]', 'label' => Lang::get('install.settings-admin-passagain-label', null, null, $this->language)))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('install.install-button', null, null, $this->language), 'icon' => 'cog')))), 'onsuccess' => 'location.href = data.rooturl;'));
if (!$form->submitted()) {
// Display the form
$body = View::make(Plugin::current()->getView('settings.tpl'), array('form' => $form));
return \Hawk\Plugins\Main\MainController::getInstance()->index($body);
} else {
// Make the installation
if ($form->check()) {
/**
* Generate Crypto constants
*/
$salt = Crypto::generateKey(24);
$key = Crypto::generateKey(32);
$iv = Crypto::generateKey(16);
$configMode = 'prod';
/**
* Create the database and it tables
*/
$tmpfile = tempnam(sys_get_temp_dir(), '');
DB::add('tmp', array(array('host' => $form->getData('db[host]'), 'username' => $form->getData('db[username]'), 'password' => $form->getData('db[password]'))));
try {
DB::get('tmp');
} catch (DBException $e) {
return $form->response(Form::STATUS_ERROR, Lang::get('install.install-connection-error'));
}
try {
$param = array('{{ $dbname }}' => $form->getData('db[dbname]'), '{{ $prefix }}' => $form->getData('db[prefix]'), '{{ $language }}' => $this->language, '{{ $timezone }}' => $form->getData('timezone'), '{{ $title }}' => Db::get('tmp')->quote($form->getData('title')), '{{ $email }}' => Db::get('tmp')->quote($form->getData('admin[email]')), '{{ $login }}' => Db::get('tmp')->quote($form->getData('admin[login]')), '{{ $password }}' => Db::get('tmp')->quote(Crypto::saltHash($form->getData('admin[password]'), $salt)), '{{ $ip }}' => Db::get('tmp')->quote(App::request()->clientIp()));
$sql = strtr(file_get_contents(Plugin::current()->getRootDir() . 'templates/install.sql.tpl'), $param);
// file_put_contents($tmpfile, $sql);
Db::get('tmp')->query($sql);
/**
* Create the config file
*/
$param = array('{{ $salt }}' => addcslashes($salt, "'"), '{{ $key }}' => addcslashes($key, "'"), '{{ $iv }}' => addcslashes($iv, "'"), '{{ $configMode }}' => $configMode, '{{ $rooturl }}' => $form->getData('rooturl'), '{{ $host }}' => $form->getData('db[host]'), '{{ $username }}' => $form->getData('db[username]'), '{{ $password }}' => $form->getData('db[password]'), '{{ $dbname }}' => $form->getData('db[dbname]'), '{{ $prefix }}' => $form->getData('db[prefix]'), '{{ $sessionEngine }}' => $form->getData('session'), '{{ $version }}' => $form->getData('version'));
$config = strtr(file_get_contents(Plugin::current()->getRootDir() . 'templates/config.php.tpl'), $param);
file_put_contents(INCLUDES_DIR . 'config.php', $config);
/**
* Create etc/dev.php
*/
App::fs()->copy(Plugin::current()->getRootDir() . 'templates/etc-dev.php', ETC_DIR . 'dev.php');
/**
* Create etc/prod.php
*/
App::fs()->copy(Plugin::current()->getRootDir() . 'templates/etc-prod.php', ETC_DIR . 'prod.php');
$form->addReturn('rooturl', $form->getData('rooturl'));
return $form->response(Form::STATUS_SUCCESS, Lang::get('install.install-success'));
} catch (\Exception $e) {
return $form->response(Form::STATUS_ERROR, Lang::get('install.install-error'));
}
}
}
}
示例10: open
/**
* Open a new session
*
* @param string $savePath Not used
* @param string $name The session name (defaulty 'PHPSESSID')
*/
public function open($savePath, $name)
{
$this->db = App::db();
$this->table = DB::getFullTablename('Session');
// Update the session mtime
if (App::request()->getCookies($name)) {
SessionModel::getDbInstance()->update(SessionModel::getTable(), new DBExample(array('id' => App::request()->getCookies($name))), array('mtime' => time()));
}
// Clean expired sessions
$this->gc(0);
}
示例11: links
private function links($file)
{
$url = \App::request()->getBaseUrl();
$skin = \App::user()->get()->config()->skin;
$type = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$moduleDir = \App::router()->dir;
$themeLink = $url . '/themes/';
$skinLink = $themeLink . $skin . '/';
$skinPath = THEMES_PATH . $skin . DS;
return [[$skinPath . 'modules' . DS . $moduleDir . DS . $type . DS . $file, $skinLink . 'modules/' . $moduleDir . '/' . $type . '/' . $file], [ASSETS_PATH . 'modules' . DS . $moduleDir . DS . $type . DS . $file, $url . '/assets/modules/' . $moduleDir . '/' . $type . '/' . $file], [$skinPath . $type . DS . $file, $skinLink . $type . '/' . $file], [ASSETS_PATH . 'template' . DS . $type . DS . $file, $url . '/assets/template/' . $type . '/' . $file]];
}
示例12: index
/**
* Display the main page of the permission settings
*/
public function index()
{
$permissionGroups = Permission::getAllGroupByPlugin();
$example = isset($this->roleId) ? array('roleId' => $this->roleId) : array();
$data = RolePermission::getListByExample(new DBExample($example));
$values = array();
foreach ($data as $value) {
$values[$value->permissionId][$value->roleId] = $value->value;
}
$roles = isset($this->roleId) ? array(Role::getById($this->roleId)) : Role::getAll(null, array(), array(), true);
$param = array('id' => 'permissions-form', 'fieldsets' => array('form' => array(), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))))));
foreach ($roles as $role) {
foreach ($permissionGroups as $group => $permissions) {
if (Plugin::get($group)) {
foreach ($permissions as $permission) {
if ($role->id == Role::ADMIN_ROLE_ID) {
$default = 1;
} elseif (isset($values[$permission->id][$role->id])) {
$default = $values[$permission->id][$role->id];
} else {
$default = 0;
}
$param['fieldsets']['form'][] = new CheckboxInput(array('name' => "permission-{$permission->id}-{$role->id}", 'disabled' => $role->id == Role::ADMIN_ROLE_ID || $role->id == Role::GUEST_ROLE_ID && !$permission->availableForGuests, 'default' => $default, 'class' => $permission->id == Permission::ALL_PRIVILEGES_ID ? 'select-all' : '', 'nl' => false));
}
}
}
}
$form = new Form($param);
if (!$form->submitted()) {
$page = View::make(Plugin::current()->getView("permissions.tpl"), array('permissions' => $permissionGroups, 'fields' => $form->inputs, 'roles' => $roles));
return NoSidebarTab::make(array('icon' => 'unlock-alt', 'title' => Lang::get('permissions.page-title'), 'page' => $form->wrap($page)));
} else {
try {
foreach ($form->inputs as $name => $field) {
if (preg_match('/^permission\\-(\\d+)\\-(\\d+)$/', $name, $match)) {
$permissionId = $match[1];
$roleId = $match[2];
$value = App::request()->getBody($name) ? 1 : 0;
if ($roleId != Role::ADMIN_ROLE_ID && !($roleId == Role::GUEST_ROLE_ID && !$permission->availableForGuests)) {
$permission = new RolePermission();
$permission->set(array('roleId' => $roleId, 'permissionId' => $permissionId, 'value' => $value));
$permission->save();
}
}
}
App::logger()->info('Permissions were succesfully updated');
return $form->response(Form::STATUS_SUCCESS, Lang::get("roles.permissions-update-success"));
} catch (Exception $e) {
App::logger()->error('An error occured while updating permissions');
return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get("roles.permissions-update-error"));
}
}
}
示例13: index
public function index()
{
$req = App::request();
if ($req->isPost()) {
if ($this->auth->login($req->post('user'), $req->post('passwd'))) {
App::flash('info', "Your login was successful")->redirect('home');
} else {
App::flash('error', 'Your username or password was wrong');
}
}
App::render('auth/login');
}
示例14: write
/**
* Write log
*
* @param string $level The log level : 'debug', 'info', 'notice', 'warning', 'error'
* @param string $message The message to write
*/
private function write($level, $message)
{
if (empty($this->resources[$level])) {
$this->open($level);
}
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$trace = (object) $trace[1];
$request = App::request();
$data = array('date' => date_create()->format('Y-m-d H:i:s'), 'requestId' => $request->uid, 'method' => $request->getMethod(), 'clientIp' => $request->clientIp(), 'uri' => $request->getUri(), 'file' => $trace->file, 'line' => $trace->line, 'message' => $message);
$input = json_encode($data, JSON_UNESCAPED_SLASHES);
fwrite($this->resources[$level], $input . PHP_EOL);
}
示例15: apiJson
public function apiJson()
{
$comments = file_get_contents('assets/comments.json');
$req = App::request();
if ($req->isPost()) {
$post = $req->post();
$commentsDecoded = json_decode($comments, true);
$commentsDecoded[] = ['author' => $post['author'], 'text' => $post['text']];
$comments = json_encode($commentsDecoded, JSON_PRETTY_PRINT);
file_put_contents('assets/comments.json', $comments);
}
ZiUtil::to_json($comments);
}