谁一开始就是大神?

PHP 第32页

PHP

updateAll返回2,但是数据库并没有更新[1.1]

youthdolphin阅读(89)

RT,updateAll返回2,但是数据库并没有更新;

$result = $this->updateAll(array('status' => 1), 'store_id=:store_id', array(':store_id' => $store_id));

$result返回2.

数据库:

11.png

可以看出,数据库并没有改;

sqlLog:

2017/04/07 11:22:08 [trace] [system.db.CDbCommand] Executing SQL: UPDATE `slb_stock_balance` SET `status`=:yp0 WHERE store_id=:id

我记得有个参数可以把 :yp0 这个部分也显示到log中的,然后你根据 sql进行反查就行了。

php队列问题请教大牛

Ellielove阅读(90)

看了处理高并发下单解决方案

库存只有10 每次有人下单,就丢到队列里面,然后队列里面校验库存,这样有并发的时候也只是多插入了队列

疑问

把请求下单放到了列队里面 也就是说本次请求只是加入了列队没有下单入库请求就结束了 那么列队里的请求通过什么方式来触发处理?列队里面的前10可以下单成功 其他的下单失败 那么怎么返回给客户呢?这会用户下单的请求已经结束了

队列可以通过常规php 访问进行数据库写入,结果可以通过ajax获取。
场景如下:
队列里大于等于10,不就即时返回失败给客户端吗,假设不小心队列超出10了,在支付的时候再进行一次处理,先支付的先得

yii如何判断是手机访问还是电脑访问[2.0]

Beesuper阅读(88)

大神好 求yii如何判断是手机访问还是电脑访问

帅哥,不用纠结了,Yii官方是没有提供方法去判断来源是移动设备还是PC的,包括其核心代码以及扩展代码。
在服务器和客户端的 HTTP 交互中,客户端会通过请求头中的 User-Agent 告知服务器客户端到底是啥玩意。你可以直接获取 这个 User-Agent,不过基于 CGI 协议,PHP可以直接用 $_SERVER['HTTP_USER_AGENT']获取这个 User-Agent。但不幸的是,它是一大堆字符串,人们虽然可能可以通过其直接判断是移动设备还是PC,但程序却很麻烦,毕竟难免有所疏漏之处。所以有专门的人士去做自然最好。
https://github.com/serbanghita/Mobile-Detect,这个程序可以的。star 六千,还专门为 Yii 写个了扩展,应该不会辱没帅哥你的程序的。。
https://www.baidu.com/s?wd=如何判断是手机访问还是电脑访问&ie=UTF-8
composer下一个
可以使用 $_SERVER[‘HTTP_USER_AGENT’] 来进行判断~,然后可以继承 baseModel来封装成一个类中的判断方法~希望可以帮到你
yii框架没有的。 可以用这个 http://www.yiichina.com/tutorial/346
https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples
<?php
// These lines are mandatory.
require_once ‘Mobile_Detect.php’;
$detect = new Mobile_Detect;
<?php
// Basic detection.
$detect->isMobile();
$detect->isTablet();
// Magic methods.
$detect->isIphone();
$detect->isSamsung();
// […]
// Alternative to magic methods.
$detect->is(‘iphone’);
// Find the version of component.
$detect->version(‘Android’);
// Additional match method.
$detect->match(‘regex.*here’);
// Browser grade method.
$detect->mobileGrade();
// Batch methods.
$detect->setUserAgent($userAgent);
$detect->setHttpHeaders($httpHeaders);
<?php
// Check for mobile environment.
if ($detect->isMobile()) {
}
<?php
// Check for tablet device.
if($detect->isTablet()){
}
<?php
// Check for any mobile device, excluding tablets.
if ($detect->isMobile() && !$detect->isTablet()) {
}
<?php
// Keep the value in $_SESSION for later use
// and for optimizing the speed of the code.
if(!$_SESSION[‘isMobile’]){
}
<?php
// Redirect the user to your mobile version of the site.
if($detect->isMobile()){
}
<?php
// Include and instantiate the class.
require_once ‘Mobile_Detect.php’;
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
}
// Any tablet device.
if( $detect->isTablet() ){
}
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
}
// Check for a specific platform with the help of the magic methods:
if( $detect->isiOS() ){
}
if( $detect->isAndroidOS() ){
}
// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->is(‘Chrome’)
$detect->is(‘iOS’)
$detect->is(‘UCBrowser’)
$detect->is(‘Opera’)
// […]
// Batch mode using setUserAgent():
$userAgents = array(
‘Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19’,
‘BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103’,
// […]
);
foreach($userAgents as $userAgent){
$detect->setUserAgent($userAgent);
$isMobile = $detect->isMobile();
$isTablet = $detect->isTablet();
// Use the force however you want.
}
// Get the version() of components.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->version(‘iPad’); // 4.3 (float)
$detect->version(‘iPhone’) // 3.1 (float)
$detect->version(‘Android’); // 2.1 (float)
$detect->version(‘Opera Mini’); // 5.0 (float)
// […]
这个tp框架封装了的,直接复制出来用
自己写了一个方法,方法有点笨,使用了多种判断的方法,不过用起来还算是有用些,可以试一试!

