javalzbin
- javalzbin 2016-10-21 已签到连续签到242天,获得了20个金钱
- javalzbin 2016-10-20 已签到连续签到241天,获得了20个金钱
yii2的数据交互就有很明显的例子丫:
$db = Yii::$app->db; $outerTransaction = $db->beginTransaction(); try { $db->createCommand($sql1)->execute(); $innerTransaction = $db->beginTransaction(); try { $db->createCommand($sql2)->execute(); $innerTransaction->commit(); } catch (\Exception $e) { $innerTransaction->rollBack(); throw $e; } $outerTransaction->commit(); } catch (\Exception $e) { $outerTransaction->rollBack(); throw $e; }
@xczizz 哥们,我觉得你这个说法好像不对,如果确实是事务的控制,应该是其中有一个出错,必须的影响其他,保证一致性,要么全部成功,要么全部失败,所以在catch中需要回滚。
yii2的数据交互就有很明显的例子丫:
$db = Yii::$app->db; $outerTransaction = $db->beginTransaction(); try { $db->createCommand($sql1)->execute(); $innerTransaction = $db->beginTransaction(); try { $db->createCommand($sql2)->execute(); $innerTransaction->commit(); } catch (\Exception $e) { $innerTransaction->rollBack(); throw $e; } $outerTransaction->commit(); } catch (\Exception $e) { $outerTransaction->rollBack(); throw $e; }
@iceluo 我也不知道怎么表达,但是我的理解是,如果希望程序在出现运行时错误的时候,还能正常的执行代码,就使用异常,比如,你的数据库操作,当你不捕获异常,那么页面显示的就是500,当我捕获异常之后,我的catch语句还能执行,我可以子啊catch语句中做其他处理,然后catch语句之后,我还能继续执行其他逻辑,并且按照我的预期返回比500更合适的提示。
yii2的数据交互就有很明显的例子丫:
$db = Yii::$app->db; $outerTransaction = $db->beginTransaction(); try { $db->createCommand($sql1)->execute(); $innerTransaction = $db->beginTransaction(); try { $db->createCommand($sql2)->execute(); $innerTransaction->commit(); } catch (\Exception $e) { $innerTransaction->rollBack(); throw $e; } $outerTransaction->commit(); } catch (\Exception $e) { $outerTransaction->rollBack(); throw $e; }
- javalzbin 2016-10-19 已签到连续签到240天,获得了20个金钱
把你的域名指向的目录,定向到basic/web/这个目录下,nginx的配置大概是这样:
location ~ \.php$ { root /xxx/xxx/basic/web/; ......//其他配置 }
那样,访问路径就变成了www.kinstu.pw/index.php?r=控制器/操作
如果你需要 www.kinstu.pw/basic/web/index.php?r=控制器/操作,,这样访问,那么你的配置的路径应该是这样:
location ~ \.php$ { root /xxx/xxx/; ......//其他配置 }
最后顺便说下,你还可以把index.php也省掉,配置是这样:
location / { root /xxx/xxx/basic/web/; index index.php index.html index.htm; if (!-e $request_filename) { rewrite ^/index.php(.*)$ /index.php?s=$1 last; rewrite ^(.*)$ /index.php?s=$1 last; break; } }
那么你访问就是 www.kinstu.pw/?r=控制器/操作,这样来访问。
- javalzbin 2016-10-18 已签到连续签到239天,获得了20个金钱
输出图片,可以这样:
$photo='图片路径.jpg'; $size = getimagesize($photo); //获取mime信息 $fp=fopen($photo, "rb"); //二进制方式打开文件 header("Content-type: {$size['mime']}"); fpassthru($fp); // 输出至浏览器 exit;
当然路径存在之类的判断你自己要做好,如果确定图片格式是jpeg,那么可以写死mime
header( "Content-type: image/jpeg"); $photo='图片路径.jpg'; $fp=fopen($photo, "rb"); //二进制方式打开文件 fpassthru($fp); // 输出至浏览器 exit;
- javalzbin 2016-10-17 已签到连续签到238天,获得了20个金钱