本文整理匯總了PHP中Input::getDate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Input::getDate方法的具體用法?PHP Input::getDate怎麽用?PHP Input::getDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Input
的用法示例。
在下文中一共展示了Input::getDate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sortInputs
/**
* Callback for sorting inputs by date then value
*
* @param Input $a
* @param Input $b
* @return int
*/
protected function sortInputs($a, $b)
{
if ($a->getDate() == $b->getDate()) {
if ($a->getValue() == $b->getValue()) {
return 0;
}
// Positive values come first, so same-day start/ends are
// incremented before they are decremented
return $a->getValue() > $b->getValue() ? -1 : 1;
}
return $a->getDate() < $b->getDate() ? -1 : 1;
}
示例2: processForm
function processForm($postImage)
{
$errors = [];
$errors['count'] = 0;
$today = date("Y-m-d");
//pass this to be inserted into the database
//form was submitted when $_POST is not empty
if (!empty($_POST)) {
try {
$category = Input::getString('category');
} catch (Exception $e) {
$errors['category'] = 'Category: ' . $e->getMessage();
$errors['count']++;
}
try {
$postingTitle = Input::getString('title');
} catch (Exception $e) {
$errors['title'] = 'Posting Title: ' . $e->getMessage();
$errors['count']++;
}
try {
$price = Input::getNumber('price');
} catch (Exception $e) {
$errors['price'] = 'Price: ' . $e->getMessage();
$errors['count']++;
}
try {
$description = Input::getString('description');
} catch (Exception $e) {
$errors['description'] = 'Description: ' . $e->getMessage();
$errors['count']++;
}
try {
$date_posted = Input::getDate('date_posted');
} catch (Exception $e) {
$errors['date_posted'] = 'Date Posted: ' . $e->getMessage();
$errors['count']++;
}
if ($errors['count'] == 0) {
$adObject = new AdModel();
$adObject->category = $category;
$adObject->title = $postingTitle;
$adObject->price = $price;
$adObject->description = $description;
var_dump($postImage);
$adObject->image = $postImage;
$adObject->date_posted = $today;
// hardcoded: $adObject->user_id = $_SESSION['user_id'];
$adObject->users_id = 1;
$adObject->save();
//unset the $_SESSION['image'] - will be using the one in the database
unset($_SESSION['image']);
header("Location: /ads.show.php?id=" . $adObject->id);
//this will be the $_GET for the ads.show.php
die;
}
}
return $errors;
}
示例3: insertPark
function insertPark($dbc, $park)
{
$errorsArray = [];
try {
$name = Input::getString('name');
} catch (Exception $e) {
$error = $e->getMessage();
array_push($errorsArray, $error);
}
try {
$location = Input::getString('location');
} catch (Exception $e) {
$error = $e->getMessage();
array_push($errorsArray, $error);
}
try {
$date_established = Input::getDate('date_established');
} catch (Exception $e) {
$error = $e->getMessage();
array_push($errorsArray, $error);
}
try {
$area = Input::getNumber('area');
} catch (Exception $e) {
$error = $e->getMessage();
array_push($errorsArray, $error);
}
try {
$visitors = Input::getString('visitors');
} catch (Exception $e) {
$error = $e->getMessage();
array_push($errorsArray, $error);
}
try {
$description = Input::getString('description');
} catch (Exception $e) {
$error = $e->getMessage();
array_push($errorsArray, $error);
}
if (!empty($errorsArray)) {
return $errorsArray;
}
$query = "INSERT INTO national_parks (name, location, date_established, area, visitors, description)\n\t\t\t\tVALUES (:name, :location, :date_established, :area, :visitors, :description)";
$query = $dbc->prepare($query);
$query->bindValue(':name', $name, PDO::PARAM_STR);
$query->bindValue(':location', $location, PDO::PARAM_STR);
$query->bindValue(':date_established', $date_established, PDO::PARAM_STR);
$query->bindValue(':area', $area, PDO::PARAM_STR);
$query->bindValue(':visitors', $visitors, PDO::PARAM_STR);
$query->bindValue(':description', $description, PDO::PARAM_STR);
// $query->fetchAll(PDO::FETCH_ASSOC);
$query->execute();
}
示例4: insertPark
function insertPark($dbc)
{
$errors = [];
try {
$date = Input::getDate('date_established');
$d = $date->format('Y-m-d');
} catch (Exception $e) {
$error = "An error occured: " . $e->getMessage() . PHP_EOL;
array_push($errors['date_established'], $e->getMessage());
}
try {
$name = Input::getString('name');
} catch (Exception $e) {
$error = "An error occured: " . $e->getMessage() . PHP_EOL;
array_push($errors['name'], $e->getMessage());
}
try {
$location = Input::getString('location');
} catch (Exception $e) {
$error = "An error occured: " . $e->getMessage() . PHP_EOL;
array_push($errors['location'], $e->getMessage());
}
try {
$area_in_acres = Input::getNumber('area_in_acres');
} catch (Exception $e) {
$error = "An error occured: " . $e->getMessage() . PHP_EOL;
array_push($errors['area_in_acres'], $e->getMessage());
}
try {
$description = Input::getString('description');
} catch (Exception $e) {
$error = "An error occured: " . $e->getMessage() . PHP_EOL;
array_push($errors['description'], $e->getMessage());
}
if ($error) {
echo $error;
print_r($errors);
} else {
$insert = "INSERT INTO national_parks (name, location, date_established, area_in_acres, description)\n\tVALUES (:name, :location, :date_established, :area_in_acres, :description)";
$stmt = $dbc->prepare($insert);
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->bindValue(':location', $location, PDO::PARAM_STR);
$stmt->bindValue(':date_established', $d, PDO::PARAM_STR);
$stmt->bindValue(':area_in_acres', $area_in_acres, PDO::PARAM_STR);
$stmt->bindValue(':description', $description, PDO::PARAM_STR);
$stmt->execute();
}
}
示例5: insertParks
function insertParks($dbc)
{
// Now calls on the Input class's getString and getDate methods with try catches.
// Try catch create an array of errors for passing to the user in the HTML.
$errorArray = [];
try {
$name = Input::getString('name', 0, 50);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errName'] = $error;
}
try {
$location = Input::getString('location', 0, 50);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errLoc'] = $error;
}
try {
$date_established = Input::getDate('date_established', '1776-07-04', 'next month');
$date_established = $date_established->format('Y-m-d');
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errDate'] = $error;
}
try {
$area_in_acres = Input::getNumber('area_in_acres', 0, 375000000);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errArea'] = $error;
}
try {
$description = Input::getString('description', 0, 500);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errDes'] = $error;
}
// If the $errorArray is not empty, this will return out of the method before binding values and executing below. The $errorArray returns with an array of strings.
if (!empty($errorArray)) {
return $errorArray;
}
$stmt = $dbc->prepare('INSERT INTO national_parks (name, location, date_established, area_in_acres, description) VALUES (:name, :location, :date_established, :area_in_acres, :description)');
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->bindValue(':location', $location, PDO::PARAM_STR);
$stmt->bindValue(':date_established', $date_established, PDO::PARAM_STR);
$stmt->bindValue(':area_in_acres', $area_in_acres, PDO::PARAM_STR);
$stmt->bindValue(':description', $description, PDO::PARAM_STR);
$stmt->execute();
}
示例6: insertData
function insertData($dbc)
{
$errors = [];
if (!empty($_POST)) {
try {
$name = Input::getString('name');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$location = Input::getString('location');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$date = Input::getDate('date_established');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$area = Input::getNumber('area_in_acres');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$description = Input::getString('description');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
if (Input::notEmpty('name') && Input::notEmpty('location')) {
$userData = 'INSERT INTO national_parks (name, location, date_established, area_in_acres, description)
VALUES (:name, :location, :date_established, :area_in_acres, :description)';
$userStmt = $dbc->prepare($userData);
$userStmt->bindValue(':name', $name, PDO::PARAM_STR);
$userStmt->bindValue(':location', $location, PDO::PARAM_STR);
$userStmt->bindValue(':date_established', $date, PDO::PARAM_STR);
$userStmt->bindValue(':area_in_acres', $area, PDO::PARAM_STR);
$userStmt->bindValue(':description', $description, PDO::PARAM_STR);
try {
$userStmt->execute();
} catch (Exception $e) {
$errors[] = $e->getMessage();
throw new Exception('Error: {$e->getMessage()}');
}
}
}
return $errors;
}
示例7: insertListing
function insertListing($dbc, $item_name, $price, $image, $description, $status = "active")
{
$userId = Auth::id();
$d = Input::getDate('now');
$listing_date = $d->format('Y-m-d');
$insert = "INSERT INTO ads(listing_date, item_name, price, image, description, status, user_id) \n\t\tVALUES (:listing_date, :item_name, :price, :image, :description, :status, :user_id)";
$stmt = $dbc->prepare($insert);
$stmt->bindValue(':listing_date', $listing_date, PDO::PARAM_STR);
$stmt->bindValue(':item_name', $item_name, PDO::PARAM_STR);
$stmt->bindValue(':price', $price, PDO::PARAM_INT);
$stmt->bindValue(':image', $image, PDO::PARAM_STR);
$stmt->bindValue(':description', $description, PDO::PARAM_STR);
$stmt->bindValue(':status', $status, PDO::PARAM_STR);
$stmt->bindValue(':user_id', $userId, PDO::PARAM_INT);
$stmt->execute();
}
示例8: insertpark
function insertpark($dbc)
{
$name = Input::getString('parkname', 2, 100);
$location = Input::getString('parklocation', 2, 100);
$date = Input::getDate('date', '1776-07-04', '9999-01-01');
$area = Input::getNumber('area', 0, 1000000000000);
$description = Input::getString('parkdescription', 2, 10000);
$inner = 'INSERT INTO national_parks (name, location, date_established, area_in_acres, description) VALUES (:name, :location, :date_established, :area_in_acres, :description)';
$query = $dbc->prepare($inner);
$query->bindValue(':name', $name, PDO::PARAM_STR);
$query->bindValue(':location', $location, PDO::PARAM_STR);
$query->bindValue(':date_established', $date, PDO::PARAM_INT);
$query->bindValue(':area_in_acres', $area, PDO::PARAM_INT);
$query->bindValue(':description', $description, PDO::PARAM_STR);
$query->fetchAll(PDO::FETCH_ASSOC);
$query->execute();
}
示例9: insertPark
function insertPark($dbc)
{
$errors = [];
try {
$park = Input::has('park') ? Input::getString('park') : null;
} catch (Exception $e) {
array_push($errors, $e->getMessage());
}
try {
$location = Input::has('location') ? Input::getString('location') : null;
} catch (Exception $e) {
array_push($errors, $e->getMessage());
}
try {
$date_established = Input::has('date_established') ? Input::getDate('date_established') : null;
$date_established = $date_established->format('Y-m-d');
} catch (Exception $e) {
array_push($errors, $e->getMessage());
}
try {
$area_in_acres = Input::has('area_in_acres') ? Input::getNumber('area_in_acres') : null;
} catch (Exception $e) {
array_push($errors, $e->getMessage());
}
try {
$description = Input::has('description') ? Input::getString('description') : null;
} catch (Exception $e) {
array_push($errors, $e->getMessage());
}
if (!empty($errors)) {
return $errors;
}
$query = "INSERT INTO national_parks (park, location, date_established, area_in_acres, description) VALUES (:park, :location, :date_established, :area_in_acres, :description)";
$stmt = $dbc->prepare($query);
$stmt->bindValue(':park', $park, PDO::PARAM_STR);
$stmt->bindValue(':location', $location, PDO::PARAM_STR);
$stmt->bindValue(':date_established', $date_established, PDO::PARAM_STR);
$stmt->bindValue(':area_in_acres', $area_in_acres, PDO::PARAM_STR);
$stmt->bindValue(':description', $description, PDO::PARAM_STR);
$stmt->execute();
return $errors;
}
示例10: Park
Input::has('location')) {
$park = new Park();
try {
$park->name = Input::getString('name');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$park->area_in_acres = Input::getNumber('area_in_acres');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$park->date_established = Input::getDate('date_established');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$park->description = Input::getString('description');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$park->location = Input::getString('location');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
示例11: VALUES
require_once 'db_connect.php';
require_once 'Input.php';
if (isset($_GET['page'])) {
$page = $_GET['page'];
if ($page < 1) {
$page = 1;
}
} else {
$page = 1;
}
$limit = 4;
$offset = ($page - 1) * 4;
//prepare statements for user submissions
//A NOTE FROM THURSDAY: right now, the specific getDate/String/Number methods from Input class are only being applied at the user submission level. to update this, (remove these?? maybe not) add these to your PDO, or whatever it is called)
//note FROM THURSDAY CATCH LESSON: Push your errors onto an $errors[] array.
if (Input::has('nameSubmit') && Input::getString('nameSubmit') != "" && Input::has('acreageSubmit') && Input::getNumber('acreageSubmit') != "" && Input::getString('stateSubmit') && Input::has('stateSubmit') != "" && Input::getDate('date_estSubmit') && Input::has('date_estSubmit') != "" && Input::getString('descriptionSubmit') && Input::has('descriptionSubmit') != "") {
echo "THANK YOU FOR YOUR INPUT." . PHP_EOL;
$nameSubmit = $_POST['nameSubmit'];
$stateSubmit = $_POST['stateSubmit'];
$date_estSubmit = $_POST['date_estSubmit'];
$acreageSubmit = $_POST['acreageSubmit'];
$descriptionSubmit = $_POST['descriptionSubmit'];
$stmt = $connection->prepare("INSERT INTO national_parks (name, location, date_est, acreage, description) VALUES (:nameSubmit, :stateSubmit, :date_estSubmit, :acreageSubmit, :descriptionSubmit)");
$stmt->bindValue(':nameSubmit', $nameSubmit, PDO::PARAM_STR);
$stmt->bindValue(':stateSubmit', $stateSubmit, PDO::PARAM_STR);
$stmt->bindValue(':date_estSubmit', $date_estSubmit, PDO::PARAM_STR);
$stmt->bindValue(':acreageSubmit', $acreageSubmit, PDO::PARAM_STR);
$stmt->bindValue(':descriptionSubmit', $descriptionSubmit, PDO::PARAM_STR);
$stmt->execute();
}
//to convert a query statement to a prepare statement, change query to prepare and change $variable to :variable
示例12: COUNT
$limit = 4;
$pageID = Input::has('page') ? Input::get('page') : 1;
$offset = $limit * $pageID - $limit;
$stmt = $dbc->prepare("SELECT * FROM national_parks LIMIT :limit OFFSET :offset");
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();
$count = $dbc->query('SELECT COUNT(*) FROM national_parks;')->fetchColumn();
$parks = $stmt->fetchAll(PDO::FETCH_ASSOC);
$numPages = ceil($count / $limit);
$next = $pageID + 1;
$previous = $pageID - 1;
$newPark = [];
$errorMessage = "Add a Park!";
if (!empty($_POST)) {
if (Input::getString('name') && Input::getString('url') && Input::getString('location') && Input::getDate('date_established') && Input::getNumber('area_in_acres') && Input::getString('description')) {
$newPark = $dbc->prepare("INSERT INTO national_parks(name, url, location, date_established, area_in_acres, description) \n\t\tVALUES(:name, :url, :location, :date_established, :area_in_acres, :description)");
$newPark->bindValue(':name', Input::get('name'), PDO::PARAM_STR);
$newPark->bindValue(':url', Input::get('url'), PDO::PARAM_STR);
$newPark->bindValue(':location', Input::get('location'), PDO::PARAM_STR);
$newPark->bindValue(':date_established', Input::get('date_established'), PDO::PARAM_STR);
$newPark->bindValue(':area_in_acres', Input::get('area_in_acres'), PDO::PARAM_STR);
$newPark->bindValue(':description', Input::get('description'), PDO::PARAM_STR);
$newPark->execute();
} else {
$errorMessage = 'To add a park please input all fields!';
}
}
$del = "DELETE FROM `national_parks` WHERE `id` = :id_to_delete";
?>
示例13: catch
$limit = 4;
$offset = $page * $limit - $limit;
if (Input::has('name') && Input::get('name') != '' && Input::has('location') && Input::get('location') != '' && Input::has('date_established') && Input::get('date_established') != '' && Input::has('area_in_acres') && Input::get('area_in_acres') != '' && Input::has('description') && Input::get('description') != '') {
try {
$parkname = Input::getString('name');
} catch (Exception $e) {
array_push($errorMessages, $e->getMessage());
// echo 'An error occurred: ' . $e->getMessage() . PHP_EOL;
}
try {
$parklocation = Input::getString('location');
} catch (Exception $e) {
array_push($errorMessages, $e->getMessage());
}
try {
$parkdate = Input::getDate('date_established');
} catch (Exception $e) {
array_push($errorMessages, $e->getMessage());
}
try {
$parksize = Input::getNumber('area_in_acres');
} catch (Exception $e) {
array_push($errorMessages, $e->getMessage());
}
try {
$parkdescr = Input::getString('description');
} catch (Exception $e) {
array_push($errorMessages, $e->getMessage());
}
if (empty($errorMessages)) {
$checkrow = 'SELECT id FROM national_parks WHERE name = :name';
示例14: catch
} catch (OutOfRangeException $e) {
$errors[] = $e->getMessage();
} catch (DomainException $e) {
$errors[] = $e->getMessage();
} catch (RangeException $e) {
$errors[] = $e->getMessage();
}
if ($_FILES) {
$uploadsDirectory = 'img/uploads/';
$filename = $uploadsDirectory . basename($_FILES['image_url']['name']);
if (!move_uploaded_file($_FILES['image_url']['tmp_name'], $filename)) {
$errors[] = "Sorry, there was an error uploading your file.";
}
}
try {
$sale_end_date = Input::getDate('sale_end_date');
} catch (Exception $e) {
$errors[] = $e->getMessage();
}
try {
$categories = Input::getString('categories');
} catch (InvalidArguementException $e) {
$errors[] = $e->getMessage();
} catch (OutOfRangeException $e) {
$errors[] = $e->getMessage();
} catch (DomainException $e) {
$errors[] = $e->getMessage();
} catch (LengthException $e) {
$errors[] = $e->getMessage();
}
try {
示例15: catch
$password = Input::getString('password');
} catch (Exception $e) {
$errors['password'] = $e->getMessage();
}
try {
$confirmPassword = Input::getString('confirm_password');
} catch (Exception $e) {
$errors['confirm_password'] = $e->getMessage();
}
try {
$email = Input::getString('email');
} catch (Exception $e) {
$errors['email'] = $e->getMessage();
}
try {
$dateTimeObject = Input::getDate('birth_date', new DateTime('1900-01-01'), new DateTime());
} catch (Exception $e) {
$errors['birth_date'] = $e->getMessage();
}
try {
$gender = Input::get('gender');
} catch (Exception $e) {
$errors['gender'] = $e->getMessage();
}
var_dump($errors);
$user = new User();
try {
if ($user->checkUsername($userName)) {
throw new Exception("Username has been taken");
}
} catch (Exception $e) {