本文整理匯總了PHP中app\News::insertGetId方法的典型用法代碼示例。如果您正苦於以下問題:PHP News::insertGetId方法的具體用法?PHP News::insertGetId怎麽用?PHP News::insertGetId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\News
的用法示例。
在下文中一共展示了News::insertGetId方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: create
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
if (Auth::user()->role_id == 1 || Auth::user()->role_id == 2) {
if (Request::isMethod('get')) {
return View::make('admin.news.create');
} else {
if (Request::isMethod('post')) {
$data = Input::all();
date_default_timezone_set('Asia/Jakarta');
// CDT
$current_date = date('Y-m-d');
$name = $_FILES['imginp']['name'];
$test = pathinfo($name, PATHINFO_FILENAME);
$target_dir = "news/";
$original_name = $test;
$imageFileType = pathinfo($name, PATHINFO_EXTENSION);
//$target_file = $target_dir . basename($_FILES["imginp"]["name"]);
$uploadOk = 1;
// Check if image file is a actual image or fake image
if (isset($_POST["submit"])) {
$check = getimagesize($_FILES["imginp"]["tmp_name"]);
if ($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if file already exists
$i = 1;
while (file_exists($target_dir . $test . "." . $imageFileType)) {
$test = (string) $original_name . $i;
$name = $test . "." . $imageFileType;
$i++;
}
$target_file = $target_dir . $name;
// Check file size
if ($_FILES["imginp"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["imginp"]["tmp_name"], $target_file)) {
echo "The file " . basename($_FILES["imginp"]["name"]) . " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$target_file_final = "../../" . $target_file;
News::insertGetId(array('judul' => $data['judul'], 'konten' => $data['konten'], 'tanggal' => $current_date, 'gambar' => $target_file_final, 'users_id' => Auth::user()->id));
return redirect('admin/news');
}
}
}
}