yii 随笔(二):创建第一个用户(yii2脚本程序初识)

1. 进入到 webroot/advanced (yii安装目录)

2.创建数据库, 配置数据库
配置文件路径为:webroot/advanced/common/config/main-local.php

3. 进入到 webroot/advanced目录, 执行 yii migrate 命令(migrate命令是yii自带的数据库转移工具,可对数据库进行备份升级等操作)
该命令实质执行的数据文件是:webroot/advanced/console/migrations/*.php
该命令的执行控制器文件是:webroot/advanced/vendor/yiisoft/yii2/console/controllers/MigrateController.php

4. 现在有了现在数据库里有了 user表,现在建立一个可登陆的用户

5. 用命令行创建password
1). 创建新的命令行控制器

webroot/advanced/console/controllers/testController.php

2). 在新的命令行控制器写下

/**
 * 主命令
 * 本例预计执行示例:在yii根目录执行 yii test(或者 yii test/tes) 
 */

//不可少
namespace console\controllers;
//不可少
use Yii;
//控制器的名字首字母必须为大写,继承 console 控制器
class TestController extends \yii\console\Controller{
    //默认执行的子命令,首字母必须为小写
    public $defaultAction = 'tes';
    
    //执行的子命令
    public function actionTes(){
        echo Yii::$app->getSecurity()->generatePasswordHash('123123');//123123 是需要被设置的密码
        return 0;
    }
}

发表在 yii2 | 留下评论

yii 随笔(一):初始化环境

1. 下载高级模板包(我选择的是解压安装)
http://www.yiiframework.com/download/

