blog-details

Học lập trinh web PHP basic sử dụng phần mêm ATCSMART gồm các bài sau.

1. Tạo chức năng các bảng dữ liệu

   + Dữ liệu trang web tin tức đơn giản BlogATC

Sau khi tạo chức năng theo ý trên phần mềm  thì chúng ta bấm genscript sql

Kết quả được như sau: Đối với MySQL hoặc MariaDB  thì dùng như bên dưới. Còn SQLSERVER Thì chọn tab khác

CREATE DATABASE BlogATC;

USE BlogATC; 
CREATE TABLE IF NOT EXISTS `roile` (
`id` int unsigned NOT NULL  AUTO_INCREMENT , 
`name` varchar (100) NULL, 
`status` bit NULL, 
`access` text NULL 
, INDEX(id), PRIMARY KEY(id))
ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `menu` (
`id` int unsigned NOT NULL  AUTO_INCREMENT , 
`name` varchar (150) NULL, 
`parent` int NULL, 
`sort` int NULL, 
`link` varchar (255) NULL, 
`status` bit NULL 
, INDEX(id), PRIMARY KEY(id))
ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `category` (
`id` int unsigned NOT NULL  AUTO_INCREMENT , 
`name` varchar (255) NULL, 
`sort` int NULL, 
`parrent` int NULL, 
`status` boolean NULL 
, INDEX(id), PRIMARY KEY(id))
ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `blog` (
`id` int unsigned NOT NULL  AUTO_INCREMENT , 
`name` varchar (255) NULL, 
`sort` int NULL, 
`images` varchar (255) NULL, 
`categoryid` int NULL, 
`description` varchar NULL, 
`status` boolean NULL, 
`content` text NULL, 
`datepost` date NULL 
, INDEX(id), PRIMARY KEY(id))
ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `user` (
`username` int NOT NULL, 
`name` varchar (50) NULL, 
`password` varchar (50) NULL, 
`roileid` int NULL 
, PRIMARY KEY(username))
ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `contact` (
`id` int unsigned NOT NULL  AUTO_INCREMENT , 
`name` varchar (255) NULL, 
`email` varchar (100) NULL, 
`phone` varchar (20) NULL, 
`message` text NULL, 
`status` boolean NULL, 
`datesend` date NULL 
, INDEX(id), PRIMARY KEY(id))
ENGINE=InnoDB;

 

2. Tạo và backup database  lên MYSQL

3. Bulding code và chọn mẫu.

 

4. Xuất code và cấu hình

Hình chọn đường dẫn xuất code

 

Hình 2. Code xuất ra cấu trúc thư mục như bên dưới

Hình 3. Cấu trúc admin

Hình 4. Các file index.php chức năng quản lý Blog

Hình 5. thêm mới chức năng Blog

<?php
			include '../layout/header.php';
			include '../../models/Dataprovider.php';

		 $cb_categoryid= Dataprovider::get_arr('SELECT * FROM Category');
		  if(isset($_GET['id'])& isset($_GET['action']))

		{		      if($_GET['action']=='edit')

		    {
			 $row= Dataprovider::get_detail("SELECT * FROM  `blog` WHERE id='".$_GET['id']."'");
			  $id=$row['id'];

			  $name=$row['name'];

			  $sort=$row['sort'];

			  $images=$row['images'];

			  $categoryid=$row['categoryid'];

			  $description=$row['description'];

			  $status=$row['status'];

			  $content=$row['content'];

			  $datepost=$row['datepost'];

			   }
			 }
		  if(isset($_POST['submit']))

			{
			if(isset($_POST['id'])&isset($_POST['name'])&isset($_POST['sort'])&isset($_POST['images'])&isset($_POST['categoryid'])&isset($_POST['description'])&isset($_POST['status'])&isset($_POST['content'])&isset($_POST['datepost']))

			 {			   $id=$_POST['id'];
			   $name=$_POST['name'];
			   $sort=$_POST['sort'];
			   $images=$_POST['images'];
			   $categoryid=$_POST['categoryid'];
			   $description=$_POST['description'];
			   $status=$_POST['status'];
			   $content=$_POST['content'];
			   $datepost=$_POST['datepost'];

			   $sql= "UPDATE `blog` SET id='{$id}',name='{$name}',sort='{$sort}',images='{$images}',categoryid='{$categoryid}',description='{$description}',status='{$status}',content='{$content}',datepost='{$datepost}' WHERE id='{$id}'";
			   Dataprovider::Executequery($sql);
 			/*thực thi câu lệnh update sql*/

			 // header('Location: edit.php?action=edit&id='.$id);
			 // echo "<script>alert('Đã cập nhật thành công');window.location.href='admin/user/edit.php?action=edit&id=$id'; </script>";
			  header('Location: index.php');
			 }
		}
		 ?>
