tp5 入门项目之 blog

本博客为学习tp的练习项目的笔记。方便日后查找需要。

------------------------------------------------------------------------------------------------------

{if condition="empty($auders->toArray()['data'])"}<tr><td align="center" colspan="9">暂无相关数据!</td></tr>{/if}

---------------------------------------------------------------------------------------------------------------------------------

一 开发准备,环境搭建

1 phpstudy中站点域名配置中配置项目信息

自动生成的配置

<VirtualHost *:80>
    DocumentRoot "E:\myphp_www\PHPTutorial\WWW\xl_blog\public"
    ServerName my.blog.com
    ServerAlias
  <Directory "E:\myphp_www\PHPTutorial\WWW\xl_blog\public">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
     Require all granted
  </Directory>
</VirtualHost>

2 下载 tp5源码 完全开发手册 跟快速开发手册。tp5项目部署至服务器下。访问域名,可以得到笑脸。说明配置成功。

二 静态文件引入

1 前后台静态资源文件引入

把资源文件放到 public/static 文件目录下

--------------------------------------------------------

index入口文件中定义 相关路径信息

//定义网站域名

define('WEB_URL', 'http://my.blog.com/');

//定义前台 js css font 路径

define('HOME_STYLE',WEB_URL.'static/home/');

--------------------------------------------------------

index 模块中 创建本模块配置文件 config.php

配置路径信息,以便在模板文件中使用。配置信息如下

<?php

return [

'view_replace_str' => [

"__HOMECSS__" => HOME_STYLE.'style/',

],

];

----------------------------------------------------------

index 模块中,分离出公共的头部 侧边栏 尾部信息

公共文件中使用刚才配置的变量,引入静态资源文件

------------------------------------------------------------------------

模板中调用刚才创建的公共模块数据

--------------------------------------------------------

http://my.blog.com/index/lst

http://my.blog.com/index/article

http://my.blog.com/index/index 进行访问

 --------------------------------------------------

文件上传

if($_FILES['pic']['tmp_name']){

$file = request()->file('pic');

$info = $file->move(ROOT_PATH . 'public' . DS . 'static/uploads');

$data['pic']='/uploads/'.$info->getSaveName();

}

----------------------------------------------------

模板文件中 volist 循环

模板文件中 if 判断

模板文件中 时间戳转换

 ---------------------------------------------------

验证码的具体实现

 

 -------------------------------------------------------------

简单的权限拦截

 ------------------------------------------------------------------------------

模板中 时间戳转化成时间

<td align="center">{$person.createtime|date='Y-m-d',###}</td>

-----------------------------------------------------------------------------------

公共函数库,其中的方法可以直接在本模块中调用

--------------------------------------------------------

admin模块下 配置文件

-------------------------------------------------------

数据校验

<?php

namespace app\admin\validate;

use think\Validate;

class Admin extends Validate

{

protected $rule = [

'username' => 'require|max:25|unique:admin',

'password' => 'require',

];

 

protected $message = [

'username.require' => '管理员名称必须填写',

'username.max' => '管理员名称长度不得大于25位',

'username.unique' => '管理员名称不得重复',

'password.require' => '管理员密码必须填写',

 

];

 

protected $scene = [

'add' => ['username'=>'require|unique:admin','password'],

'edit' => ['username'=>'require|unique:admin'],

];

}

文件中调用校验规则

    $id=input('id');

    $cates=db('cate')->find($id);

    if(request()->isPost()){

        $data=[

            'id'=>input('id'),

            'catename'=>input('catename'),

        ];

            $validate = \think\Loader::validate('cate');

        if(!$validate->scene('edit')->check($data)){

             $this->error($validate->getError()); die;

            }

-------------------------------------------

搜索页面分页的实现

public function index()

{

$keywords=input('keywords');

if($keywords){

$map['title']=['like','%'.$keywords.'%'];

$searchres=db('article')

->where($map)->order('id desc')

->paginate($listRows = 3, $simple = false, $config = [

'query'=>array('keywords'=>$keywords),

]);

$this->assign(array(

'searchres'=>$searchres,

'keywords'=>$keywords

));

}else{

$this->assign(array(

'searchres'=>null,

'keywords'=>'暂无数据'

));

}

 

return $this->fetch('search');

}

-------------------------------------

入口文件

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liu709127859

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值