thinkphp5项目--个人博客(五)

项目地址

fry404006308/personalBlog: personalBlog
https://github.com/fry404006308/personalBlog

后台操作完成的差不多了,下面开始前台操作

一、数据库数据分配到前台

在后台设置好的数据分配到前台

后台数据

数据库数据

前台数据

下面讲如何操作

控制器中得到数据并分配数据

 <?php
namespace app\index\controller; use think\Controller;
use think\Db;
class Index extends controller
{
public function index()
{
//得到数据,并且分配
$cateres = Db::name('cate')->order('id asc')->select();
$this->assign('cateres',$cateres); return view();
}
}

视图页面显示数据

                         {volist name="cateres" id="value"}
<a href="{:url('cate/index',array('cateid'=>$value['id']))}" rel='dropmenu209'>{$value.catename}</a>
{/volist}

可以写一个基类,然后其它类继承这个基类来完成对数据的分配。

二、文章的分类显示

之前的页面传递的数据

                         <a href="{:url('index/index')}"  rel='dropmenu209'>首页</a>
{volist name="cateres" id="value"}
<a href="{:url('cate/index',array('cateid'=>$value['id']))}" rel='dropmenu209'>{$value.catename}</a>
{/volist}

控制器

     public function index()
{
$cateid=input('cateid');
$articleres=db('article')->where(array('cateid'=>$cateid))->paginate(1);
$this->assign('articleres',$articleres);
return view();
}

视图

     <div class="left">

         {volist name="articleres" id="value"}
