当前位置: 首页>>代码示例>>PHP>>正文


PHP News::insertGetId方法代码示例

本文整理汇总了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');
             }
         }
     }
 }
开发者ID:ryujikun,项目名称:bridge,代码行数:70,代码来源:NewsController.php


注:本文中的app\News::insertGetId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。