#438
展开↯#440
展开↯#441
作者:广西南宁市
老板发工资给我,不是因为我为公司做事,而是因为我为了这份工作,没能为自己做事。
不是因为公司得到了什么,而是因为我失去了什么。
所以公司给我的那份工资,严格来说不是工资,是赔偿。
其中分别就是,你出粮给我,我要多谢你。
你赔偿给我,你要加多一句“对不起”。
——黄子华
雇佣关系而已,我时刻提醒自己
第1次你给我发错(多)了,我原谅你。
第2次你又发错(少)了,怎么能继续原谅你?
一个很老的笑话
15830371000
文章:@意见反馈/技术支持/伊网/安企网 发表时间:2017-09-14, 11:48:07
#442
展开↯#443
作者:广西河池市宜州市
安装nginx #,广西河池市宜州市,2018-08-01,10:10:20, 输入命令./nginx -t
看到如下显示nginx.conf syntax is ok
nginx.conf test is successful
说明配置文件正确 #,广西河池市宜州市,2018-08-01,10:11:12,
在启动命令-c前加-t #,广西河池市宜州市,2018-08-10,23:22:32, #,广西河池市宜州市,2018-08-21,15:18:10,
Linux下ftp服务可以通过搭建vsftpd服务来实现
执行 systemctl start vsftpd.service 启动vsftp服务,然后可以通过命令: systemctl status vsftpd.service 查看ftp服务的运行状态
#,广西河池市宜州市,2018-08-21,15:53:09, sftp和ftp区别在于:文件的安全性
FTP是一种文件传输协议,一般是为了方便数据共享的。包括一个FTP服务器和多个FTP客户端。FTP客户端通过FTP协议在服务器上下载资源。
SFTP协议是在FTP的基础上对数据进行加密,使得传输的数据相对来说更安全。但是这种安全是以牺牲效率为代价的。
SFTP的传输效率比FTP要低。
//进入nginx目录
cd nginx
Run code
Cut to clipboard
看到如下显示nginx.conf syntax is ok
nginx.conf test is successful
说明配置文件正确
wget -O wordpress.zip http://www.linuxde.net/download.aspx?id=1080
Centos出现-bash: unzip: command not found的解决办法
利用unzip命令解压缩的时候,出现-bash:
unzip: command not found的错误。
unzip——命令没有找到,其原因肯定是没有安装unzip。
利用一句命令就可以解决了。
命令是:
yum install -y unzip zip
安装成功后就可以使用unzip命令
Run code
Cut to clipboard
Linux下ftp服务可以通过搭建vsftpd服务来实现
执行 systemctl start vsftpd.service 启动vsftp服务,然后可以通过命令: systemctl status vsftpd.service 查看ftp服务的运行状态
systemctl stop vsftpd.service
Run code
Cut to clipboard
FTP是一种文件传输协议,一般是为了方便数据共享的。包括一个FTP服务器和多个FTP客户端。FTP客户端通过FTP协议在服务器上下载资源。
SFTP协议是在FTP的基础上对数据进行加密,使得传输的数据相对来说更安全。但是这种安全是以牺牲效率为代价的。
SFTP的传输效率比FTP要低。
文章:LINUX安装NGINX笔记 发表时间:2018-06-14, 17:49:17
#444
作者:广西南宁市
文章:程序员编程常用网页工具集[游戏] 发表时间:2017-07-29, 10:26:00
#445
作者:广西河池市宜州市
文章:@意见反馈/技术支持/伊网/安企网 发表时间:2018-08-02, 15:09:59
#446
作者:广西河池市宜州市
到底是“学术研究无禁区”,还是“思想道德无底线” #,广西河池市宜州市,2018-08-17,09:14:03, 集权可以跑的很快,但刹不住车
文章:@意见反馈/技术支持/伊网/安企网 发表时间:2018-08-17, 09:10:02
#447
作者:广西河池市宜州市
october CMS 模板
变量:
标签:
过滤器:
功能:
this.page:
this.layout:
this.param:
this.environment
{%partial%}
{%content%}
{%占位符%}
变量:
{{variable}}
{{isAjax?'Yes':'No'}}
{{'Your name:' ~ name}}
Run code
Cut to clipboard
标签:
{%tag%}
{%if stormCloudComing%}
Stay inside
{else %}
Gooutside and play
{%endif%}
{%set activePage='blog'%}
Run code
Cut to clipboard
过滤器:
{{‘string’|filter}}
{{price |currency('USD')}}
{{'October Glory'|upper|replace({'October':'Morning'})}}
Run code
Cut to clipboard
功能:
{{function()}}
{{dump(variable)}}
Run code
Cut to clipboard
this.page:
//布局:
{{this.page.layout}}
//id:文件名称和文件夹名称转换为css友好标识符
<body class="page-{{this.page.id}}">
//标题
<h1>{{this.page.title}}</h1>
//描述
<p>{{ this.page.description }}</p>
//meta_title
<title>{{ this.page.meta_title }}</title>
//meta_description
<meta name="description" content="{{ this.page.meta_description }}">
//隐:隐藏的页面只能由登录的后端用户访问。
{% if this.page.hidden %}
<p>Note to other admins: We are currently working on this page.</p>
{% endif %}
Run code
Cut to clipboard
this.layout:
//属性:您可以通过访问当前的布局对象,this.layout并返回该对象Cms\Classes\Layout
//ID:
<body class="layout-{{ this.layout.id }}">
//描述
<meta name="description" content="{{ this.layout.description }}">
this.theme:
//属性 :this.theme将提供直接访问表单字段值,由任何主题定制定义。它本身也具有以下特性
//ID
<body class="theme-{{ this.theme.id }}">
//配置
<meta name="description" content="{{ this.theme.config.description }}">
Run code
Cut to clipboard
this.param:
//您可以通过this.param它访问当前的URL参数,并返回一个PHP数组
//访问页面参数
//如何访问tab页面中的URL参数。
url = "/account/:tab"
==
{% if this.param.tab == 'details' %}
<p>Here are all your details</p>
{% elseif this.param.tab == 'history' %}
<p>You are viewing a blast from the past</p>
{% endif %}
//如果参数名称也是一个变量,那么可以使用数组语法
url = "/account/:post_id"
==
{% set name = 'post_id' %}
<p>The post ID is: {{ this.param[name] }}</p>
Run code
Cut to clipboard
this.environment
//您可以通过访问当前环境对象,this.environment并返回引用当前环境配置的字符串
//如果网站在测试环境中运行,以下示例将显示横幅:
{% if this.environment == 'test' %}
<div class="banner">Test Environment</div>
{% endif %}
Run code
Cut to clipboard
{%partial%}
{% partial "footer" %}
{% partial "sidebar/menu" %}
{% set tabName = "profile" %}
{% partial tabName %}
% partial "blog-posts" posts=posts %}
{% partial "location" city="Vancouver" country="Canada" %}
<p>Country: {{ country }}, city: {{ city }}.</p>
Run code
Cut to clipboard
{%content%}
{% content "contacts.htm" %}
{% content "sidebar/content.htm" %}
{% content "readme.txt" %}
{% content "changelog.md" %}
{% put sidebar %}
{% content 'sidebar-content.htm' %}
{% endput %}
{% content "welcome.htm" name=user.name %}
{% content "location.htm" city="Vancouver" country="Canada" %}
<p>Country: {country}, city: {city}.</p>
{% content "welcome.htm" likes=[
{name:'Dogs'},
{name:'Fishing'},
{name:'Golf'}
] %}
<ul>
{likes}
<li>{name}</li>
{/likes}
</ul>
Run code
Cut to clipboard
{%占位符%}
{% placeholder name %}
{% put name %}
<p>Place this text in the name placeholder</p>
{% endput %}
{% placeholder sidebar default %}
<p><a href="/contacts">Contact us</a></p>
{% endplaceholder %}
{% put sidebar %}
<p><a href="/services">Services</a></p>
{% default %}
{% endput %}
//检测占位符是否存在
{% if placeholder('sidemenu') %}
<!-- Markup for a page with a sidebar -->
<div class="row">
<div class="col-md-3">
{% placeholder sidemenu %}
</div>
<div class="col-md-9">
{% page %}
</div>
</div>
{% else %}
<!-- Markup for a page without a sidebar -->
{% page %}
{% endif %}
//自定义属性
{% placeholder ordering title="Ordering information" type="text" %}
{% placeholder ordering default title="Ordering information" type="text" %}
There is no ordering information for this product.
{% endplaceholder %}
Run code
Cut to clipboard
文章:OctoberCms学习笔记中文文档翻译 发表时间:2018-08-14, 16:55:00
#448
作者:广西河池市宜州市
模仿网易梦幻西游游戏西游记师徒四人行走动画css效果 gif背景动画图片 唐僧 孙悟空 猪八戒 沙和尚 西天取经
<style>
.west-01 {
position: absolute;
width: 200px;
height: 180px;
left: 50%;
margin-left: -398px;
top: 352px;
background-image: url(https://out.img.pan.lizhenqiu.com/FqDMTm_8I03UBd6Lx-cY9FaIB99m);
background-repeat: no-repeat;
-webkit-animation: play01 1.4s steps(8) infinite;
-moz-animation: play01 1.4s steps(8) infinite;
-ms-animation: play01 1.4s steps(8) infinite;
animation: play01 1.4s steps(8) infinite
}
@-webkit-keyframes play01 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
@-moz-keyframes play01 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
@-o-keyframes play01 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
@-ms-keyframes play01 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
@keyframes play01 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
.west-02 {
position: absolute;
width: 200px;
height: 180px;
left: 50%;
margin-left: -198px;
top: 356px;
background-image: url(https://out.img.pan.lizhenqiu.com/Fjr4nM2HtaFF-XM-oabkVJBL-U1z);
background-repeat: no-repeat;
-webkit-animation: play02 1.4s steps(8) infinite;
-moz-animation: play02 1.4s steps(8) infinite;
-ms-animation: play02 1.4s steps(8) infinite;
animation: play02 1.4s steps(8) infinite
}
@-webkit-keyframes play02 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
@-moz-keyframes play02 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
@-o-keyframes play02 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
@-ms-keyframes play02 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
@keyframes play02 {
0% {
background-position: 0 0
}
100% {
background-position: -1600px 0
}
}
.west-03 {
position: absolute;
width: 170px;
height: 240px;
left: 50%;
margin-left: -11px;
top: 326px;
background-image: url(https://out.img.pan.lizhenqiu.com/Ft1ZQTkZbB535lBwZ4vjVhWU5ol6);
background-repeat: no-repeat;
-webkit-animation: play03 1.4s steps(8) infinite;
-moz-animation: play03 1.4s steps(8) infinite;
-ms-animation: play03 1.4s steps(8) infinite;
animation: play03 1.4s steps(8) infinite
}
@-webkit-keyframes play03 {
0% {
background-position: 0 0
}
100% {
background-position: -1360px 0
}
}
@-moz-keyframes play03 {
0% {
background-position: 0 0
}
100% {
background-position: -1360px 0
}
}
@-o-keyframes play03 {
0% {
background-position: 0 0
}
100% {
background-position: -1360px 0
}
}
@-ms-keyframes play03 {
0% {
background-position: 0 0
}
100% {
background-position: -1360px 0
}
}
@keyframes play03 {
0% {
background-position: 0 0
}
100% {
background-position: -1360px 0
}
}
.west-04 {
position: absolute;
width: 210px;
height: 200px;
left: 50%;
margin-left: 198px;
top: 372px;
background-image: url(https://out.img.pan.lizhenqiu.com/FjTycCEEtOfP7JYjlvAybcZVFYqh);
background-repeat: no-repeat;
-webkit-animation: play04 1.4s steps(8) infinite;
-moz-animation: play04 1.4s steps(8) infinite;
-ms-animation: play04 1.4s steps(8) infinite;
animation: play04 1.4s steps(8) infinite
}
@-webkit-keyframes play04 {
0% {
background-position: 0 0
}
100% {
background-position: -1680px 0
}
}
@-moz-keyframes play04 {
0% {
background-position: 0 0
}
100% {
background-position: -1680px 0
}
}
@-o-keyframes play04 {
0% {
background-position: 0 0
}
100% {
background-position: -1680px 0
}
}
@-ms-keyframes play04 {
0% {
background-position: 0 0
}
100% {
background-position: -1680px 0
}
}
@keyframes play04 {
0% {
background-position: 0 0
}
100% {
background-position: -1680px 0
}
}
</style>
<div class="west-01"></div>
<div class="west-02"></div>
<div class="west-03"></div>
<div class="west-04"></div>
Run code
Cut to clipboard
文章:模仿优酷首页的一些前端布局 发表时间:2018-08-09, 11:08:14
#449
作者:广西河池市宜州市
git 换行符LF与CRLF转换问题
#,广西河池市宜州市,2018-08-09,10:48:28, 解决crlf 和 lf不同带来的冲突问题
crlf 和 lf 是文本换行的不同方式:
crlf: "\r\n", windows系统的换行方式
lf: "\n", Linux系统的换行方式
他们之间的不同经常会导致不同会导致使用不同系统的同事之间的代码冲突问题。
在你使用git拉取代码的时候,git会自动将代码当中与你当前系统不同的换行方式转化成你当前系统的换行方式,从而造成这种冲突。
window系统解决办法:
1. 修改git全局配置,禁止git自动将lf转换成crlf, 命令:
git config --global core.autocrlf false
2. 修改编辑器的用户配置,例如vscode
"files.eol": "\n", // 文件换行使用lf方式
一、背景
在各操作系统下,文本文件所使用的换行符是不一样的。UNIX/Linux 使用的是 0x0A(LF),早期的 Mac OS 使用的是0x0D(CR),后来的 OS X 在更换内核后与 UNIX 保持一致了。但 DOS/Windows 一直使用 0x0D0A(CRLF)作为换行符。Git提供了一个“换行符自动转换”功能。这个功能默认处于“自动模式”,当你在签出文件时,它试图将 UNIX 换行符(LF)替换为 Windows 的换行符(CRLF);当你在提交文件时,它又试图将 CRLF 替换为 LF。Git 的“换行符自动转换”功能听起来似乎很智能、很贴心,因为它试图一方面保持仓库内文件的一致性(UNIX 风格),一方面又保证本地文件的兼容性(Windows 风格)。但遗憾的是,这个功能是有 bug 的,而且在短期内都不太可能会修正。
二、解决方案
1.Git设置
git config --global core.autocrlf false
git config --global core.safecrlf true
含义:
AutoCRLF
#提交时转换为LF,检出时转换为CRLF
git config --global core.autocrlf true
#提交时转换为LF,检出时不转换
git config --global core.autocrlf input
#提交检出均不转换
git config --global core.autocrlf false
SafeCRLF
#拒绝提交包含混合换行符的文件
git config --global core.safecrlf true
#允许提交包含混合换行符的文件
git config --global core.safecrlf false
#提交包含混合换行符的文件时给出警告
git config --global core.safecrlf warn
2.IDE设置使用UNIX换行符
IDEA的设置File -> Settings
Editor -> Code Style
Line separator (for new lines) ,选择:Unix and OS X (\n)
对已使用Windows换行符的文件,可以使用Sublime Text打开,
View->Line Endings,选Unix,保存;
Run code
Cut to clipboard
crlf 和 lf 是文本换行的不同方式:
crlf: "\r\n", windows系统的换行方式
lf: "\n", Linux系统的换行方式
他们之间的不同经常会导致不同会导致使用不同系统的同事之间的代码冲突问题。
在你使用git拉取代码的时候,git会自动将代码当中与你当前系统不同的换行方式转化成你当前系统的换行方式,从而造成这种冲突。
window系统解决办法:
1. 修改git全局配置,禁止git自动将lf转换成crlf, 命令:
git config --global core.autocrlf false
2. 修改编辑器的用户配置,例如vscode
"files.eol": "\n", // 文件换行使用lf方式
文章:GitHub代码管理代码托管 发表时间:2018-08-09, 10:48:10
#450
作者:广西河池市宜州市
octobercms数据库使用
检索结果
models:
//运行select查询
$users = Db::select(‘select * from users where active = ?‘, [1]);
传递给该select方法的第一个参数是原始SQL查询,而第二个参数是需要绑定到查询的任何参数绑定。通常,这些是where子句约束的值。参数绑定提供了针对SQL注入的保护。
该select方法将始终返回一个array结果。数组中的每个结果将是一个PHP stdClass对象,允许您访问结果的值:
foreach ($users as $user) {
echo $user->name;
}
//使用命名绑定
$results = Db::select(‘select * from users where id = :id‘, [‘id‘ => 1]);
//运行一个insert语句
要执行一个insert语句,你可以使用insert在Db立面上的方法。像这样select,这个方法将原始SQL查询作为第一个参数,绑定作为第二个参数:
Db::insert(‘insert into users (id, name) values (?, ?)‘, [1, ‘Joe‘]);
//运行更新语句
该update方法应用于更新数据库中的现有记录。该语句受影响的行数将由方法返回:
$affected = Db::update(‘update users set votes = 100 where name = ?‘, [‘John‘]);
//运行delete语句
该delete方法应用于从数据库中删除记录。喜欢update,将返回删除的行数:
$deleted = Db::delete(‘delete from users‘);
//运行一般声明
某些数据库语句不应返回任何值。对于这些类型的操作,您可以使用立面上的statement方法Db
Db::statement(‘drop table users‘);
//多个数据库连接
当使用多个连接时,您可以通过立面上的connection方法访问每个连接Db。在name传递给connection方法应该对应于您列出的其中一个连接config/database.php组态文件中
$users = Db::connection(‘foo‘)->select(...);
$pdo = Db::connection()->getPdo();
//数据库事务
Db::transaction(function () {
Db::table(‘users‘)->update([‘votes‘ => 1]);
Db::table(‘posts‘)->delete();
});
//手动使用交易
如果您想手动开始事务并完全控制回滚和提交,您可以使用立面上的beginTransaction方法Db:
Db::beginTransaction();
您可以通过以下rollBack方法回滚事务:
Db::rollBack();
最后,您可以通过以下commit方法提交事务:
Db::commit();
//数据库事件
如果要接收应用程序执行的每个SQL查询,可以使用该listen方法。此方法对于记录查询或调试很有用。
Db::listen(function($sql, $bindings, $time) {
//
});
//查询记录
启用查询日志记录时,将记录所有已为当前请求运行的查询的内存。调用该enableQueryLog方法启用此功能
Db::connection()->enableQueryLog();
要获取执行查询的数组,可以使用以下getQueryLog方法:
$queries = Db::getQueryLog();
然而,在某些情况下,例如当插入大量行时,这可能导致应用程序使用多余的内存。要禁用日志,您可以使用以下disableQueryLog方法:
Db::connection()->disableQueryLog();
Run code
Cut to clipboard
检索结果
//从表中检索所有行--get来看一下表中的所有记录
$users = Db::table(‘users‘)->get();
//通过访问列作为对象的属性来访问每列的值:
foreach ($users as $user) {
echo $user->name;
}
//从表中检索单个行/列
$user = Db::table(‘users‘)->where(‘name‘, ‘John‘)->first();
echo $user->name;
//如果您甚至不需要整行,您可以使用该value方法从记录中提取单个值。此方法将直接返回列的值:
$email = Db::table(‘users‘)->where(‘name‘, ‘John‘)->value(‘email‘);
//分块结果从一张桌子
Db::table(‘users‘)->chunk(100, function($users) {
foreach ($users as $user) {
//
}
});
//您可以通过以下方式返回false来阻止进一步处理的块Closure:
Db::table(‘users‘)->chunk(100, function($users) {
// Process the records...
return false;
});
//检索列值列表
//如果要检索包含单列值的数组,则可以使用该lists方法
$titles = Db::table(‘roles‘)->lists(‘title‘);
foreach ($titles as $title) {
echo $title;
}
//您还可以为返回的数组指定自定义键列:
$roles = Db::table(‘roles‘)->lists(‘title‘, ‘name‘);
foreach ($roles as $name => $title) {
echo $title;
}
//骨料
$users = Db::table(‘users‘)->count();
$price = Db::table(‘orders‘)->max(‘price‘);
$price = Db::table(‘orders‘)
->where(‘is_finalized‘, 1)
->avg(‘price‘);
//选择
$users = Db::table(‘users‘)->select(‘name‘, ‘email as user_email‘)->get();
//该distinct方法允许您强制查询返回不同的结果:
$users = Db::table(‘users‘)->distinct()->get();
$query = Db::table(‘users‘)->select(‘name‘);
$users = $query->addSelect(‘age‘)->get();
//原始表达式
$users = Db::table(‘users‘)
->select(Db::raw(‘count(*) as user_count, status‘))
->where(‘status‘, ‘<>‘, 1)
->groupBy(‘status‘)
->get();
//加盟
$users = Db::table(‘users‘)
->join(‘contacts‘, ‘users.id‘, ‘=‘, ‘contacts.user_id‘)
->join(‘orders‘, ‘users.id‘, ‘=‘, ‘orders.user_id‘)
->select(‘users.*‘, ‘contacts.phone‘, ‘orders.price‘)
->get();
$users = Db::table(‘users‘)
->leftJoin(‘posts‘, ‘users.id‘, ‘=‘, ‘posts.user_id‘)
->get();
Db::table(‘users‘)
->join(‘contacts‘, function ($join) {
$join->on(‘users.id‘, ‘=‘, ‘contacts.user_id‘)->orOn(...);
})
->get();
Db::table(‘users‘)
->join(‘contacts‘, function ($join) {
$join->on(‘users.id‘, ‘=‘, ‘contacts.user_id‘)
->where(‘contacts.user_id‘, ‘>‘, 5);
})
->get();
//where子句
$users = Db::table(‘users‘)->where(‘votes‘, ‘=‘, 100)->get();
$users = Db::table(‘users‘)->where(‘votes‘, 100)->get();
$users = Db::table(‘users‘)
->where(‘votes‘, ‘>=‘, 100)
->get();
$users = Db::table(‘users‘)
->where(‘votes‘, ‘<>‘, 100)
->get();
$users = Db::table(‘users‘)
->where(‘name‘, ‘like‘, ‘T%‘)
->get();
//“或”声明
$users = Db::table(‘users‘)
->where(‘votes‘, ‘>‘, 100)
->orWhere(‘name‘, ‘John‘)
->get();
//“之间”之间的陈述
$users = Db::table(‘users‘)
->whereBetween(‘votes‘, [1, 100])->get();
$users = Db::table(‘users‘)
->whereNotBetween(‘votes‘, [1, 100])
->get();
//“在哪里”声明
$users = Db::table(‘users‘)
->whereIn(‘id‘, [1, 2, 3])
->get();
$users = Db::table(‘users‘)
->whereNotIn(‘id‘, [1, 2, 3])
->get();
//“null”语句
$users = Db::table(‘users‘)
->whereNull(‘updated_at‘)
->get();
$users = Db::table(‘users‘)
->whereNotNull(‘updated_at‘)
->get();
//排序
$users = Db::table(‘users‘)
->orderBy(‘name‘, ‘desc‘)
->get();
//分组
$users = Db::table(‘users‘)
->groupBy(‘account_id‘)
->having(‘account_id‘, ‘>‘, 100)
->get();
//该havingRaw方法可用于将原始字符串设置为having子句的值。例如,我们可以找到销售额超过$ 2,500的所有部门:
$users = Db::table(‘orders‘)
->select(‘department‘, Db::raw(‘SUM(price) as total_sales‘))
->groupBy(‘department‘)
->havingRaw(‘SUM(price) > 2500‘)
->get();
//限制和抵消
//要限制从查询返回的结果数,或者在查询(OFFSET)中跳过给定数量的结果,可以使用skip和take方法:
$users = Db::table(‘users‘)->skip(10)->take(5)->get();
//插入
Db::table(‘users‘)->insert(
[‘email‘ => ‘john@example.com‘, ‘votes‘ => 0]
);
Db::table(‘users‘)->insert([
[‘email‘ => ‘taylor@example.com‘, ‘votes‘ => 0],
[‘email‘ => ‘dayle@example.com‘, ‘votes‘ => 0]
]);
//自动递增ID
$id = Db::table(‘users‘)->insertGetId(
[‘email‘ => ‘john@example.com‘, ‘votes‘ => 0]
);
//更新
Db::table(‘users‘)
->where(‘id‘, 1)
->update([‘votes‘ => 1]);
//递增/递减
Db::table(‘users‘)->increment(‘votes‘);
Db::table(‘users‘)->increment(‘votes‘, 5);
Db::table(‘users‘)->decrement(‘votes‘);
Db::table(‘users‘)->decrement(‘votes‘, 5);
Db::table(‘users‘)->increment(‘votes‘, 1, [‘name‘ => ‘John‘]);
//删除
Db::table(‘users‘)->delete();
Db::table(‘users‘)->where(‘votes‘, ‘<‘, 100)->delete();
Db::table(‘users‘)->truncate();
//悲观锁定
Db::table(‘users‘)->where(‘votes‘, ‘>‘, 100)->sharedLock()->get();
Db::table(‘users‘)->where(‘votes‘, ‘>‘, 100)->lockForUpdate()->get();
//缓存查询
//持久缓存
$users = Db::table(‘users‘)->remember(10)->get();
//内存缓存
Db::table(‘users‘)->get(); // Result from database
Db::table(‘users‘)->get(); // Result from database
Model::all(); // Result from database
Model::all(); // Result from in-memory cache
//您可以使用enableDuplicateCache或disableDuplicateCache方法启用或禁用重复缓存
Db::table(‘users‘)->enableDuplicateCache()->get();
//如果查询存储在缓存中,则当使用insert,update,delete或truncate语句时,它将自动被清除。但是您可以使用该flushDuplicateCache方法手动清除缓存
Db::table(‘users‘)->enableDuplicateCache()->get();
Run code
Cut to clipboard
models:
//介绍
plugins/
acme/
blog/
models/
user/ <=== Model config directory
columns.yaml <=== Model config files
fields.yaml <==^
User.php <=== Model class
Plugin.php
//定义模型
namespace Acme\Blog\Models;
use Model;
class Post extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = ‘acme_blog_posts‘;
}
//支持的属性
class User extends Model
{
protected $primaryKey = ‘id‘;
public $exists = false;
protected $dates = [‘last_seen_at‘];
public $timestamps = true;
protected $jsonable = [‘permissions‘];
protected $guarded = [‘*‘];
}
//首要的关键
class Post extends Model
{
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = ‘id‘;
}
//时间戳
class Post extends Model
{
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}
//如果您需要自定义时间戳的格式,请设置$dateFormat模型上的属性。此属性确定日期属性如何存储在数据库中,以及当模型序列化为数组或JSON时的格式:
class Post extends Model
{
/**
* The storage format of the model‘s date columns.
*
* @var string
*/
protected $dateFormat = ‘U‘;
}
//值存储为JSON
class Post extends Model
{
/**
* @var array Attribute names to encode and decode using JSON.
*/
protected $jsonable = [‘data‘];
}
//访问列值
foreach ($flights as $flight) {
echo $flight->name;
}
//添加附加约束
$flights = Flight::where(‘active‘, 1)
->orderBy(‘name‘, ‘desc‘)
->take(10)
->get();
//集合
foreach ($flights as $flight) {
echo $flight->name;
}
//分块结果
Flight::chunk(200, function ($flights) {
foreach ($flights as $flight) {
//
}
});
//检索单个模型
// Retrieve a model by its primary key
$flight = Flight::find(1);
// Retrieve the first model matching the query constraints
$flight = Flight::where(‘active‘, 1)->first();
//找不到例外
$model = Flight::findOrFail(1);
$model = Flight::where(‘legs‘, ‘>‘, 100)->firstOrFail();
Route::get(‘/api/flights/{id}‘, function ($id) {
return Flight::findOrFail($id);
});
//检索聚合
$count = Flight::where(‘active‘, 1)->count();
$max = Flight::where(‘active‘, 1)->max(‘price‘);
//基本插入
$flight = new Flight;
$flight->name = ‘Sydney to Canberra‘;
$flight->save();
//基本更新
$flight = Flight::find(1);
$flight->name = ‘Darwin to Adelaide‘;
$flight->save();
//还可以针对与给定查询匹配的任意数量的模型执行更新。在这个例子中,所有的航班active,有一个destination的San Diego将被标记为延迟:
Flight::where(‘is_active‘, true)
->where(‘destination‘, ‘Perth‘)
->update([‘delayed‘ => true]);
//质量分配
class Flight extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [‘name‘];
}
//一旦我们赋予了属性质量分配,我们可以使用该create方法在数据库中插入新的记录。该create方法返回保存的模型实例:
$flight = Flight::create([‘name‘ => ‘Flight 10‘]);
//其他创作方法
$flight = Flight::make([‘name‘ => ‘Flight 10‘]);
// Functionally the same as...
$flight = new Flight;
$flight->fill([‘name‘ => ‘Flight 10‘]);
// Retrieve the flight by the attributes, otherwise create it
$flight = Flight::firstOrCreate([‘name‘ => ‘Flight 10‘]);
// Retrieve the flight by the attributes, or instantiate a new instance
$flight = Flight::firstOrNew([‘name‘ => ‘Flight 10‘]);
//删除模型
$flight = Flight::find(1);
$flight->delete();
//按键删除现有的模型
Flight::destroy(1);
Flight::destroy([1, 2, 3]);
Flight::destroy(1, 2, 3);
//通过查询删除模型
$deletedRows = Flight::where(‘active‘, 0)->delete();
//查询范围
class User extends Model
{
/**
* Scope a query to only include popular users.
*/
public function scopePopular($query)
{
return $query->where(‘votes‘, ‘>‘, 100);
}
/**
* Scope a query to only include active users.
*/
public function scopeActive($query)
{
return $query->where(‘is_active‘, 1);
}
}
//利用查询范围
$users = User::popular()->active()->orderBy(‘created_at‘)->get();
//动态范围
class User extends Model
{
/**
* Scope a query to only include users of a given type.
*/
public function scopeApplyType($query, $type)
{
return $query->where(‘type‘, $type);
}
}
//现在您可以在调用范围时传递参数:
$users = User::applyType(‘admin‘)->get();
Run code
Cut to clipboard
文章:OctoberCms学习笔记中文文档翻译 发表时间:2018-08-07, 09:21:33
#451
作者:广西河池市宜州市
使Nginx服务器支持.htaccess的方法
nginx可以include任何文件,而不仅仅是.htaccess
在 nginx/nginx.conf的server{}中引入 .htaccess 文件:
nginx可以include任何文件,而不仅仅是.htaccess
在 nginx/nginx.conf的server{}中引入 .htaccess 文件:
include /vhosts/quany.info/.htaccess;
Run code
Cut to clipboard
文章:OctoberCms学习笔记中文文档翻译 发表时间:2018-08-07, 09:16:25
#452
作者:广西河池市宜州市
画布大小,点哪边留哪边

如图,将向上裁剪,底部图片内容不变,顶部图片被裁剪 #,广西河池市宜州市,2018-08-02,16:02:17, 左右正好相反哦
如图,将向上裁剪,底部图片内容不变,顶部图片被裁剪
文章:常用代码2 发表时间:2018-08-02, 15:50:04
#454
作者:广西河池市宜州市
解决CentOS7关闭/开启防火墙出现Unit iptables.service failed to load: No such file or directory.
CentOS7中执行
service iptables start/stop
会报错Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.
在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理,
如果要添加范围例外端口 如 1000-2000
语法命令如下:启用区域端口和协议组合
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
此举将启用端口和协议的组合。端口可以是一个单独的端口 <port> 或者是一个端口范围 <port>-<port> 。协议可以是 tcp 或 udp。
实际命令如下:
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone=public --query-port=80/tcp
删除
firewall-cmd --zone=public --remove-port=80/tcp --permanent
当然你可以还原传统的管理方式。
执行一下命令:
systemctl stop firewalld
systemctl mask firewalld
并且安装iptables-services:
yum install iptables-services
设置开机启动:
systemctl enable iptables
systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables
保存设置:
service iptables save
OK,再试一下应该就好使了
开放某个端口 在/etc/sysconfig/iptables里添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT #,广西河池市宜州市,2018-08-01,10:18:13,
输入 service iptables restart
Redirecting to /bin/systemctl restart iptables.service
Failed to restart iptables.service: Unit not found.
被完美解决!!!
#,广西河池市宜州市,2018-08-01,10:18:26,
“ 查看 firewall-cmd --zone= public --query-port=80/tcp ” 这个语句输入后报错 “ usage: see firewall-cmd man page firewall-cmd: error: unrecognized arguments: public ” 将语句修改为 “ firewall-cmd --query-port=80/tcp ” 后可以使用 #,广西河池市宜州市,2018-08-01,10:18:44, Failed to start iptables.service: Unit not found. 这个错误也可以解决...
CentOS7中执行
service iptables start/stop
会报错Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.
在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理,
如果要添加范围例外端口 如 1000-2000
语法命令如下:启用区域端口和协议组合
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
此举将启用端口和协议的组合。端口可以是一个单独的端口 <port> 或者是一个端口范围 <port>-<port> 。协议可以是 tcp 或 udp。
实际命令如下:
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone=public --query-port=80/tcp
删除
firewall-cmd --zone=public --remove-port=80/tcp --permanent
当然你可以还原传统的管理方式。
执行一下命令:
systemctl stop firewalld
systemctl mask firewalld
并且安装iptables-services:
yum install iptables-services
设置开机启动:
systemctl enable iptables
systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables
保存设置:
service iptables save
OK,再试一下应该就好使了
开放某个端口 在/etc/sysconfig/iptables里添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
输入 service iptables restart
Redirecting to /bin/systemctl restart iptables.service
Failed to restart iptables.service: Unit not found.
被完美解决!!!
“ 查看 firewall-cmd --zone= public --query-port=80/tcp ” 这个语句输入后报错 “ usage: see firewall-cmd man page firewall-cmd: error: unrecognized arguments: public ” 将语句修改为 “ firewall-cmd --query-port=80/tcp ” 后可以使用
文章:LINUX安装NGINX笔记 发表时间:2018-08-01, 10:17:50
#455
作者:广西河池市宜州市
Nginx启动SSL功能,并进行功能优化
1.1 Nginx如果未开启SSL模块,配置Https时提示错误
原因也很简单,nginx缺少http_ssl_module模块,编译安装的时候带上--with-http_ssl_module配置就行了,但是现在的情况是我的nginx已经安装过了,怎么添加模块,其实也很简单,往下看: 做个说明:我的nginx的安装目录是/usr/local/nginx这个目录,我的源码包在/usr/local/src/nginx-1.6.2目录
1.2 Nginx开启SSL模块
切换到源码包:
查看nginx原有的模块
在configure arguments:后面显示的原有的configure参数如下:
那么我们的新配置信息就应该这样写:
运行上面的命令即可,等配置完
配置完成后,运行命令
这里不要进行make install,否则就是覆盖安装
然后备份原有已安装好的nginx
然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)
然后启动nginx,仍可以通过命令查看是否已经加入成功
Nginx 配置Http和Https共存
把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用
Nginx 配置SSL安全证书重启避免输入密码
可以用私钥来做这件事。生成一个解密的key文件,替代原来key文件。
Nginx SSL性能调优
Nginx 配置Http跳转Https
1.1 Nginx如果未开启SSL模块,配置Https时提示错误
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:37
Run code
Cut to clipboard
原因也很简单,nginx缺少http_ssl_module模块,编译安装的时候带上--with-http_ssl_module配置就行了,但是现在的情况是我的nginx已经安装过了,怎么添加模块,其实也很简单,往下看: 做个说明:我的nginx的安装目录是/usr/local/nginx这个目录,我的源码包在/usr/local/src/nginx-1.6.2目录
1.2 Nginx开启SSL模块
切换到源码包:
cd /usr/local/src/nginx-1.11.3
Run code
Cut to clipboard
查看nginx原有的模块
/usr/local/nginx/sbin/nginx -V
Run code
Cut to clipboard
在configure arguments:后面显示的原有的configure参数如下:
--prefix=/usr/local/nginx --with-http_stub_status_module
Run code
Cut to clipboard
那么我们的新配置信息就应该这样写:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
Run code
Cut to clipboard
运行上面的命令即可,等配置完
配置完成后,运行命令
make
Run code
Cut to clipboard
这里不要进行make install,否则就是覆盖安装
然后备份原有已安装好的nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
Run code
Cut to clipboard
然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)
cp ./objs/nginx /usr/local/nginx/sbin/
Run code
Cut to clipboard
然后启动nginx,仍可以通过命令查看是否已经加入成功
/usr/local/nginx/sbin/nginx -V
Run code
Cut to clipboard
Nginx 配置Http和Https共存
server {
listen 80 default backlog=2048;
listen 443 ssl;
server_name wosign.com;
root /var/www/html;
ssl_certificate /usr/local/Tengine/sslcrt/ wosign.com.crt;
ssl_certificate_key /usr/local/Tengine/sslcrt/ wosign.com .Key;
}
Run code
Cut to clipboard
把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用
Nginx 配置SSL安全证书重启避免输入密码
可以用私钥来做这件事。生成一个解密的key文件,替代原来key文件。
openssl rsa -in server.key -out server.key.unsecure
Run code
Cut to clipboard
Nginx SSL性能调优
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
Run code
Cut to clipboard
Nginx 配置Http跳转Https
server {
listen 80;
server_name www.域名.com;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443;
server_name www.域名.com;
root /home/www;
ssl on;
ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;
}
Run code
Cut to clipboard
文章:LINUX安装NGINX笔记 发表时间:2018-08-01, 10:16:12
#456
作者:广西河池市宜州市
https服务器配置、nginx配置、系统的443端口检查和开启
查看了所运行的端口
>(如果发现端口没有443),说明该端口防火墙没有配置到,所以也不能进行代理的操作;及没有找到下面这个
解决办法:
进入防火墙配置文件看看了
vim /etc/sysconfig/iptables
// 看看有没有443的文件,没有的话在改文件中添加下面这行
>-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
再次注意,
>-A INPUT -j REJECT –reject-with icmp-host-prohibited
添加的新的那句需要在这句的前面,否则443端口也有问题
#,广西河池市宜州市,2018-08-01,10:06:41, 特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面
原因是这条规则的作用是拒绝所有-j REJECT 在iptables帮助文档里面有一下说明This is used to send back an error packet in response to the matched packet
就是表明拒绝你,并返回一个错误连接信息。请求没到nginx那,肯定没有状态码返回,同时你的浏览器返回的只能是无法连接。 #,广西河池市宜州市,2018-08-01,10:07:11, 被netstat -anp 出来的内容欺骗了,规则是添加了,但是没起效果。
如果返回404,403等等,那说明是nginx的配置等因素; #,广西河池市宜州市,2018-08-01,10:09:03, /usr/local/nginx/sbin/nginx -s reload 时报invalid PID number报错
查看了所运行的端口
>
netstat -anp
Run code
Cut to clipboard
解决办法:
进入防火墙配置文件看看了
vim /etc/sysconfig/iptables
// 看看有没有443的文件,没有的话在改文件中添加下面这行
>-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
再次注意,
>-A INPUT -j REJECT –reject-with icmp-host-prohibited
添加的新的那句需要在这句的前面,否则443端口也有问题
原因是这条规则的作用是拒绝所有-j REJECT 在iptables帮助文档里面有一下说明This is used to send back an error packet in response to the matched packet
就是表明拒绝你,并返回一个错误连接信息。请求没到nginx那,肯定没有状态码返回,同时你的浏览器返回的只能是无法连接。
如果返回404,403等等,那说明是nginx的配置等因素;
/usr/local/nginx/sbin/nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
解决方法:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
使用nginx -c的参数指定nginx.conf文件的位置
[root@localhost nginx]# cd logs/
[root@localhost logs]# ll
总用量 12
-rw-r--r-- 1 root root 1246 12月 9 18:10 access.log
-rw-r--r-- 1 root root 516 12月 10 15:39 error.log
-rw-r--r-- 1 root root 5 12月 10 15:38 nginx.pid
看nginx.pid文件已经有了
Run code
Cut to clipboard
文章:LINUX安装NGINX笔记 发表时间:2018-08-01, 09:57:51
将请求存入redis 为了模拟多个用户的请求,使用一个for循环替代 //redis数据入队操作 $redis = new Redis(); $redis->connect('127.0.0.1',6379); for($i=0;$i<50;$i++){ try{ $redis->LPUSH('click',rand(1000,5000)); }catch(Exception $e){ echo $e->getMessage(); } } 在后台进行数据处理 守护进程 //redis数据出队操作,从redis中将请求取出 $redis = new Redis(); $redis->pconnect('127.0.0.1',6379); while(true){ try{ $value = $redis->LPOP('click'); if(!$value){ break; } //var_dump($value)."\n"; /* * 利用$value进行逻辑和数据处理 */ }catch(Exception $e){ echo $e->getMessage(); } }
//关于redis事务的案例 header("content-type:text/html;charset=utf-8"); $redis = new redis(); $redis->connect('localhost', 6379); //$result = $redis->connect('localhost', 6379); //$redis = Yii::app()->redis; $redis->set("testName","33"); //$mywatchkey = $redis->get("mywatchkey"); $mywatchkey = $redis->get('testName'); //($test);exit; $rob_total = 100; //抢购数量 if($mywatchkey<$rob_total){ $redis->watch("testName"); $redis->multi(); //设置延迟,方便测试效果。 sleep(5); //插入抢购数据 $redis->hSet("testName","user_id_".mt_rand(1, 9999),time()); $redis->set("testName",$mywatchkey+1); $rob_result = $redis->exec(); if($rob_result){ $mywatchlist = $redis->hGetAll("testName"); echo "抢购成功!<br/>"; echo "剩余数量:".($rob_total-$mywatchkey-1)."<br/>"; echo "用户列表:<pre>"; var_dump($mywatchlist); }else{ echo "手气不好,再抢购!";exit; } }
先将商品库存存入队列:
<?php $store=1000; //商品库存 $redis=new Redis(); $result=$redis->connect('127.0.0.1',6379); $res=$redis->llen('goods_store'); for($i=0; $i<$store; $i++){ $redis->lpush('goods_store',1); } echo $redis->llen('goods_store'); ?>
客户执行下单操作:
$redis=new Redis(); $result=$redis->connect('127.0.0.1',6379); $count = $redis->lpop('goods_store'); if(!$count){ echo '抢购失败!'; return; }