blog

ThinkPHP5——模型(model)的使用

人盡茶涼 提交于 2019-12-03 15:19:38
在使用ThinkPHP5的过程中,我经常使用db进行数据库操作的,后来接触到了模型(model),刚使用时感觉跟db没啥区别,后来查官网知道模型基类中还提供了较多的其他的方法可以方便使用例如获取器、修改器、数据完成等等功能。 因此模型的功能更为强大, tp5官网推荐使用model。 就数据格式而言,在DB中是采用的数组格式使用。而在模型中统一使用对象。其中数据库交互后涉及到格式转换。因此在同等情况下db的数据略快与模型方式。 因此对于ThinkPHP5使用DB与model的方式具体在编程中选择哪一个按照个人的观点并无强制要求。有时候为了项目中的封装采用模型方式可能更为合适一些 1、模型定义 在model定义一个Blog模型类: <?php namespace app\demo\model; use think\Model; class Blog extends Model { //默认主键为自动识别,如果需要指定,可以设置属性: //protected $pk = 'uid'; } 模型会自动对应数据表,模型类的命名规则是除去表前缀的数据表名称,采用驼峰法命名,并且首字母大写,例如: 模型名 约定对应数据表(假设数据库的前缀定义是 think_) User think_user UserType think_user_type 2、模型调用 模型类可以使用 静态调用 或者

Django后台admin的使用详解

烈酒焚心 提交于 2019-12-03 13:10:52
简述: Django的admin可以提供一个强大的后台管理功能,可以在web界面对数据库进行操作,我们需要修改admin.py将要操作的数据表注册到后台管理中. 一,新建一个 名称为 zqxt_admin 的项目: ? 1 django - admin.py startproject zqxt_admin 二,新建一个 叫做 blog 的app: ? 1 2 3 4 5 # 进入 zqxt_admin 文件夹 cd zqxt_admin # 创建 blog 这个 app python manage.py startapp blog 三,修改 blog 文件夹中的 models.py: ? 1 2 3 4 5 6 7 8 9 10 # coding:utf-8 from django.db import models class Article(models.Model): title = models.CharField(u '标题' , max_length = 256 ) content = models.TextField(u '内容' ) pub_date = models.DateTimeField(u '发表时间' , auto_now_add = True , editable = True ) update_time = models.DateTimeField(u

自己写了一个多行文本溢出文字补全的小库, 说不定你会用得到的

a 夏天 提交于 2019-12-03 10:23:18
本文转载于: 猿2048 网站➵ https://www.mk2048.com/blog/blog.php?id=i2ka1cji2j 有些时候产品会有这么个需求,希望给文章或者帖子给一个摘要,最多3行,或者其它行数,超出3行会补上'...'。当然这种很简单,用css可以搞定。但是遇上要求多点的产品,希望补上的是'...查看全文',这样的话就难办了。 我也在网上查了很多,至少我没发现有一个比较好的解决方案,也参考了微博和知乎的信息流,发现它们可能是根据文字的个数来算的,因为并没有看到有那种 刚好'阅读全文'这4个字就处于最后一行的末尾。 微博效果: 知乎效果: 因此自己也鼓捣了一番,终于勉强搞出了自己一个还算比较满意的小库。 整体的思路还是算每个字的宽度来计算出有多少行。因为web前端还是没有办法直接得到文本到底有多少行,所以这个计算还是比较麻烦。用的小技巧就是把每个字都包裹一个行内标签,计算这个行内标签的宽度。 我自己的项目效果: 项目已经放在github上了,npm上也已发布了,搜 text-overflow 即可 项目地址 demo地址 希望喜欢的同学,或者用的到的同学可以用起来,有问题也可以给我提issue,也别忘了给我的项目点star哦, 这样我会继续更新下去的。 来源: https://www.cnblogs.com/qianduanwriter/p/11790905

nginx reverse proxy from rails to wordpress

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Ruby on Rails application and a Wordpress blog hosted on separate EC2 instances. I'm trying to make the Wordpress blog to act like a subfolder of the Rails application (example.com/blog instead of blog.example.com) for better SEO The Rails application can be accessed through http and https (http is redirecting to https) https://www.nginx.com/resources/admin-guide/reverse-proxy/ I tried using nginx reverse proxy function and I think it's my best option right now but my attempt was unsuccessful. The main page of the blog opens as

Having huge redirect list in .htaccess a Problem?

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to redirect every post 301 redirect, but I have over 3000 posts. If I list Redirect permanent / blog / 2010 / 07 / post . html http : //new.blog.com/2010/07/23/post/ Redirect permanent / blog / 2010 / 07 / post1 . html http : //new.blog.com/2010/07/24/post1/ Redirect permanent / blog / 2010 / 07 / post2 . html http : //new.blog.com/2010/07/25/post2/ Redirect permanent / blog / 2010 / 07 / post3 . html http : //new.blog.com/2010/07/26/post3/ Redirect per ...... for over 3000 url redirect command in .htaccess would this eat my

品优购(IDEA版)-第一天

我们两清 提交于 2019-12-03 08:37:18
# 品优购(IDEA版)-第一天 品优购IDEA版应该是2019年的新项目。目前只有视频。资料其他都还是旧的。 ## 1.学习目标 1:了解电商行业特点以及理解电商的模式 2:了解整体品优购的架构特点 3:能够运用 Dubbo+SSM 搭建分布式应用 4:搭建工程框架,完成品牌列表后端代码 ## 2. 电商概述 ## 3. 品优购需求分析与设计 ### 3.1. 品优购简介 品优购商城主要分为网站前台、网站后台、商家后台三类系统。 #### 3.1.1. 网站前台 主要包括网站首页、商家首页、商品详情、搜索、会员中心、订单与支付相关页面、秒杀频道等。 ![在这里插入图片描述](https://img2018.cnblogs.com/blog/756375/201911/756375-20191103021804323-1727543117.png) #### 3.1.2. 网站后台 运营该电商平台的运营人员的管理后台。 主要包括商家审核、品牌管理、规格管理、模板管理、商品分类管理、商品审核、广告类型管理、广告管理、订单查询、商家结算等。 ![在这里插入图片描述](https://img2018.cnblogs.com/blog/756375/201911/756375-20191103021806534-1852194779.png) #### 3.1.3. 商家管理后台

Servlet Real Path

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am running a webapp under the directory blog. (e.g. www.example.com/blog). I would like to get the real filesystem path of a request. e.g. www.example.com/blog/test-file.html -> /usr/share/tomcat7/webapps/blog/test-file.html I tried the following: public String realPath ( HttpServletRequest request , ServletContext servletContext ){ String requestURI = request . getRequestURI (); String realPath = servletContext . getRealPath ( requestURI ); return realPath ; } However this returns /usr/share/tomcat7/webapps/blog/blog/test-file

ActiveModel::ForbiddenAttributesError + cancan + rails 4 + model with scoped controller

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I m using cancan(1.6.10) with rails 4.0.0. I have a model called 'App'(not scoped) and a controller Admin::AppsController(its scoped. ie app/controllers/admin/apps_controller). the controller code is as class Admin::AppsController < ApplicationController before_filter :authenticate_user! load_and_authorize_resource class: App def index end #CRUD methods and some other custom methods ... private def app_params params.require(:app).permit(:name, :description, :author, :url_path, :validated, :active, :version) end end I m getting error when i

blog: Spring Boot - Actuator Web 访问开启

北城余情 提交于 2019-12-03 06:49:30
1. 概述 打开 Spring Boot Actuator 的 Web 访问 2. 场景 之前看 Spring 的时候, 曾经想了解当时的配置 后来发现, 确实有这么个工具 刚开始发现, 除了 actuator, 别的也看不了什么 3. 环境 os win10 jdk 1.8 ide ida 2018.1 spring spring boot 2.0.4 release 组件 thymeleaf starter-web devtool starter-test actuator browser firefox 70.0 ref spring boot in action 4. 问题 参考书 ref spring boot in action 书上说 书上列了一堆 url 感觉可以看很多事 问题 我试了一圈, 就 3 个 url 能用 \actuator \health \info 但是书上给我的感觉, 好像都是配上就好了 也不知道为啥 又要开始找开关 5. 解决 尝试找 官方文档 找到了 api ref Spring Boot Actuator: Production-ready features 看到了 清一色的 Yes 我陷入了沉思 为啥我就脸黑老是 再往下看 发现了另一个表格 发现 yes 的都是 jmx 而 web 那块, 又都是 清一色的 no 好了, 确认是配置没开

Locks in Java(翻译blog)

别来无恙 提交于 2019-12-03 05:55:15
###翻译自 [Jakob Jenkov]( http://tutorials.jenkov.com/java-concurrency/locks.html#simple-lock from Java 5 the package java.util.concurrent.locks contains several lock implementations, so you may not have to implement your own locks. But you will still need to know how to use them, and it can still be useful to know the theory behind their implementation. For more details, see my tutorial on the java.util.concurrent.locks.Lock interface. //JAVA5以来,在java.util.concurrent.locks包中提供了若干种锁的实现,所以所以你可能不必实现你自己的锁。但是你需要知道如何使用它们,并且知道实现后面的原理。通过下面的代码块,看我关于锁的教程。 A Simple Lock Let's start out by looking at a