本文整理汇总了PHP中Validate::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::factory方法的具体用法?PHP Validate::factory怎么用?PHP Validate::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_reply
/**
* Create a new post.
*/
public function action_reply($id)
{
$topic = Jelly::select('forum_topic')->where('id', '=', $id)->load();
// Make sure the topic exists
if (!$topic->loaded()) {
Message::set(Message::ERROR, 'Topic does not exist');
$this->request->redirect('forum');
}
$this->title = 'Forum - Reply to ' . $topic->title;
// Validate the form input
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
if ($post->check()) {
$values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id, 'topic' => $id);
$message = Jelly::factory('forum_post');
// Assign the validated data to the Jelly object
$message->set($values);
$message->save();
$topic_id = $id;
$topic = Jelly::select('forum_topic')->where('id', '=', $topic_id)->load();
$topic->posts = $topic->posts + 1;
$topic->save();
Message::set(Message::SUCCESS, 'You posted a new reply.');
$this->request->redirect('forum/topic/' . $id);
} else {
$this->errors = $post->errors('forum');
}
if (!empty($this->errors)) {
Message::set(Message::ERROR, $this->errors);
}
$this->template->content = View::factory('forum/post/create')->set('post', $post->as_array());
}
示例2: action_createOrUpdateBrand
public function action_createOrUpdateBrand()
{
try {
$post = Validate::factory($_POST)->rule('brand_full_name', 'not_empty')->rule('brand_short_name', 'not_empty');
if (!$post->check()) {
echo "0|ERROR";
die;
}
$brand_full_name = $_POST['brand_full_name'];
$brand_short_name = $_POST['brand_short_name'];
$brand_id = $_POST['brand_id'];
$brand = new Model_Brand();
if ($brand_id != 0) {
$brand = ORM::factory('Brand', $brand_id);
}
$brand->fullName = trim($brand_full_name);
$brand->shortName = trim($brand_short_name);
$brand->status = $this->GENERAL_STATUS['ACTIVE'];
$brand->save();
echo "1|ok";
} catch (Exception $exc) {
echo "0|" . $exc->getTraceAsString();
}
die;
}
示例3: action_create
public function action_create()
{
// Check if the user has a character already.
if ($this->character->loaded()) {
$this->request->redirect('character/create');
}
$character = Jelly::factory('character');
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('name', 'not_empty')->rule('name', 'min_length', array(3))->rule('name', 'max_length', array(20))->rule('gender', 'not_empty')->rule('race', 'not_empty')->callback('race', array($this, 'valid_race'));
if ($post->check()) {
try {
$values = array('name' => $post['name'], 'gender' => $post['gender'], 'race' => $post['race'], 'user' => $this->user->id, 'money' => 1000, 'hp' => 100, 'max_hp' => 100, 'level' => 1, 'xp' => 0, 'energy' => 100, 'alignment' => 5000, 'zone' => 1);
$character->set($values);
$character->save();
$this->MG->add_history('Created the character: ' . $post['name']);
$this->request->redirect('character');
} catch (Validate_Exception $e) {
// Get the errors using the Validate::errors() method
$this->errors = $e->array->errors('register');
}
} else {
$this->errors = $post->errors('character/create');
}
// Get the races the user can choose from.
$races = $this->getRaces();
$this->template->content = View::factory('character/create')->set('post', $post)->set('races', $races);
}
示例4: action_index
public function action_index()
{
$this->content->bind('errors', $errors);
$this->content->bind('success', $success);
$this->content->bind('form', $form);
$this->content->bind('fields', $fields);
$form = $this->company;
$success = FALSE;
$fields = array('name' => 'Nazwa firmy', 'account' => 'Numer konta', 'address' => 'Adres', 'nip' => 'NIP');
if ($_POST) {
$form = array_intersect_key($_POST, $fields);
$validate = Validate::factory($form)->labels($fields)->rule(TRUE, 'not_empty')->rule('account', 'account_number')->rule('nip', 'nip');
if (!$validate->check()) {
$errors = $validate->errors('validate');
$form = (object) $form;
} else {
foreach ($form as $k => $v) {
$this->company->set($k, $v);
}
$form = $this->company;
$success = TRUE;
}
}
$fields = (object) $fields;
}
示例5: action_createOrUpdateDiscount
public function action_createOrUpdateDiscount()
{
try {
$post = Validate::factory($_POST)->rule('discount_value', 'not_empty');
if (!$post->check()) {
echo "0|ERROR";
die;
}
$dicount_value = $_POST['discount_value'];
$discount_id = $_POST['discount_id'];
$discount = new Model_Discount();
if ($discount_id != 0) {
$discount = ORM::factory('Discount', $discount_id);
} else {
$discount->registrationDate = Date::formatted_time();
}
$discount->discount = trim($dicount_value);
$discount->status = $this->GENERAL_STATUS['ACTIVE'];
$discount->save();
echo "1|ok";
} catch (Exception $exc) {
echo "0|" . $exc->getTraceAsString();
}
die;
}
示例6: sendorder
function sendorder()
{
$check = Validate::factory($_POST)->label('fio', 'ФИО')->label('address', 'адрес')->label('phone', 'телефон')->label('email', 'EMail')->rule('fio', 'not_empty')->rule('address', 'not_empty')->rule('phone', 'not_empty')->rule('phone', 'phone')->rule('email', 'not_empty')->rule('email', 'email');
if ($check->check()) {
//$order = ORM::factory('good', $_POST['orderid'])->as_array();
$session = Session::instance();
$_SESSION =& $session->as_array();
$orders = '<b>Наименования:</b><br>';
$price = 0;
foreach ($_SESSION['orders'] as $k => $v) {
$orders .= $_SESSION['orders'][$k]['name'] . ' (ID: ' . $_SESSION['orders'][$k]['id'] . ') - ' . $_SESSION['orders'][$k]['price'] . ' грн. (' . $_SESSION['orders'][$k]['count'] . ' ' . $_SESSION['orders'][$k]['select'] . ')<br>';
$cof = $_SESSION['orders'][$k]['select'] == 'kg' ? $_SESSION['orders'][$k]['count'] : $_SESSION['orders'][$k]['count'] / 1000;
$price += $_SESSION['orders'][$k]['price'] * $cof;
}
$text = '<b>ФИО:</b> ' . $_POST['fio'] . '<br>
<b>Адрес:</b> ' . $_POST['address'] . '<br>
<b>Телефон:</b> ' . $_POST['phone'] . '<br>
<b>EMail:</b> ' . $_POST['email'] . '<br>' . $orders . '<p><b>Итоговая цена без доставки:</b> ' . $price;
$mailer = email::connect();
$message = Swift_Message::NewInstance('Новый заказ', $text, 'text/html', 'utf-8');
$message->setTo('info@sg.od.ua');
$message->setFrom('no-reply@sg.od.ua');
$mailer->send($message);
Session::instance()->delete('orders');
return TRUE;
} else {
return strtolower(implode(' и ', $check->errors('')));
}
}
示例7: action_createOrUpdateMenu
public function action_createOrUpdateMenu()
{
try {
$post = Validate::factory($_POST)->rule('menu_name', 'not_empty')->rule('menu_url', 'not_empty');
if (!$post->check()) {
echo "0|ERROR - Empty Data Post";
die;
}
$menu_name = $_POST['menu_name'];
$menu_url = $_POST['menu_url'];
$super_menu_id = $_POST['idSuperMenu'];
$menu_id = $_POST['idMenu'];
$menu = new Model_Menu();
if ($menu_id != 0) {
$menu = ORM::factory('Menu', $menu_id);
}
$menu->name = trim($menu_name);
$menu->url = trim($menu_url);
if ($_POST['menu_type'] == $this->MENU_TYPE['MENU']) {
$menu->type = $this->MENU_TYPE['MENU'];
} else {
$menu->type = $this->MENU_TYPE['ACTION'];
}
if ($super_menu_id != 0) {
$menu->idSuperMenu = $super_menu_id;
}
$menu->status = $this->GENERAL_STATUS['ACTIVE'];
$menu->save();
echo "1|ok";
} catch (Exception $exc) {
echo "0|" . $exc->getTraceAsString();
}
die;
}
示例8: action_view
public function action_view($id2, $id)
{
if (!is_numeric($id)) {
Message::set(Message::ERROR, 'Invalid ID');
$this->request->redirect('zone');
}
$item = Model_Shop::get_one_item($this->shop->id, $id);
$this->title = $item->name;
$this->item = $item;
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('amount', 'digit')->callback('amount', array($this, 'shop_got_item'));
if ($post->check()) {
$item2 = Model_User::get_item($this->user->id, $id);
// User got the item in his relation table.
if ($item2) {
DB::update('user_items')->set(array('amount' => new Database_Expression('amount + ' . $post['amount'])))->where('user_id', '=', $this->user->id)->and_where('item_id', '=', $id)->execute();
} else {
DB::insert('user_items', array('user_id', 'item_id', 'amount'))->values(array($this->user->id, $id, $post['amount']))->execute();
}
DB::update('shop_items')->set(array('amount' => new Database_Expression('amount - ' . $post['amount'])))->where('shop_id', '=', $this->shop_id)->and_where('item_id', '=', $id)->execute();
$item->amount = $item->amount - $post['amount'];
Message::set(Message::SUCCESS, 'You bought ' . $post['amount'] . ' ' . $item->name);
} else {
if ($post->errors()) {
Message::set(Message::ERROR, $post->errors('shop'));
}
}
$this->template->content = View::factory('shop/view')->set('shop', $this->shop)->set('item', $item);
}
示例9: action_login
/**
* Display login form and perform login
*/
public function action_login()
{
Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Auth::action_login');
// If user is already logged in, redirect to admin main
if ($this->a2->logged_in()) {
Kohana::$log->add('ACCESS', "Attempt to login made by logged-in user");
Kohana::$log->add(Kohana::DEBUG, "Attempt to login made by logged-in user");
Message::instance()->error(Kohana::message('a2', 'login.already'));
$this->request->redirect(Route::get('admin')->uri());
}
$this->template->content = View::factory('admin/auth/login')->bind('post', $post)->bind('errors', $errors);
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('username', 'not_empty')->rule('password', 'not_empty')->callback('username', array($this, 'check_username'));
if ($post->check()) {
if ($this->a1->login($post['username'], $post['password'], !empty($post['remember']))) {
Kohana::$log->add('ACCESS', 'Successful login made with username, ' . $post['username']);
Message::instance()->info(Kohana::message('a2', 'login.success'), array(':name' => $post['username']));
// If external request, redirect to referring URL or admin main
if (!$this->_internal) {
// Get referring URI, if any
$referrer = $this->session->get('referrer') ? $this->session->get('referrer') : Route::get('admin')->uri();
$this->session->delete('referrer');
$this->request->redirect($referrer);
}
} else {
Kohana::$log->add('ACCESS', 'Unsuccessful login attempt made with username, ' . $post['username']);
$post->error('password', 'incorrect');
}
}
$errors = $post->errors('admin');
}
示例10: action_index
public function action_index()
{
$this->template->content = View::factory('contact/email')->bind('post', $post)->bind('errors', $errors)->bind('work_types', $work)->bind('budget_types', $budget);
// Project type
$work = array('development' => 'Web Development', 'database' => 'Database Design', 'review' => 'Code Review', 'kohana' => 'KohanaPHP Consulting', 'other' => 'Other');
// Project budget
$budget = array('under_500' => 'Under $500', 'under_1000' => '$500 - $1000', 'under_5000' => '$1000 - $5000', 'over_5000' => '$5000 or more');
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('name', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('work', 'not_empty')->rule('work', 'in_array', array(array_keys($work)))->rule('description', 'not_empty')->rule('budget', 'not_empty')->rule('budget', 'in_array', array(array_keys($budget)));
if ($post->check()) {
// Create the email body
$body = View::factory('template/lead')->set('name', $post['name'])->set('work', $work[$post['work']])->set('budget', $budget[$post['budget']])->set('description', $post['description'])->render();
// Get the email configuration
$config = Kohana::config('email');
// Load Swift Mailer support
require Kohana::find_file('vendor', 'swift/lib/swift_required');
// Create an email message
$message = Swift_Message::newInstance()->setSubject('w.ings consulting: New Lead from ' . $post['name'])->setFrom(array($post['email'] => $post['name']))->setTo(array('woody@wingsc.com' => 'Woody Gilk'))->setBody(strip_tags($body))->addPart($body, 'text/html');
// Connect to the server
$transport = Swift_SmtpTransport::newInstance($config->server, 25)->setUsername($config->username)->setPassword($config->password);
// Send the message
Swift_Mailer::newInstance($transport)->send($message);
// Redirect to the thanks page
$this->request->redirect(url::site($this->request->uri(array('action' => 'hire'))));
} else {
$errors = $post->errors('forms/contact');
}
}
示例11: action_index
public function action_index()
{
$this->template->content = View::factory('admin/projects/create')->bind('post', $post)->bind('errors', $errors)->bind('associates', $assoc);
$assoc = DB::query(Database::SELECT, 'SELECT id, name FROM associates ORDER BY name')->execute()->as_array('id', 'name');
// Add an option for "no associate"
arr::unshift($assoc, 0, '- none -');
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('title', 'not_empty')->rule('title', 'regex', array('/^[\\pL\\pP\\s]{4,255}$/iu'))->rule('associate_id', 'not_empty')->rule('associate_id', 'in_array', array(array_keys($assoc)))->rule('completed', 'not_empty')->rule('completed', 'date')->rule('website', 'regex', array('#^https?://.+$#'));
if ($post->check($errors)) {
if (empty($post['associate_id'])) {
// Make the associate NULL
$post['associate_id'] = NULL;
// Use only the title for the slug
$post['slug'] = url::title($post['title']);
} else {
// Use the title with associate for the slug
$post['slug'] = url::title($post['title']) . '/with/' . url::title($assoc[$post['associate_id']]);
}
if (empty($post['website'])) {
// Make the website value NULL
$post['website'] = NULL;
}
// Get the values of the array
$values = $post->as_array();
// Convert the completed date into a timestamp
$values['completed'] = strtotime($values['completed']);
$query = DB::query(Database::INSERT, 'INSERT INTO projects (title, associate_id, completed, website, slug) VALUES (:values)')->bind(':values', $values)->execute();
// Set a cookie message
cookie::set('message', 'Created new project with an ID of ' . $query);
// Redirect back to the same page
$this->request->redirect(url::site($this->request->uri));
}
}
示例12: action_createOrDeleteAccess
public function action_createOrDeleteAccess()
{
try {
$post = Validate::factory($_POST)->rule('menu_id', 'not_empty')->rule('group_id', 'not_empty');
if (!$post->check()) {
echo "0|ERROR - Empty Data Post";
die;
}
$menu_id = $_POST['menu_id'];
$group_id = $_POST['group_id'];
$privilege = new Model_Privilege();
$privilege = ORM::factory('Privilege')->where('idMenu', '=', $menu_id)->where('idGroup', '=', $group_id)->find();
if ($privilege->loaded() == TRUE) {
$privilege->delete();
} else {
$privilege->idMenu = $menu_id;
$privilege->idGroup = $group_id;
$privilege->grantDate = Date::formatted_time();
$privilege->idUser = $this->getSessionParameter('user_id');
$privilege->save();
}
echo "1|ok";
} catch (Exception $exc) {
echo "0|" . $exc->getTraceAsString();
}
die;
}
示例13: action_edit
public function action_edit($id)
{
$message = Jelly::select('forum_post')->where('id', '=', $id)->load();
// Make sure the post exists
if (!$message->loaded()) {
Message::set(Message::ERROR, 'Post does not exist');
$this->request->redirect('forum');
}
if ($this->user->id != $message->user->id) {
Message::set(Message::ERROR, 'You are not the author of this post.');
$this->request->redirect('forum');
} else {
$this->title = 'Forum - Edit ' . $message->title;
// Validate the form input
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
if ($post->check()) {
$values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id);
// Assign the validated data to the Jelly object
$message->title = $post['title'];
$message->content = $post['content'];
$message->save();
Message::set(Message::SUCCESS, 'Post has been edited.');
$this->request->redirect('forum');
}
$this->template->content = View::factory('forum/post/edit')->set('message', $message)->set('post', $post);
}
}
示例14: action_index
public function action_index()
{
$supplychain_alias = ORM::factory('supplychain_alias');
$page = max($this->request->param('page'), 1);
$items = 20;
$offset = $items * ($page - 1);
$count = $supplychain_alias->count_all();
$pagination = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'page'), 'total_items' => $supplychain_alias->count_all(), 'items_per_page' => $items));
$this->template->supplychain_alias = $supplychain_alias->limit($pagination->items_per_page)->offset($pagination->offset)->find_all()->as_array(null, array('id', 'site', 'alias', 'supplychain_id'));
$this->template->page_links = $pagination->render();
$this->template->offset = $pagination->offset;
$supplychain_alias_count = $supplychain_alias->count_all();
$post = Validate::factory($_POST);
$post->rule('site', 'not_empty')->rule('alias', 'not_empty')->filter('site', 'strip_tags')->filter('alias', 'strip_tags')->rule('supplychain_id', 'not_empty')->filter(true, 'trim');
if (strtolower(Request::$method) === 'post' && $post->check()) {
$check = false;
$post = (object) $post->as_array();
$site_added = $post->site;
$alias_added = $post->alias;
$id = $post->supplychain_id;
// check if the alias already exists, if not add new alias
$supplychain_alias = ORM::factory('supplychain_alias');
$supplychain_alias->supplychain_id = $id;
$supplychain_alias->site = $site_added;
$supplychain_alias->alias = $alias_added;
try {
$supplychain_alias->save();
} catch (Exception $e) {
Message::instance()->set('Could not create alias. Violates the unique (site, alias)');
}
$this->request->redirect('admin/aliases');
}
Breadcrumbs::instance()->add('Management', 'admin/')->add('Aliases', 'admin/aliases');
}
示例15: action_new_topic
/**
* Create a new topic.
*/
public function action_new_topic($id)
{
$this->title = 'Forum - New Topic';
$category = Jelly::select('forum_category')->where('id', '=', $id)->load();
if (!$category->loaded()) {
Message::set(Message::ERROR, 'Category does not exist');
$this->request->redirect('forum');
}
// Validate the form input
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
if ($post->check()) {
$topic_values = array('title' => $post['title'], 'user' => $this->user->id, 'category' => $id, 'status' => 'open', 'posts' => '1');
$topic = Jelly::factory('forum_topic');
// Assign the validated data to the sprig object
$topic->set($topic_values);
$topic->save();
$topic_id = $topic->id;
$post_values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id, 'topic' => $topic_id);
$message = Jelly::factory('forum_post');
// Assign the validated data to the sprig object
$message->set($post_values);
$message->save();
Message::set(Message::SUCCESS, 'You created a topic.');
$this->request->redirect('forum/category/' . $id);
} else {
$this->errors = $post->errors('forum');
}
if (!empty($this->errors)) {
Message::set(Message::ERROR, $this->errors);
}
$this->template->content = View::factory('forum/topic/create')->set('post', $post->as_array());
}