2. 解压安装包(我下载的是https://github.com/yiisoft/yii2/releases/download/2.0.6/yii-advanced-app-2.0.6.tgz),到 webroot/advanced

3. 进到 webroot/advanced 执行 init,跟着提示走

4. 开启apache(关于安装,配置略)

5.访问前台 http://localhost/advanced/frontend/web/

发表在 yii2 | 留下评论

This TED Talk is frequently praised among the finest TED Discusses out there.

There’s small if any recognition of the counterargument to the writer’s position. It conditions pupils for essay writing by participating those in the procedure for composing numerous kinds paragraphs for example expository, convincing, and narrative. 继续阅读

发表在 Uncategorized | 留下评论

It’s exceedingly simple for your kids to observe the books supplied and place them when they’re done.

Man understands he have entirely free will. Men tend toward believe that the cosmos was made for their distinctive use. If some one comprehends which he/she can not understand Lord, then they won’t attempt judge additional individuals Every person knows their specific talents, flaws and possible. There are lots of methods a willing individual is able to include to the revolution of societal and financial relations in the world. 继续阅读

发表在 Uncategorized | 留下评论

It is rather important to be certain that the on-line, when selecting the best net defensive driving class in Arizona institution has got the recommendations that are ideal.

You’re probably to be spending A good deal of time with one of these folks It truly is determined by how much you’re prepared to spend and the length of time you give the author. It’s typically not transmissible, and vanishes after some minute, but in a number of cases, therapy and consult from the doctor may be needed. Do it 3-4 occasions per day till you become conscious of recovery. 继续阅读

发表在 Uncategorized | 留下评论

php 中 str_replace或者preg_replace对php代码的性能的影响

str_replace或者preg_replace对php代码的性能的影响,如下:


$str = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
$time = array_sum(explode(' ',microtime() ) );
for($i = 0;$i < 500; $i++){
	$str = $str;
}
echo 'time is: ' .(array_sum(explode(' ',microtime() ) ) - $time).'<br />';
$time = array_sum(explode(' ',microtime() ) );
for($i = 0;$i < 500; $i++){
	$str = str_replace('dolor','dolor',$str);
}
echo 'time is: ' .(array_sum(explode(' ',microtime() ) ) - $time).'(str_replace)<br />';
$time = array_sum(explode(' ',microtime() ) );
for($i = 0;$i < 500; $i++){
	$str = preg_replace("/dolor/",'dolor', $str);
}
echo 'time is: ' .(array_sum(explode(' ',microtime() ) ) - $time).'(preg_replace)<br />';
exit;
//time is: 0.000119924545288
//time is: 0.0014500617981(str_replace)
//time is: 0.00306391716003(preg_replace)
发表在 php 优化 | 留下评论

mysql left join,right join,inner join 的区别

mysql> select * from str;
+----+-----------+-----------+
| id | string    | scenario  |
+----+-----------+-----------+
|  1 | dddd      |           | 
|  2 | ssssff    | ffff      | 
|  3 | 1231      | 23123123  | 
|  4 | 123123123 | 123123123 | 
|  5 | ssssff    | ffff      | 
|  6 | asdfas    | fffffdsdf | 
+----+-----------+-----------+
6 rows in set (0.00 sec)

mysql> select * from str1;
+------+------+
| s_id | tag  |
+------+------+
|    1 | 33   | 
|    4 | aas  | 
|    5 | asdf | 
|    7 | sdf  | 
|    8 | asdf | 
+------+------+
5 rows in set (0.00 sec)

mysql> select * from str s left join str1  t on s.id = t.s_id;
+----+-----------+-----------+------+------+
| id | string    | scenario  | s_id | tag  |
+----+-----------+-----------+------+------+
|  1 | dddd      |           |    1 | 33   | 
|  2 | ssssff    | ffff      | NULL | NULL | 
|  3 | 1231      | 23123123  | NULL | NULL | 
|  4 | 123123123 | 123123123 |    4 | aas  | 
|  5 | ssssff    | ffff      |    5 | asdf | 
|  6 | asdfas    | fffffdsdf | NULL | NULL | 
+----+-----------+-----------+------+------+
6 rows in set (0.00 sec)

mysql> select * from str s right join str1  t on s.id = t.s_id;
+------+-----------+-----------+------+------+
| id   | string    | scenario  | s_id | tag  |
+------+-----------+-----------+------+------+
|    1 | dddd      |           |    1 | 33   | 
|    4 | 123123123 | 123123123 |    4 | aas  | 
|    5 | ssssff    | ffff      |    5 | asdf | 
| NULL | NULL      | NULL      |    7 | sdf  | 
| NULL | NULL      | NULL      |    8 | asdf | 
+------+-----------+-----------+------+------+
5 rows in set (0.00 sec)

mysql> select * from str s inner join str1  t on s.id = t.s_id;
+----+-----------+-----------+------+------+
| id | string    | scenario  | s_id | tag  |
+----+-----------+-----------+------+------+
|  1 | dddd      |           |    1 | 33   | 
|  4 | 123123123 | 123123123 |    4 | aas  | 
|  5 | ssssff    | ffff      |    5 | asdf | 
+----+-----------+-----------+------+------+
3 rows in set (0.00 sec)

mysql> select * from str s inner join str1  t ;
+----+-----------+-----------+------+------+
| id | string    | scenario  | s_id | tag  |
+----+-----------+-----------+------+------+
|  1 | dddd      |           |    1 | 33   | 
|  1 | dddd      |           |    4 | aas  | 
|  1 | dddd      |           |    5 | asdf | 
|  1 | dddd      |           |    7 | sdf  | 
|  1 | dddd      |           |    8 | asdf | 
|  2 | ssssff    | ffff      |    1 | 33   | 
|  2 | ssssff    | ffff      |    4 | aas  | 
|  2 | ssssff    | ffff      |    5 | asdf | 
|  2 | ssssff    | ffff      |    7 | sdf  | 
|  2 | ssssff    | ffff      |    8 | asdf | 
|  3 | 1231      | 23123123  |    1 | 33   | 
|  3 | 1231      | 23123123  |    4 | aas  | 
|  3 | 1231      | 23123123  |    5 | asdf | 
|  3 | 1231      | 23123123  |    7 | sdf  | 
|  3 | 1231      | 23123123  |    8 | asdf | 
|  4 | 123123123 | 123123123 |    1 | 33   | 
|  4 | 123123123 | 123123123 |    4 | aas  | 
|  4 | 123123123 | 123123123 |    5 | asdf | 
|  4 | 123123123 | 123123123 |    7 | sdf  | 
|  4 | 123123123 | 123123123 |    8 | asdf | 
|  5 | ssssff    | ffff      |    1 | 33   | 
|  5 | ssssff    | ffff      |    4 | aas  | 
|  5 | ssssff    | ffff      |    5 | asdf | 
|  5 | ssssff    | ffff      |    7 | sdf  | 
|  5 | ssssff    | ffff      |    8 | asdf | 
|  6 | asdfas    | fffffdsdf |    1 | 33   | 
|  6 | asdfas    | fffffdsdf |    4 | aas  | 
|  6 | asdfas    | fffffdsdf |    5 | asdf | 
|  6 | asdfas    | fffffdsdf |    7 | sdf  | 
|  6 | asdfas    | fffffdsdf |    8 | asdf | 
+----+-----------+-----------+------+------+
30 rows in set (0.00 sec)
发表在 mysql | 留下评论

判断客户端是否是手机


function is_mobile(){
	$regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
	$regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
	$regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";
	$regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|";
	$regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220";
	$regex_match.=")/i";
	
	return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
}

转自:http://snipplr.com/view/48763/simple-user-agent-mobile-and-smartphone-detection-and-redirction-with-php/

发表在 php函数集 | 留下评论

php计算月份差

/*
 *取某个日期到现在时间的月份差值。如果不够一个月,按一个月算
 */
function diffMonth($date){
        if(strtotime($date) < time() ){
                $start = $date;
                $end  = date('Y-n-j');
        }else{
                $start = date('Y-n-j');
                $end  = $date;
        }
        $starY = date("Y",strtotime($start));
        $starM = date("n",strtotime($start));
        $starD = date("j",strtotime($start));
	
        $nowY = date("Y",strtotime($end));
        $nowM = date("n",strtotime($end));
        $nowD = date("j",strtotime($end));
	
        $diffM = 0;
	
        if($starY == $nowY){
                if($starM == $nowM){
                        if($starD < $nowD){
                                $diffM = 1;
                        }elseif($starD = $nowD){
                                $diffM = 0;
                        }else{
                                $diffM = false;
                        }
                }elseif($starM < $nowM){
                        if($starD < $nowD){
                                $diffM = $nowM - $starM + 1;
                        }else{
                                $diffM = $nowM - $starM;
                        }
                }else{
                        $diffM = false;
                }
        }elseif($starY < $nowY){
                $diffY = $nowY - $starY;
                if($starD < $nowD){
                        $diffM = (12 - $starM + $nowM + 1) + 12 * ($diffY - 1);
                }else{
                        $diffM = (12 - $starM + $nowM) + 12 * ($diffY - 1);
                }
	
        }else{
                $diffM = false;
        }
	
        return $diffM;
}
发表在 php函数集 | 一条评论

js 得到函数名称

function getFunctionName(fn) {
	if (typeof fn != "function") throw "the argument must be a function.";
	var reg = /W*functions+([w$]+)s*\(/;
	var name = reg.exec(fn);
	if (!name) {
	return '(Anonymous)';
	}
	return name[1];
}
发表在 js | 留下评论