yii\web\Application::version[2.0]

Wendysuper阅读(88)

日志是导入到数据库的:报如下的错误
Unable to send log via yii\debug\LogTarget: Exception (Unknown Property) ‘yii\base\UnknownPropertyException’ with message ‘Getting unknown property: yii\web\Application::version’

in /home/wwwroot/www.dev.com/vendor/yiisoft/yii2/base/Component.php:147

Stack trace:
#0 /home/wwwroot/www.dev.com/vendor/yiisoft/yii2/di/ServiceLocator.php(75): yii\base\Component->get(‘version’)
#1 /home/wwwroot/www.dev.com/vendor/yiisoft/yii2-debug/panels/ConfigPanel.php(92): yii\di\ServiceLocator->
get(‘version’)
#2 /home/wwwroot/www.dev.com/vendor/yiisoft/yii2-debug/LogTarget.php(54): yii\debug\panels\ConfigPanel->save()
#3 /home/wwwroot/www.dev.com/vendor/yiisoft/yii2-debug/LogTarget.php(118): yii\debug\LogTarget->export()
#4 /home/wwwroot/www.dev.com/vendor/yiisoft/yii2/log/Dispatcher.php(188): yii\debug\LogTarget->collect(Array, true)
#5 /home/wwwroot/www.dev.com/vendor/yiisoft/yii2/log/Logger.php(177): yii\log\Dispatcher->dispatch(Array, true)
#6 [internal function]: yii\log\Logger->flush(true)
#7 {main}

从你的哦错误提示里面,至少有这么几个疑点:(列出来希望对你有帮助)
首先要说的,yii\base\Component->get(‘version’),yii\base\Component是没有这个get()这个方法的,
其次,yii\di\ServiceLocator->get(‘version’)获取的’version’这个组件(component)而不是yii\web\Application::version这个属性
最后,yii\web\Application::version,是有这个属性的,这个是确定的
看不懂。。。。。。。。。。
检查你的写法里面的语句是不是有问题,一般这种情况都是符号之类的错误
没有version这个字段,检查你的数据库结构,和模型中的字段是否匹配。

放一个.ico到web目录,就会被直接覆盖成Yii2默认的模样,怎么办?[2.0]

ACGpony阅读(89)

如题,我自己做了一个,.png放过去还好,如果名为.ico,就会被直接覆盖成三个小砖块……会不会影响SEO?咋办啊

不会。
seo才不管你的小图标。
你指的三个小砖块是图标名称?还是文件被替换?
如果是替换,那说明你的文件没放对位置。
据我所知 icon和seo没有半毛钱关系。
可以试试 favicon.ico 这个名字,我在nginx下就是用这个来实现icon的。

怎么防止上传相同文件[2.0]

Swiftlovely阅读(93)

准备弄个一台文件存储服务器
怎么防止上传相同文件(图片 文档 视频 ==)不管文件名是否相同 只要文件里面的数据相同就不在上传了 直接返回已经存在的文件路径 目前的想法 上传过的文件都用md5_file 加密进行数据库存储 每次新上传都去查询是否存在相同
不知道可行否 还是有没有更好的办法

检验文件sha值,服务器上已存在的文件就修改一个链接地址指向已存在的文件。
要不百度网盘里上G的文件能秒传得怎么实现的。
我能想到的就是 拿空间换时间,做个table 里面存上 文件的 hash值和对应的 存储路径,然后上传文件的时候检查下,但是貌似还是需要上传到服务器才行,有点类似现在百度网盘的文件检测原理。
上传到文件命名名称 保存到数据库 然后每次上传文件之前 跟数据库对比一下 如果存在 不让他上传即可

Yii2高级模板ignore文件[2.0]

CindyStone阅读(87)

最近尝试使用Yii高级模板,发现里面有很多gitignore文件,我想把我的代码全部push到git上,这些文件影响到我了…
我想知道,这些文件在Yii中的作用是什么,为什么需要这些文件,删掉行不行

比如:团队开发时候,大家一起开发,每个人有相同的数据库,但是每个人在本地的数据库登录名和密码是不同的。包含这些数据库等配置文件就不需要上传上git了。可以将不需要上传的文件加入 .gitignore文件来忽略上传。否则,那不天下大乱了吗~
去学习下git吧,这是git的文件,存在即有道理。
删除了,影响更大。
用git提交的时候 不会把一些本地的配置 测试环境的信息提交
用git提交的时候 不会把一些本地的配置 测试环境的信息提交

findAll();[2.0]

Aibydolphin阅读(90)

试问findAll(['id'=>1,'status'=>ture]);是否能得到同时满足两个条件的activeRecord结果集?

可以的骚年 但是你的 ‘status’=>ture 我着实看不懂。
另外可以使用 这种形式的查询方式
我还没来就回答了,你们真厉害,哈哈
findAll很多框架有这个方法

登录

找回密码

注册