本文整理汇总了PHP中Input::is_ajax方法的典型用法代码示例。如果您正苦于以下问题:PHP Input::is_ajax方法的具体用法?PHP Input::is_ajax怎么用?PHP Input::is_ajax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Input
的用法示例。
在下文中一共展示了Input::is_ajax方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_create
public function action_create()
{
if (\Input::method() == 'POST') {
$msg = ['msg' => '', 'errcode' => 0, 'status' => 'succ'];
//检测必要的订单信息
$data = \Input::post();
//生成订单明细
$details = [];
foreach ($data['goods'] as $id) {
$item = \Model_Trolley::find_one_by('goods_id', $id);
array_push($details, $item->to_array());
}
$this->load_details($details);
//生成优惠信息
$this->load_preferential($data['coupons']);
if (!$this->save($data)) {
$msg = ['msg' => $this->result_message, 'errcode' => 20, 'status' => 'err'];
}
if (\Input::is_ajax()) {
die(json_encode($msg));
}
}
$params = ['title' => ''];
$params['trolley_ids'] = [1, 2, 3];
\View::set_global($params);
$this->template->title = '创建订单';
$this->template->content = \View::forge("{$this->theme}/create");
}
示例2: before
/**
* @param none
* @throws none
* @returns void
*/
public function before()
{
$result = array();
// users need to be logged in to access this controller
if (!\Sentry::check()) {
$result = array('message' => 'You need to be logged in to access that page.', 'url' => '/admin/login');
// Don't show this message if url is just 'admin'
if (\Uri::string() == 'admin/admin/index') {
unset($result['message']);
}
\Session::set('redirect_to', \Uri::admin('current'));
} else {
if (!\Sentry::user()->is_admin()) {
$result = array('message' => 'Access denied. You need to be a member of staff to access that page.', 'url' => '/admin/login');
\Session::set('redirect_to', \Uri::admin('current'));
}
}
if (!empty($result)) {
if (\Input::is_ajax()) {
\Messages::error('You need to be logged in to complete this action.');
echo \Messages::display('left', false);
exit;
} else {
if (isset($result['message'])) {
\Messages::warning($result['message']);
}
\Response::redirect($result['url']);
}
}
parent::before();
}
示例3: action_add_blocked
public function action_add_blocked($block = null)
{
if (empty($block) === true) {
$block = $_POST['blocked'];
} else {
$block = str_replace('-', '.', $block);
}
$blacklist_item = Model_Blacklist::query()->where('expression', $block)->get_one();
if (empty($blacklist_item) === true) {
$blacklist_item = Model_Blacklist::forge(array('expression' => $block));
$blacklist_item->save();
if (Input::is_ajax() === true) {
echo $blacklist_item->id;
}
} else {
if (Input::is_ajax() === true) {
print_r(Format::forge(array('error' => 'Already Exists'))->to_json());
} else {
Session::set('error', $block . ' is already in the blacklist!');
}
}
if (Input::is_ajax() === true) {
die;
}
Response::Redirect_Back();
}
示例4: action_index
/**
* The index action
*
* @access public
* @return void
*/
public function action_index()
{
$settings = \Config::load('autoresponder.db');
// $autoResponder = Model_Setting::find(array('where' => array(array('meta_key', '=', 'auto-responders'))));
if (\Input::post()) {
$input = \Input::post();
if (!\Input::is_ajax()) {
$val = Model_Setting::validate('create');
if (!$val->run()) {
if ($val->error() != array()) {
// show validation errors
\Messages::error('<strong>There was an error while trying to create settings</strong>');
foreach ($val->error() as $e) {
\Messages::error($e->get_message());
}
}
} else {
try {
\Config::save('autoresponder.db', array('logo_url' => $input['logo_url'], 'company_name' => $input['company_name'], 'address' => $input['address'], 'website' => $input['website'], 'phone' => $input['phone'], 'email_address' => $input['email_address'], 'sender_email_address' => $input['sender_email_address'], 'contact_us_email_address' => $input['contact_us_email_address'], 'instagram_account_name' => $input['instagram_account_name'], 'facebook_account_name' => $input['facebook_account_name']));
// $setting->save();
\Messages::success('Settings successfully created.');
\Response::redirect('admin/settings');
} catch (\Database_Exception $e) {
// show validation errors
\Messages::error('<strong>There was an error while trying to create settings.</strong>');
// Uncomment lines below to show database errors
$errors = $e->getMessage();
\Messages::error($errors);
}
}
}
}
\View::set_global('title', 'Settings');
\Theme::instance()->set_partial('content', $this->view_dir . 'index')->set('settings', $settings, false);
}
示例5: action_login
public function action_login()
{
$url_redirect = \Uri::create('system/index/index');
if (\Auth::check()) {
\Response::redirect($url_redirect);
}
if (\Input::is_ajax()) {
$val = \Validation::forge('validate_login');
$val->add_field('email', 'Email', 'required|valid_email');
$val->add_field('password', 'Password', 'required');
if ($val->run(array())) {
if (\Auth::instance()->login(\Input::param('email'), \Input::param('password'))) {
if (\Input::param('remember', false)) {
\Auth::remember_me();
} else {
\Auth::dont_remember_me();
}
$response = array('status' => 'success', 'url' => $url_redirect);
} else {
$messages = \Auth::get_error();
$response = array('status' => 'error', 'msg' => $messages);
}
} else {
$messages = $val->error_message();
$response = array('status' => 'error', 'msg' => $messages);
}
return \Response::forge(json_encode($response));
}
$this->theme->set_template('login');
$this->theme->get_template()->set('content', \view::forge('default/login', $this->_arrParam));
}
示例6: before
public function before()
{
parent::before();
if (!Input::is_ajax()) {
$this->_init_nav();
}
}
示例7: action_save
/**
* 编辑保存被投票项目
* @param int $id
* @throws \Exception
* @throws \FuelException
*/
public function action_save($id = 0)
{
if (\Input::method() == 'POST') {
$msg = ['status' => 'err', 'msg' => '', 'errcode' => 10];
$data = \Input::post();
$data['start_at'] = $data['start_at'] ? strtotime($data['start_at']) : 0;
$data['end_at'] = $data['end_at'] ? strtotime($data['end_at']) : 0;
$data['account_id'] = \Session::get('WXAccount')->id;
$data['seller_id'] = \Session::get('WXAccount')->seller_id;
$data['type'] = 'VOTE';
$market = \Model_Marketing::find($id);
if (!$market) {
$market = \Model_Marketing::forge();
}
$market->set($data);
if ($market->save()) {
$limit = \Model_MarketingLimit::forge(['involved_total_num' => 1, 'marketing_id' => $market->id]);
$limit->save();
$msg = ['status' => 'succ', 'msg' => '', 'errcode' => 0, 'data' => $market->to_array()];
}
if (\Input::is_ajax()) {
die(json_encode($msg));
}
\Session::set_flash('msg', $msg);
}
}
示例8: output
public static function output($status = 'success', $message = '', $data = array())
{
$output = (object) array('status' => $status, 'message' => $message, 'data' => $data);
$response = \Request::active()->controller_instance->response;
if (\Input::is_ajax()) {
$response->set_header('Content-type', 'application/json');
}
return $response->body(json_encode($output));
}
示例9: action_parse_info_table
/**
* Parse info tab content
*
* @param $table = Table to parse
*/
public function action_parse_info_table($table = false)
{
if (\Input::is_ajax()) {
$table = \Input::post('table', '');
echo $this->parse_info_table($table);
}
if (\Request::is_hmvc()) {
echo $this->parse_info_table($table);
}
}
示例10: post_is_unique
public function post_is_unique()
{
if (Input::is_ajax()) {
// $this->format = 'json';
$username = Input::post('username');
$username = Model_User::query()->where('email', $username)->get_one();
if ($username === null) {
return $this->response(array('unique' => true));
}
return $this->response(array('unique' => false));
}
return false;
}
示例11: action_ajax_test_ftp
public function action_ajax_test_ftp()
{
// is ajax
if (!\Input::is_ajax()) {
\Response::redirect(\Uri::create('admin'));
}
// check permission
if (\Model_AccountLevelPermission::checkAdminPermission('config_global', 'config_global') == false) {
\Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string()))));
return null;
}
if (\Input::method() == 'POST') {
// get post value and test connection
$config['hostname'] = trim(\Input::post('hostname'));
$config['username'] = trim(\Input::post('username'));
$config['password'] = trim(\Input::post('password'));
$config['port'] = (int) trim(\Input::post('port'));
$config['passive'] = trim(\Input::post('passive')) == 'true' ? true : false;
$config['ssl_mode'] = false;
$config['debug'] = false;
$basepath = trim(\Input::post('basepath'));
// connect to ftp
$ftp = \Ftp::forge($config);
$ftp->connect();
$ftp->change_dir($basepath);
$files = $ftp->list_files();
$ftp->close();
$output = array();
if ($files !== false) {
$output['form_status'] = 'success';
$output['form_status_message'] = \Lang::get('config_ftp_connected_check_basepath_from_dir_structure_below');
natsort($files);
$output['list_files'] = '<ul>';
foreach ($files as $file) {
$output['list_files'] .= '<li>' . $file . '</li>';
}
$output['list_files'] .= '</ul>';
} else {
// got false from list_files means cannot connect
$output['form_status'] = 'error';
$output['form_status_message'] = \Lang::get('config_ftp_could_not_connect_to_server');
}
// clear no use variables
unset($basepath, $config, $file, $files, $ftp);
// send out json values
$response = new \Response();
$response->set_header('Content-Type', 'application/json');
$response->body(json_encode($output));
return $response;
}
}
示例12: action_menus
public function action_menus()
{
$params = array('title' => "菜单项", 'menu' => 'wechat-menu', 'action_name' => "自定义菜单");
$account = \Model_WXAccount::find(\Session::get('WXAccount')->id);
if (!$account) {
if (\Input::is_ajax()) {
die(json_encode(array('status' => 'err', 'msg' => '您还未绑定有效公众帐户', 'errcode' => 10)));
}
die('您还未绑定有效公众帐户');
}
$params['items'] = isset($account->menu) && $account->menu ? json_decode($account->menu) : '';
\View::set_global($params);
return \View::forge("ace/mp/coustom_menu/moblie");
}
示例13: action_index
/**
* The index action
*
* @access public
* @return void
*/
public function action_index()
{
$settings = \Config::load('backup.db');
if (\Input::post()) {
$input = \Input::post();
if (!\Input::is_ajax()) {
$val = Model_Backup::validate('create');
if (!$val->run()) {
if ($val->error() != array()) {
// show validation errors
\Messages::error('<strong>There was an error while trying to create settings</strong>');
foreach ($val->error() as $e) {
\Messages::error($e->get_message());
}
}
} else {
try {
\Config::save('backup.db', array('enable' => $input['enable'], 'email' => $input['email'], 'period' => $input['period']));
//save cronjob
$output = shell_exec('crontab -l');
$db_backup_cron_file = "/tmp/db_backup_cron.txt";
if ($input['enable']) {
if ($input['period'] == 'daily') {
$daily_backup_command = '0 0 * * * wget ' . \Uri::create('backup/execute');
file_put_contents($db_backup_cron_file, $daily_backup_command . PHP_EOL);
} else {
if ($input['period'] == 'weekly') {
$weekly_backup_command = '0 0 * * 0 wget ' . \Uri::create('backup/execute');
file_put_contents($db_backup_cron_file, $weekly_backup_command . PHP_EOL);
}
}
} else {
file_put_contents($db_backup_cron_file, "" . PHP_EOL);
}
exec("crontab {$db_backup_cron_file}");
\Messages::success('Settings successfully created.');
\Response::redirect('admin/backup');
} catch (\Database_Exception $e) {
// show validation errors
\Messages::error('<strong>There was an error while trying to create settings.</strong>');
// Uncomment lines below to show database errors
$errors = $e->getMessage();
\Messages::error($errors);
}
}
}
}
\View::set_global('title', 'Backup');
\Theme::instance()->set_partial('content', $this->view_dir . 'index')->set('settings', $settings, false);
}
示例14: after
/**
* After controller method has run, render the theme template
*
* @param Response $response
*/
public function after($response)
{
if (!\Input::is_ajax()) {
// If nothing was returned set the theme instance as the response
if (empty($response)) {
$response = \Response::forge(\Theme::instance());
}
if (!$response instanceof Response) {
$response = \Response::forge($response);
}
return $response;
}
return parent::after($response);
}
示例15: action_index
/**
* Returns a list of event agenda items.
* The method is mainly intended to be called using ajax
* in this case, a json-formated string is returned.
* @param int $event_id
*/
public function action_index($event_id = null)
{
!isset($event_id) and Response::redirect("event");
$event = Model_Orm_Event::find($event_id, array("related" => array("agendas")));
!isset($event) and Response::redirect("event");
if (Input::is_ajax()) {
$response = Response::forge(Format::forge()->to_json($event->agendas));
$response->set_header("Content-Type", "application/json");
return $response;
} else {
$data['event'] = $event;
$this->template->title = "Agenda items: " . $event->title;
$this->template->content = View::forge('agenda/index', $data);
}
}