本文整理汇总了PHP中Arr::extract方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::extract方法的具体用法?PHP Arr::extract怎么用?PHP Arr::extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::extract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_delete
/**
* Удаление новости автосервиса
* @return void
*/
function action_delete()
{
$settings = ORM::factory('payment_settings', $this->request->param('id', null));
if (!$settings->loaded()) {
Message::set(Message::ERROR, Kohana::message('admin', 'payment.settings_not_found'));
$this->request->redirect('admin/payment/settings');
}
if ($settings->system == 'Y') {
Message::set(Message::NOTICE, 'Нельзя удалять системные настройки');
$this->request->redirect('admin/payment/settings');
}
if ($_POST) {
$action = Arr::extract($_POST, array('submit', 'cancel'));
if ($action['cancel']) {
$this->request->redirect('admin/payment/settings');
}
if ($action['submit']) {
$name = $settings->name;
$settings->delete();
Message::set(Message::SUCCESS, 'Платежная настройка <strong>' . $name . '</strong> удалена');
$this->request->redirect('admin/payment/settings');
}
}
$this->view = View::factory('backend/delete')->set('url', 'admin/payment/settings/delete/' . $settings->id)->set('from_url', 'admin/payment/settings')->set('title', 'Удаление платежной настройки: ' . $settings->name)->set('text', 'Вы действительно хотите удалить "' . $settings->name . '?');
$this->template->title = 'Удаление новости "' . $settings->name . '"';
$this->template->bc['#'] = $this->template->title;
$this->template->content = $this->view;
}
示例2: action_share
/**
* REST endpoint for sharing droplets via email
*/
public function action_share()
{
$this->template = '';
$this->auto_render = FALSE;
if ($this->request->method() != "POST") {
throw HTTP_Exception::factory(405)->allowed('POST');
}
// Extract the input data to be used for sending the email
$post = Arr::extract($_POST, array('recipient', 'drop_title', 'drop_url', 'security_code'));
$csrf_token = $this->request->headers('x-csrf-token');
// Setup validation
$validation = Validation::factory($post)->rule('recipient', 'not_empty')->rule('recipient', 'email')->rule('security_code', 'Captcha::valid')->rule('drop_title', 'not_empty')->rule('drop_url', 'url');
// Validate
if (!CSRF::valid($csrf_token) or !$validation->check()) {
Kohana::$log->add(Log::DEBUG, "CSRF token or form validation failure");
throw HTTP_Exception::factory(400);
} else {
list($recipient, $subject) = array($post['recipient'], $post['drop_title']);
// Modify the mail body to include the email address of the
// use sharing content
$mail_body = __(":user has shared a drop with you via SwiftRiver\n\n:url", array(':user' => $this->user['owner']['username'], ':url' => $post['drop_url']));
// Send the email
Swiftriver_Mail::send($recipient, $subject, $mail_body);
}
}
示例3: action_register
public function action_register()
{
if (isset($_POST['submit'])) {
$data = Arr::extract($_POST, array('username', 'password', 'first_name', 'password_confirm', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'agree'));
$users = ORM::factory('user');
// $content->message = '';
// $content->message = Captcha::valid($_POST['captcha'])? 'Не угадал';
try {
$regdate = date("Y-M-D");
$users->create_user($_POST, array('username', 'first_name', 'password', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'regdate' => $regdate));
$role = ORM::factory('role', array('name' => 'login'));
$users->add('roles', $role);
// $users->add('roles', 1);
$email = Email::factory('Регистрация на сайте', 'Регистрация на сайте успешно завешена')->to($data['email'], $data['first_name'])->from('admin@mykohana.loc', 'mykohan')->send();
$this->action_login();
$this->request->redirect('account');
// $this->reg_ok = "<p><b>Ваш профил успешно созданно</b></p>";
$this->action_login();
$this->request->redirect('account');
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('user');
}
}
$captcha = Captcha::instance();
$captcha_image = $captcha->render();
$country = ORM::factory('country')->find_all();
$zones = ORM::factory('zone')->where('country_id', '=', 176)->find_all();
$form_register = View::factory('v_registration', array('country' => $country, 'zones' => $zones))->bind('errors', $errors)->bind('data', $data)->bind('captcha_image', $captcha_image);
// Выводим в шаблон
$this->template->title = 'Регистрация';
$this->template->page_title = 'Регистрация новога пользователя';
$this->template->block_center = array('form_register' => $form_register);
}
示例4: action_edit
public function action_edit()
{
$id = (int) $this->request->param('id');
$m = ORM::factory('manufactures', $id);
if (!$m->loaded()) {
$this->request->redirect('/admin/manufactures');
}
$data = $m->as_array();
// Редактирование
if (isset($_POST['submit'])) {
$data = Arr::extract($_POST, array('title', 'alias', 'url', 'image'));
$m->values($data);
try {
$m->save();
if (!empty($_FILES['image']['name'])) {
$image = $_FILES['image']['tmp_name'];
$filename = $this->_upload_img($image);
// Запись в БД
$m->image = $filename;
$m->save();
}
$this->request->redirect('admin/manufactures');
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('validation');
}
}
$content = View::factory('/admin/v_manufactureedit')->bind('id', $id)->bind('errors', $errors)->bind('data', $data);
$this->template->page_title = 'Редактировть страницу';
$this->template->block_center = $content;
}
示例5: action_delete
/**
* Удаление новости автосервиса
* @return void
*/
function action_delete()
{
$news = ORM::factory('newsservice', $this->request->param('id', NULL));
if (!$news->loaded()) {
Message::set(Message::ERROR, Kohana::message('admin', 'news_not_found'));
$this->request->redirect('admin/news/service');
}
if ($_POST) {
$action = Arr::extract($_POST, array('submit', 'cancel'));
if ($action['cancel']) {
$this->request->redirect('admin/news/service');
}
if ($action['submit']) {
$title = $news->title;
$service_name = $news->service->name;
$news->delete();
Message::set(Message::SUCCESS, 'Новость автосервиса <strong>' . $service_name . '</strong> "' . $title . '" удалена');
$this->request->redirect('admin/news/service');
}
}
$this->view = View::factory('backend/delete')->set('url', 'admin/news/service/delete/' . $news->id)->set('from_url', 'admin/news/service')->set('title', 'Удаление новости компании ' . $news->service->name)->set('text', 'Вы действительно хотите удалить новость "' . $news->title . '" сервиса "' . $news->service->name . '"?');
$this->template->title = 'Удаление новости "' . $news->title . '"';
$this->template->bc['#'] = $this->template->title;
$this->template->content = $this->view;
}
示例6: action_reg
public function action_reg()
{
if ($this->request->method() == 'POST') {
$date = Arr::extract($_POST, array('username', 'first_name', 'email', 'password', 'password_confirm'));
$users = ORM::factory('user');
try {
$users->create_user($_POST, array('email', 'username', 'password', 'first_name'));
$role = ORM::factory('role')->where('name', '=', 'login')->find();
$users->add('roles', $role);
$this->action_login();
// $this->request->redirect('http://kohana/catalog');
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('auto');
}
header('Location: /');
exit;
}
//закэшировал
$content = $this->cache->get('v_reg');
//$this->cache->delete('v_reg');
if ($content == NULL) {
$content = View::factory('/index/auth/v_auth_register')->bind('errors', $errors);
$this->cache->set('v_reg', $content->render());
}
//выводим в шаблон
$this->template->page_title = 'Регистрация';
$this->template->block_center = array($content);
}
示例7: action_index
public function action_index()
{
$data_pages = ORM::factory('Page')->where('title_en', '=', 'contacts')->find()->as_array();
$id = $data_pages['id'];
$data_contacts = ORM::factory('Setting', 1)->as_array();
if (isset($_POST['submit'])) {
$data_pages = Arr::extract($_POST, array('seo_snippet', 'keywords', 'title_head'));
$data_contacts = Arr::extract($_POST, array('main_adress', 'branch_adress'));
try {
$page = ORM::factory('Page', $id);
$page->values($data_pages);
$page->save();
$contacts = ORM::factory('Setting', 1);
$contacts->values($data_contacts);
$contacts->save();
Controller::redirect('admin/contacts');
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('validation');
}
}
$content = View::factory('admin/contacts/v_contacts_edit');
$content->bind('errors', $errors);
$content->bind('data_pages', $data_pages);
$content->bind('data_contacts', $data_contacts);
$this->template->page_title = 'Контакты';
$this->template->block_center = array($content);
}
示例8: action_edit
/**
* Basic
*/
public function action_edit()
{
$this->title = __('settings.settings_general');
// Fields for save
$for_extract = ['per_page_frontend', 'per_page_backend', 'sitename', 'siteslogan', 'copyright', 'year_creation_site', 'type_backend_menu'];
$config = Config::get('settings');
$data = Arr::extract($_POST, $for_extract);
if ($this->request->is_post()) {
$data = Validation::factory(array_map('trim', $data))->rules('per_page_frontend', [['not_empty'], ['digit']])->rules('per_page_backend', [['not_empty'], ['digit']])->rules('year_creation_site', [['not_empty'], ['digit']])->rule('sitename', 'not_empty');
if ($data->check()) {
foreach ($for_extract as $field) {
$config[$field] = $data[$field];
}
$config->save();
Message::success(__('settings.changes_saved'));
HTTP::redirect(Route::url('b_settings'));
} else {
Message::error(__('settings.error_saving'));
$errors = $data->errors('validation');
}
} else {
$data = $config;
}
$this->content = View::factory($this->view, ['data' => $data])->bind('errors', $errors);
}
示例9: before
public function before()
{
parent::before();
$this->params = Arr::extract($this->request->param(), array('year', 'month', 'day'));
View::bind_global('params', $this->params);
View::bind_global('content', $this->content);
}
示例10: action_edit
public function action_edit()
{
$this->request->response = View::factory($this->request->param('format') . '/movement/edit')->bind('movement', $this->movement)->set('sources', ORM::factory('source')->where('parent_id', 'IS', NULL)->find_all()->as_array('id', 'name'))->set('equities', $this->user->equities->where('parent_id', 'IS', NULL)->find_all()->as_array('id', 'name'))->set('drains', ORM::factory('drain')->where('parent_id', 'IS', NULL)->find_all()->as_array('id', 'name'));
$this->movement = ORM::factory('movement', $this->request->param('id'));
if (isset($this->input['name'])) {
$this->movement->values($this->input);
$transactions = Arr::extract($this->input, array('incomes', 'transfers', 'expenses'), array());
foreach ($transactions as $type => $transaction_array) {
foreach ($transaction_array as $transaction) {
$this->movement->add_transaction(ORM::factory(rtrim($type, 's'))->values($transaction));
}
}
if ($this->movement->check()) {
$this->movement->save();
$this->request->redirect('movement/view/' . $this->movement->id . '.' . $this->request->param('format'));
}
} else {
foreach ($this->movement->incomes->find_all() as $income) {
$this->movement->add_transaction($income);
}
foreach ($this->movement->transfers->find_all() as $transfer) {
$this->movement->add_transaction($transfer);
}
foreach ($this->movement->expenses->find_all() as $expense) {
$this->movement->add_transaction($expense);
}
}
}
示例11: action_login
public function action_login()
{
$this->template->menu_login = TRUE;
// Если залогинен, то перекидываем на дерево
if (Auth::instance()->logged_in()) {
$this->redirect(Route::url('user/id', array('user_id' => Auth::instance()->get_user()->id)));
}
$post = Arr::extract($this->request->post(), array('email', 'password'));
$data['errors'] = NULL;
if ($this->request->method() == 'POST') {
$valid = Validation::factory($post)->rules('email', array(array('not_empty')))->rules('password', array(array('not_empty')))->labels(array('email' => 'Адрес электронной почты', 'password' => 'Пароль'));
if (!$valid->check()) {
$data['errors'] = $valid->errors('valid');
} else {
if (Auth::instance()->login($valid['email'], $valid['password'], TRUE)) {
// Авторизация прошла успешно
if (!is_null($this->request->referrer())) {
$this->redirect($this->request->referrer());
} else {
$this->redirect(Route::url('user/id', array('user_id' => Auth::instance()->get_user()->id)));
}
} else {
$data['errors'] = array('usermail' => '', 'userpass' => Kohana::message('valid', 'login.incorrect'));
}
}
}
$data += $post;
$this->template->content = View::factory('auth/login', $data);
}
示例12: action_index
public function action_index()
{
if (Auth::instance()->logged_in()) {
$this->request->redirect('admin');
}
if ($_POST) {
$data = Arr::extract($_POST, array('username', 'password', 'remember'));
$status = Auth::instance()->login($data['username'], $data['password'], (bool) $data['remember']);
if ($status) {
$user = ORM::factory('user')->where('username', '=', $data['username'])->find();
if ($user->status == 1) {
if (Auth::instance()->logged_in()) {
$this->request->redirect('admin');
}
} else {
$faillogin = "<div class='alert alert-error'>Вам запрещен доступ в систему!</div>";
Auth::instance()->logout(TRUE);
}
} else {
$faillogin = "<div class='alert alert-error'>Неправильный email или пароль!</div>";
$this->response->body(View::factory('/admin/login')->bind('faillogin', $faillogin));
}
}
$this->response->body(View::factory('/admin/login')->bind('faillogin', $faillogin));
}
示例13: action_save
public function action_save()
{
$data = Arr::extract($_POST, array('sitename', 'description', 'session', 'keywords', 'robots', 'email', 'author', 'copyright', 'page404', 'status', 'debug', 'cache'));
foreach ($data as $key => $value) {
Kohana::$config->_write_config('site', $key, $value);
}
}
示例14: action_delete
public function action_delete()
{
$dispute = ORM::factory('admin_dispute', $this->request->param('id', NULL));
if (!$dispute->loaded()) {
Message::set(Message::ERROR, 'Такое дополнение не найдено');
$this->request->redirect('admin/development');
}
$task_url = 'admin/development/task/view/' . $dispute->task->id;
if ($_POST) {
$actions = Arr::extract($_POST, array('submit', 'cancel'), FALSE);
/*
if ($actions['cancel'])
$this->request->redirect('admin/development/task/view/'.$dispute->task->id);
*/
if ($actions['submit']) {
$dispute->delete();
Message::set(Message::SUCCESS, 'Дополнение к задаче удалено');
}
$this->request->redirect($task_url);
}
$this->view = View::factory('backend/delete')->set('url', $this->request->uri())->set('from_url', $task_url)->set('title', 'Удаление дополнения к задаче')->set('text', 'Вы действительно хотите удалить дополнение к задаче "' . $dispute->task->title . '"');
$this->template->title = 'Удаление дополнения к задаче';
$this->template->bc['#'] = $this->template->title;
$this->template->content = $this->view;
}
示例15: action_edit
/**
* Edit
*/
public function action_edit()
{
$this->title = __('home.page_edit');
// Fields for save
$for_extract = ['text', 'meta_t', 'meta_d', 'meta_k'];
$config = Config::get('home');
$data = Arr::extract($_POST, $for_extract);
if ($this->request->is_post()) {
$data = Validation::factory(array_map('trim', $data))->rule('meta_t', 'not_empty')->rule('meta_d', 'not_empty')->rule('meta_k', 'not_empty');
if ($data->check()) {
foreach ($for_extract as $field) {
$config[$field] = $data[$field];
}
$config->save();
Message::success(__('settings.changes_saved'));
HTTP::redirect(Route::url('b_home'));
} else {
Message::error(__('settings.error_saving'));
$errors = $data->errors('validation');
}
} else {
$data = $config;
}
$this->content = View::factory($this->view, ['data' => $data])->bind('errors', $errors);
}