<div class="xnews2">
<div class="pic">
<a target="_blank" href="20160920156216.html">
<img src="{if condition="$value['pic'] neq '' "}__IMG__{$value.pic} {else /}__PUBLIC__/images/error.png{/if} " alt="{$value.title}"/>
</a>
</div>
<div class="dec">
<h3><a target="_blank" href="20160920156216.html">{$value.title}</a></h3>
<div class="time">发布时间:{$value.time|date="Y-m-d",###}</div>
<p>{$value.desc}</p>
<div class="time"><a href='z97712.html'>聚餐</a> </div>
</div>
</div>
{/volist} <div class="pages">
<div class="plist" >
{$articleres->render()}
</div>
</div>
</div>

三、文章浏览量自动增加

每访问一次这个方法就会让这个文章的访问量自动增加一次

 <?php
namespace app\index\controller; use app\index\controller\Base;
class Article extends Base
{
public function index()
{
$arid=input('arid');
$articleres=db('article')->find($arid);
//访问一次这个方法,说明文章被访问一次,让文章的click字段值加1
db('article')->where('id','=',$arid)->setInc('click');
$cateres=db('cate')->find($articleres['cateid']);
$this->assign(array(
'articleres'=>$articleres,
'cateres'=>$cateres,
)); return view();
}
}

thinkphp手册参考

 自增或自减一个字段的值
setInc/setDec 如不加第二个参数,默认值为1 // score 字段加 1
Db::table('think_user')
->where('id', 1)
->setInc('score');
// score 字段加 5
Db::table('think_user')
->where('id', 1)
->setInc('score', 5);
// score 字段减 1
Db::table('think_user')
->where('id', 1)
->setDec('score');
// score 字段减 5
Db::table('think_user')
->where('id', 1)
->setDec('score', 5);

四、mysql默认初始值

改紫色框框的位置,而不是下面的zerofill

五、多个数据需要分配到页面的时候,可用数组方式

         $this->assign(array(
'articleres'=>$articleres,
'cateres'=>$cateres,
));

六、别人网站上面的效果能完全弄下来

CSS和JS的话可以直接弄下来,打开网站源代码点CSS和JS的链接,就可以全部弄下来,或者直接用在线的,link地址就写他们网站就好

就是你看到的源代码的部分是已经执行过逻辑的部分了,所以逻辑部分你是看不到的,比如说php逻辑部分。

七、article部分完成

控制器

 <?php
namespace app\index\controller; use app\index\controller\Base;
class Article extends Base
{
public function index()
{
$arid=input('arid');
$articleres=db('article')->find($arid);
//访问一次这个方法,说明文章被访问一次,让文章的click字段值加1
db('article')->where('id','=',$arid)->setInc('click');
$cateres=db('cate')->find($articleres['cateid']);
$this->assign(array(
'articleres'=>$articleres,
'cateres'=>$cateres,
)); return view();
}
}

视图

         <!--顶部通栏-->
<script src='/jiehun/goto/my-65547.js' language='javascript'></script> <div class="position"><a href="{:url('index/index')}}">主页</a> > <a href="{:url('cate/index',array('cateid'=>$cateres['id']))}">{$cateres.catename}</a> > </div> <div class="overall">
<div class="left">
<div class="scrap">
<h1>{$articleres.title}</h1>
<div class="spread">
<span class="writor">发布时间:{$articleres.time|date='Y-m-d',###}</span>
<span class="writor">编辑:{$articleres.author}</span>
<span class="writor">标签:<a href='/jiehun/z97712.html'>聚餐</a></span>
<span class="writor">热度:{$articleres.click}</script></span>
</div>
</div> <!--百度分享-->
<script src='/jiehun/goto/my-65542.js' language='javascript'></script> <div class="takeaway">
<span class="btn arr-left"></span>
<p class="jjxq">{$articleres.desc}
</p>
<span class="btn arr-right"></span>
</div> <script src='/jiehun/goto/my-65541.js' language='javascript'></script>
<!-- 文章主体 -->
<div class="substance">
{$articleres.content}
</div>
<!-- end文章主体 -->

八、给页面传不同的参数,就可以得到不同的页面

<div class="position"><a href="{:url('index/index')}}">主页</a> > <a href="{:url('cate/index',array('cateid'=>$cateres['id']))}">{$cateres.catename}</a> >  </div>

九、thinkphp标签带函数(比如传给页面的是时间戳,要通过在页面电泳date函数显示正常时间)

<span class="writor">发布时间:{$articleres.time|date='Y-m-d',###}</span>

thinkphp5项目--个人博客(五)的更多相关文章

  1. thinkphp5项目--个人博客(七)

    thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  2. thinkphp5项目--个人博客(四)

    thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  3. thinkphp5项目--个人博客(三)

    thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  4. thinkphp5项目--个人博客(一)

    thinkphp5项目--个人博客(一) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  5. thinkphp5项目--个人博客(八)

    thinkphp5项目--个人博客(八) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  6. thinkphp5项目--个人博客(六)

    thinkphp5项目--个人博客(六) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  7. thinkphp5项目--个人博客(二)

    thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  8. RSP小组——团队冲刺博客五

    RSP小组--团队冲刺博客五 冲刺日期:2018年12月17日 前言 周末的结束,我们并没有完全的休息,对于这个项目,以我们的实力还是需要花费更多的时间. 各成员今日(12.17)完成的任务 马瑞蕃由 ...

  9. 2015-2016-2 《Java程序设计》项目小组博客

    2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...

随机推荐

  1. Apache Tez on hive

    ———————————————————— 调配 Hadoop  ———————————————————— 1 将 编译好的 TEZ .tar.gz 文件上传到 HDFS 中.   hdfs fs -p ...

  2. Ubuntu系统的Redis安装配置

    Ubuntu系统的Redis安装配置 一.      安装Redis: 在Ubuntu系统下安装Redis数据库有两种方式: 方式一:下载最新的Redis版本(tar.gz格式),解压安装.操作如下: ...

  3. CSS学习(五)

    导航栏 熟练使用导航栏,对于任何网站都非常重要. 使用CSS你可以转换成好看的导航栏而不是枯燥的HTML菜单. 导航栏=链接列表 作为标准的HTML基础一个导航栏是必须的.在我们的例子中我们将建立一个 ...

  4. [AngularJS]Chapter 4 AngularJS程序案例分析

    前边讲的都是基础.本章看看他们怎么合作的. 我们要建一个程序.一次一步.章末结束 [这个程序] GutHub是一个简单的菜谱管理程序.功能是存好吃的的菜谱并提供步骤.这个程序包含: 两列布局 左边是导 ...

  5. we标签

    功能: ·        辅助标签.配合其它标签使用,防止与标准html标签冲突 ·        别名为test 使用方法: <we [name=key]>[value]</we& ...

  6. dom 编程(html和xml)

    html dom与xml dom关系: 什么是 DOM? DOM 是 W3C(万维网联盟)的标准. DOM 定义了訪问 HTML 和 XML 文档的标准: "W3C 文档对象模型 (DOM) ...

  7. 关于iOS7中UIView效果失效问题的解决

    最近想做一个跑马灯的效果.于是写出了例如以下的跑马灯效果的代码...可是调试发现,在iOS6下动画是能够运行的,可是在iOS7下动画并不运行,没有达到预期的效果. [_scrollLabel size ...

  8. iOS开发- 生成/解析.vcf文件

    vcf, 通讯录导出的一种格式. 一.生成vcf文件 假设要把我们iPhone通讯录里的数据, 生成vcf格式文件. 我们能够借助iCloud. 小技巧:通过iCloud导出iPhone通讯录的方法 ...

  9. swoole-tcp-server

    swoole-tcp-server 标签(空格分隔): php,linux 执行程序 php swoole_server.php 查看端口:netstat -antpl 连接服务器:telnet ip ...

  10. xBIM 基础05 3D墙案例

    系列目录    [已更新最新开发文章,点击查看详细]  使用编码的形式去生成一堵墙的模型需要做很多的工作. using System; using System.Collections.Generic ...