生成composer.bat文件
echo @php “%~dp0composer.phar” %*>composer.bat
切换阿里云镜像
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
创建一个名字为shop,laravel版本为5.3的demo
composer create-project laravel/laravel shop 5.3.* --prefer-dist
在项目文件夹cmd输入,查看端口号
php artisan serve
在项目名文件夹下cmd输入,创建UserController控制器
php artisan make:controller UserController
在项目名文件夹下cmd输入,在admin文件夹下,创建控制器
php artisan make:controller admin/UserController
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新闻发布系统</title>
<link rel="stylesheet" href="./css/style.css" />
</head>
<body>
<div class="box">
<div class="top">
<div class="title">新闻发布系统</div>
<div class="nav">
<a href="./index.php">返回列表</a>
</div>
</div>
<div class="main">
<form method="post">
<table class="news-edit">
<tr>
<th>新闻标题:</th>
<td><input type="text" name="title" placeholder="填写新闻标题..." /></td>
</tr>
<tr>
<th>新闻内容:</th>
<td><textarea name="content" placeholder="填写新闻内容..."></textarea></td>
</tr>
<tr>
<th></th>
<td><input type="submit" value="发布新闻" /></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<?php
if(!empty($_POST)){
//1.获取新闻数据(表单)
//1)保持接收到数据
$data=array();
//2)保持带接收的字段
$fields=array('title','content');
//3)从表单中获取指定字段
foreach($fields as $value){
$data[$value]=$_POST[$value];
}
//2.连接mysql服务器(int.php)
include_once 'init.php';
//3.编写添加到语句
$sql='insert into new(Title,Content) values (:title,:content)';
//4执行sql语句
//1)准备好将要执行的sql语句
$stat= $pdo->prepare($sql);
//2)执行sql语句
if(!$stat->execute($data)){
//添加失败
exit('添加新闻失败');
}
else{
//添加成功,返回首页
header("location:index.php");
}
}
//5.载入html页面
require_once 'add.html'
?>
<?php
if(!empty($_POST)){
//1.获取新闻数据(表单)
//1)保持接收到数据
$data=array();
//2)保持带接收的字段
$fields=array('title','content');
//3)从表单中获取指定字段
foreach($fields as $value){
$data[$value]=$_POST[$value];
}
//2.连接mysql服务器(int.php)
include_once 'init.php';
//3.编写添加到语句
$sql='insert into new(Title,Content) values (:title,:content)';
//4执行sql语句
//1)准备好将要执行的sql语句
$stat= $pdo->prepare($sql);
//2)执行sql语句
if(!$stat->execute($data)){
//添加失败
exit('添加新闻失败');
}
else{
//添加成功,返回首页
header("location:index.php");
}
}
//5.载入html页面
require_once 'add.html'
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新闻发布系统</title>
<link rel="stylesheet" href="./css/style.css" />
</head>
<body>
<div class="box">
<div class="top">
<div class="title">新闻发布系统</div>
<div class="nav">
<a href="./index.php">返回列表</a>
</div>
</div>
<div class="main">
<form method="post">
<table class="news-edit">
<tr>
<th>新闻标题:</th>
<td><input type="text" name="title" value="<?php echo $data['Title'] ;?>" /></td>
</tr>
<tr>
<th>新闻内容:</th>
<td><textarea name="content"><?php echo $data['Content']; ?></textarea></td>
</tr>
<tr>
<th></th>
<td><input type="submit" value="修改新闻" /></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<?php
include_once 'init.php';
$id=$_GET['id'];
$data=array('id'=>$id);
//1)有表单提交时修改新闻
if($_POST){
//a.接受表单数据
$fields=array('title','content');
foreach($fields as $v){
$data[$v]=$_POST[$v];
}
//b.编写sql语句
$sql='update new set title=:title,content=:content where id=:id';
//c.执行sql
$stmt=$pdo->prepare($sql);
if(!$stmt->execute($data)){
//修改失败
exit('修改失败');
}
else{
//修改成功,返回首页index
header("location:index.php");
}
}
//2)没有表单时,查询数据并显示到表单中
$sql='select Title,Content from new where id=:id';
$stmt=$pdo->prepare($sql);
if(!$stmt->execute($data)){
//执行失败
exit('执行失败');
}
$data=$stmt->fetch(PDO::FETCH_ASSOC);
$data['Content'] = nl2br($data['Content']);
require './edit.html';
?>
<?php
//1、设置连接字符串
$dsn='mysql:host=localhost;dbname=website;charset=utf8';
//2、实例化pdo对象
try{
$pdo=new PDO($dsn,'root','');
}catch (Exception $e){
exit('pdo连接失败:'.$e->getMessage());
}
//echo $dsn;
?>
<?php
require 'init.php';
//获取待查看的新闻ID
$id = $_GET['id'];
$id = array('id'=>$id);
//根据ID到数据库中查询数据
$sql='select Title,Content,PubData from new where id=:id';
//执行SQL语句
$stmt = $pdo->prepare($sql);
if(!$stmt->execute($id)){
exit('查询失败');
}
//处理结果集
$data = $stmt->fetch(PDO::FETCH_ASSOC,true);
//如果$data为空数组,表示没有查询到数据,即新闻不存在
if(empty($data)){
exit('新闻ID不存在');
}
//新闻内容是来自<textarea>的数据,需要进行换行符转换
$data['Content']=nl2br($data['Content']);
require './show.html';
?>