本文整理汇总了PHP中Items::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Items::create方法的具体用法?PHP Items::create怎么用?PHP Items::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Items
的用法示例。
在下文中一共展示了Items::create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
if (!empty($_POST['itemid']) && !empty($_POST['itemname']) && !empty($_POST['qty'])) {
$newItem = new Items();
if (isset($_FILES['fupload']) && $_FILES['fupload']['error'] == 0) {
//if file upload is set
move_uploaded_file($_FILES['fupload']['tmp_name'], "public/uploads/" . basename($_FILES['fupload']['name']));
$image = new Imageresize();
// an instance of image resize object
$image->load("public/uploads/" . basename($_FILES['fupload']['name']));
//$image->image =;
$image->resize(400, 400);
$image->save("public/uploads/" . basename($_FILES['fupload']['name']));
//this section is needed to get the extension for image type in renaming the image
if ($_FILES['fupload']['type'] == "image/gif") {
$ext = ".gif";
}
if ($_FILES['fupload']['type'] == "image/png") {
$ext = ".png";
}
if ($_FILES['fupload']['type'] == "image/jpeg") {
$ext = ".jpeg";
}
if ($_FILES['fupload']['type'] == "image/pjpeg") {
$ext = ".jpeg";
}
if ($_FILES['fupload']['type'] == "image/gif") {
$ext = ".gif";
}
if ($_FILES['fupload']['type'] == "image/jpg") {
$ext = ".jpg";
}
$new_name = uniqid() . "_" . time() . $ext;
//new name for the image
rename("public/uploads/" . basename($_FILES['fupload']['name']), "public/uploads/" . $new_name);
$photo = $new_name;
$applicant->img_url = $photo;
} else {
//$applicant->img_url = $_POST['imgvalue'];
}
$newItem->item_id = $_POST['itemid'];
$newItem->item_name = $_POST['itemname'];
$newItem->item_description = $_POST['descript'];
$newItem->item_type = $_POST['ttype'];
$newItem->item_cost = $_POST['cprice'];
$newItem->item_quantity = $_POST['qty'];
$newItem->item_isbn = $_POST['isbn'];
$newItem->item_serial = $_POST['serial'];
$newItem->item_dateadded = date("Y-m-d H:i:s");
if ($newItem->create()) {
return 1;
//returns 1 on success
} else {
return 2;
// returns 2 on insert error
}
} else {
return 3;
//returns 3 if requiered input field is not supplied
}
}
示例2: json_encode
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// load the items class
require_once '../classes/concertClass.php';
$response = array('error' => true, 'message' => '');
if (isset($_POST['name'])) {
$name = $_POST['name'];
$items = new Items();
// create the new item
if ($data = $items->create($name)) {
$response['error'] = false;
$response['message'] = 'Items has been created';
$response['item'] = $data;
} else {
$response['message'] = 'Could not create the new item';
}
}
// request response in json format
echo json_encode($response);
示例3: create
/**
* @name create
* @description create a new item
* @param string $name
* @return mixed
*/
private function create($name)
{
$item = new Items();
if ($data = $item->create($name)) {
return $this->response($data, 'New item has been created', false);
}
return $this->response('', 'Could not create a new item', true);
}