<div class='breadcrumbs-fixed panel-action'>
        <div class='row'>
            <div class='products-act'>
                <div class='col-md-4 col-md-offset-2'>
                    <div class='left-action text-left clearfix'>
                        <h2><i class='fa fa-refresh' style='font-size: 14px; cursor: pointer;'> </i> Cập nhật blog</h2>
                    </div>
                </div>
                <div class='col-md-6'>
                    <div class='right-action text-right'>
                        <div class='btn-groups'>
                            <button type='submit' class='btn btn-primary' onclick="Saveas('save');"><i class='fa fa-check'></i> Lưu
                            </button>
                            <button type='button' class='btn btn-primary' onclick="Saveas('');"><i class='fa fa-floppy-o'></i> Lưu
                                và tiếp tục
                            </button>
                            <button type='button' class='btn btn-default' onclick="window.location.href='admin/blog/index.php'">
<i class='fa fa-arrow-left'></i> Trở về
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	<div class='products-content' style='margin-bottom: 25px;'>  <form action="admin/blog/edit.php" method="post">
            <table id="blog_tb"   style='width:95%; '> <tr>
                <td class="right title_pro">id:</td>
                <td colspan="4" style=''><input  placeholder="" class="form-control" id="id" name="id"  readonly='' value='<?php if(isset($id)) echo $id; ?>' type="text" >

               </td>
              </tr> <tr>
                <td class="right title_pro">name:</td>
                <td colspan="4" style=''><input  placeholder="" class="form-control" id="name" name="name"  value ='<?php if(isset($name)) echo $name; ?>' required="required" type="text" >

               </td>
              </tr> <tr>
                <td class="right title_pro">sort:</td>
                <td colspan="4" style=''><input  placeholder="" class="form-control" id="sort" name="sort"  value ='<?php if(isset($sort)) echo $sort; ?>' required="required" type="text" >

               </td>
              </tr> <tr>
                <td class="right title_pro">images:</td>
                <td colspan="4" style=''><input id="images" name="images" value="" placeholder="<?php if(isset($images)) echo $images; ?>" type="text" required="required"  ><input onclick="BrowseServer('/','images')" style="width: 70px;padding: 3px;" type="button" value="Chọn hình" readonly="readonly"> 

               </td>
              </tr> <tr>
                <td class="right title_pro">categoryid:</td>
                <td colspan="4" style=''><select  class="form-control" name="categoryid" id="categoryid" required="required"  style="padding: 5px;width: 250px;"><?php

                if(isset($cb_categoryid))
				{
                   echo " <option value='0'> Chọn categoryid </option>";
				     foreach ($cb_categoryid  as $value){ ?>
				   <option  
				<?php if( isset($_POST['categoryid']))
				  { if($categoryid ==$value['id']) echo "selected = 'selected'"; } 
                  ?>
                  value = "<?=$value['id'] ?>" >
   
                   <?=$value['id'] ?>
   
                   </option>
   
                   <?php }
            }?> </select>

               </td>
              </tr> <tr>
                <td class="right title_pro">description:</td>
                <td colspan="4" style=''><textarea class="form-control" id="description" required="required" name="description" cols="20" rows="2"><?php if(isset($description)) echo $description; ?></textarea>

               </td>
              </tr> <tr>
                <td class="right title_pro">status:</td>
                <td colspan="4" style=''><input  placeholder="" class="form-control" id="status" name="status"  value ='<?php if(isset($status)) echo $status; ?>' required="required" type="text" >

               </td>
              </tr> <tr>
                <td class="right title_pro">content:</td>
                <td colspan="4" style=''><textarea  class="form-control" id="content" name="content" placeholder="required="required"" ><?php if(isset($content)) echo $content; ?></textarea>
<script type='text/javascript'>
            	    CKEDITOR.replace( 'content',{
            	    height : 150
            		
            	});		
            </script>
               </td>
              </tr> <tr>
                <td class="right title_pro">datepost:</td>
                <td colspan="4" style=''><input type="date"  id="datepost" name="datepost" class="form-control input-sm " value="<?php if(isset($datepost)) echo $datepost; ?>" required="required"> 

               </td>
              </tr><tr>
                <td colspan='6' style='text-align: center;' id='end_p'>
                    <button class='btn btn-primary' style='width: 120px;' id='saveas' name='submit' type='submit' value=''>
					<i class='fa fa-floppy-o'></i>  Cập nhật</button> <input class='btn btn-primary'  style='width: 100px;' type='reset' value='Nhập lại'/>
                    <a href='admin/blog/index.php'>
                        <input class='btn btn-primary' style='width: 100px;' type='button' value='Quay lại'/>
                    </a>
                  
                    
                </td>
              </tr></table></form> <script>

         function Saveas(c)
         {
			
			 $('#saveas').click();
          }

         </script></div>
<?php include '../layout/footer.php';?>

   Hình 6.Code file edit.php như sau

 

5. Chạy demo và triển khai đăng nhập quản lý

Hình 1. Trang đăng nhập mặc định

Hình 2 . Trang bảng điều khiền dashboard

Hình 3. quản lý menu

Hình4 . Thêm Menu

Hình 5. Thêm Blog mới

 

6. Cập nhật chỉnh sửa theo ý 1 số mục cần thiết.

7. Hoàn thiện

8. Đưa lên hosting domain

 

----Nội dung đang được tiếp tục cập nhật----

Đánh giá bài viết