├── Closure.php ├── README.md ├── crc32.php ├── cross-domain.md ├── cto笔记 ├── 10CTO第十次课程 │ ├── postgresql.pptx │ └── redis.txt ├── 11 安装redis扩展.txt ├── 12 trait和单例 │ ├── phpmq.tar.gz │ ├── phpmq │ │ ├── PHPMQ.php │ │ ├── RedisPool.php │ │ ├── UserMQ.php │ │ ├── listen.php │ │ └── reg.php │ ├── redis-3.0.0.tar.gz │ ├── redislogin.tar.gz │ └── 作业.txt ├── 13 进程和线程.txt ├── 14 CTO第十四次课程.zip.tdlex ├── 15 数据库优化原理.txt ├── 16 mysql主从.txt ├── 17 mysql自建索引.txt ├── 19 中文分词技术实现.txt ├── 1CTO第一天课程 │ └── 第一天资料及软件 │ │ ├── CTO训练营.pptx │ │ ├── CTO训练营2.pptx │ │ ├── Ubuntu服务器端下载地址.txt │ │ └── putty.zip ├── 2 CTO第二天课程.非对称秘钥.txt ├── 20 数据库分表与分库方式方法.txt ├── 21 缓存.txt ├── 23 生成静态注意细节.txt ├── 24 mongodb.txt ├── 3 隔离 │ ├── 架构图.jpg │ └── 课堂笔记.txt ├── 4 git │ ├── CTO训练营Git.ppt │ ├── CTO训练营Git.pptx │ ├── Git 常用命令.docx │ ├── GitHubSetup.exe │ └── 笔记.txt ├── 5 composer │ ├── CTO训练营之组件化开发和依赖管理.ppt │ └── 学习笔记.txt ├── 6 composer示例.txt ├── 7 nigix知识.txt ├── 8 测试驱动phpunit-book.pdf ├── 9 mariadb │ ├── CTO训练营-数据库.pptx │ └── 笔记.txt ├── redis-dump.txt └── yii2学习.txt ├── function.php ├── ioc.php ├── nginx ├── shell ├── rsync │ ├── README.md │ └── test_push_code.sh ├── shell笔记 │ ├── 10.1shell概述.txt │ ├── 10.2shell脚本运行方式.txt │ ├── 10.3.1历史命令与补全能.txt │ ├── 10.3.2别名与快捷键.txt │ ├── 10.3.3输入和输出重定向.txt │ ├── 10.3.4多命令顺序执行与管道符.txt │ ├── 10.3.5通配符和其他特殊符号.txt │ ├── 10.4.1用户自定义变量.txt │ ├── 10.4.2环境变量.txt │ ├── 10.4.3位置参数变量.txt │ ├── 10.4.4预定义变量.txt │ ├── 10.5.1数值运算与运算符.txt │ ├── 10.5.2变量测试与内容替换.txt │ ├── 10.6.环境变量配置文件.txt │ ├── 11.1正则表达式.txt │ ├── 11.2.1字符串截取-cut.txt │ ├── 11.2.2字符串截取-printf.txt │ ├── 11.2.3字符截取命令-awk.txt │ ├── 11.2.4字符截取命令-sed.txt │ ├── 11.3字符处理命令.txt │ ├── 11.4条件判断.txt │ ├── 11.5.1if语句.txt │ ├── 11.5.2case语句.txt │ └── 11.5.3for循环.txt └── task │ ├── README.md │ ├── auto_crate_crontab │ ├── cron.sh │ ├── cron_config │ ├── job.sh │ ├── run_jobs.sh │ ├── stop_jobs.sh │ └── test_push_code.sh ├── spl.md └── vhost.md /Closure.php: -------------------------------------------------------------------------------- 1 | active(); 18 | } 19 | } 20 | 21 | class app 22 | { 23 | 24 | public function bind ($str, $function) 25 | { 26 | if ($function instanceof Closure) 27 | { 28 | $this->binds[$str] = $function; 29 | } 30 | else 31 | { 32 | $this->instances[$str] = $function; 33 | } 34 | } 35 | 36 | public function make ($abstract,$parame = []) 37 | { 38 | if(isset($this->instances[$abstract])) 39 | { 40 | return $this->instances[$abstract]; 41 | } 42 | 43 | array_unshift($parame,$this); 44 | 45 | return call_user_func_array($this->binds[$abstract], $parame); 46 | } 47 | } 48 | 49 | $app = new app(); 50 | //超能力生产脚本 51 | $app->bind('person', function ($app,$parame) 52 | { 53 | return new person($app->make($parame)); 54 | }); 55 | //注入“飞的”超能力 56 | $app->bind('fly',new fly()); 57 | 58 | $app->make('person',['fly']); 59 | 60 | ?> 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # function 2 | 3 | 4 | ico ---- laravel依赖注入原理 5 | 6 | crc32 ---- hash算法,分表原理 7 | 8 | closure ----超级工厂(注入) 9 | 10 | 11 | vhost ----服务器转发请求和配置php 12 | -------------------------------------------------------------------------------- /crc32.php: -------------------------------------------------------------------------------- 1 | hash_function = $hash_function; 23 | } 24 | 25 | protected function getServerPosition($str){ 26 | return $this->hash_function->hash($str); 27 | } 28 | 29 | protected function sortServer(){ 30 | ksort($this->server_nodes); 31 | } 32 | 33 | public function find($key){ 34 | $positon = $this->hash_function->hash($key); 35 | 36 | $server = current($this->server_nodes); 37 | 38 | foreach($this->server_nodes as $k=>$v){ 39 | 40 | if($key > $positon){ 41 | $server = $v; 42 | break; 43 | } 44 | } 45 | 46 | return $server; 47 | } 48 | 49 | 50 | public function add($ip,$port){ 51 | for($i = 0;$i<$this->virtual_num;$i++){ 52 | $this->server_nodes[$this->getServerPosition($ip.":".$port.':'.$ip)] = array('ip'=>$ip,'port'=>$port); 53 | } 54 | $this->sortServer(); 55 | } 56 | 57 | public function remover($ip,$port){ 58 | for ($i = 0;$i<$this->virtual_num;$i++){ 59 | unset($this->server_nodes[$this->getServerPosition($ip.':'.$port .':' .$i)]); 60 | } 61 | } 62 | 63 | } 64 | 65 | 66 | $s = new Consistent(new crc32Hash()); 67 | 68 | $s->add("192.168.1.1",'11211'); 69 | $s->add("192.168.2.1",'11211'); 70 | $s->add("192.168.3.1",'11211'); 71 | $s->add("192.168.4.1",'11211'); 72 | $s->add("192.168.5.1",'11211'); 73 | 74 | $a = $s->find("key"); 75 | 76 | $s->remover("192.168.2.1", '11211'); 77 | $b = $s->find("key"); 78 | var_dump($a); 79 | var_dump($b); 80 | 81 | $tmp = sprintf("%u",crc32('abc')); 82 | 83 | 84 | 85 | 86 | 87 | /*---------------分割线-------------------*/ 88 | 89 | 90 | 91 | 92 | 93 | class team{ 94 | 95 | public $arr = array(); 96 | public function add($arr) 97 | { 98 | if(in_array($arr, $this->arr)) return true; 99 | $this->arr[] = $arr; 100 | } 101 | 102 | public function remove($arr) 103 | { 104 | $this->arr = array_diff($this->arr,array($arr)); 105 | } 106 | 107 | 108 | 109 | } 110 | 111 | 112 | $team = new team(); 113 | $team->add('c'); 114 | $team->add('b'); 115 | $team->add('a'); 116 | 117 | $team->remove('b'); 118 | //var_dump($team->arr); 119 | 120 | 121 | //装饰者 122 | abstract class Beverage{ 123 | public $_name; 124 | abstract public function cost(); 125 | } 126 | 127 | //被装饰者 128 | 129 | class Coffee extends Beverage{ 130 | public function __construct(){ 131 | $this->_name = 'Coffee'; 132 | } 133 | public function cost(){ 134 | return 2; 135 | } 136 | } 137 | 138 | class Milk extends Beverage{ 139 | public $_beverage; 140 | public function __construct($beverage){ 141 | $this->_name = 'Milk'; 142 | $this->_beverage = $beverage; 143 | } 144 | 145 | public function cost(){ 146 | return $this->_beverage->cost() + 1; 147 | } 148 | 149 | } 150 | 151 | 152 | $coffee = new Coffee(); 153 | $coffee = new Milk($coffee); 154 | //var_dump($coffee->cost()); 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | ?> 173 | -------------------------------------------------------------------------------- /cross-domain.md: -------------------------------------------------------------------------------- 1 | ##ajax跨域可以这样解决,也真是大吃一惊啊, 2 | 3 | 直接上 Demo 4 | 5 | 6 | ###CORS语法 7 | 8 | header(‘Access-Control-Allow-Origin: http://www.example.com/’); //指定某域下才可访问 9 | 10 | header(‘Access-Control-Allow-Methods: GET, POST, PUT, DELETE’); //可用方法 不写为全部 11 | 12 | header(‘Access-Control-Max-Age: 3628800′); //数据缓存有效期 13 | 14 | 15 | 一般来说只写第一条就可以满足大部分的需求 16 | 17 | ###具体代码: 18 | 19 | >php端,以下是比较粗暴有效的做法,为了安全可参考上面的选项 20 | 21 | 22 | ``` 23 | 前端 30 | 31 | ``` 32 | 42 | ``` 43 | 44 | 45 | 这样就能解决跨域的问题,竟也是无言以对 46 | -------------------------------------------------------------------------------- /cto笔记/10CTO第十次课程/postgresql.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/10CTO第十次课程/postgresql.pptx -------------------------------------------------------------------------------- /cto笔记/10CTO第十次课程/redis.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/10CTO第十次课程/redis.txt -------------------------------------------------------------------------------- /cto笔记/11 安装redis扩展.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/11 安装redis扩展.txt -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/phpmq.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/12 trait和单例/phpmq.tar.gz -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/phpmq/PHPMQ.php: -------------------------------------------------------------------------------- 1 | init(); 12 | } 13 | return self::$instance; 14 | } 15 | 16 | } 17 | 18 | 19 | 20 | abstract class PHPMQ 21 | { 22 | abstract protected function getKey(); 23 | abstract protected function package(); 24 | abstract protected function unpackage(); 25 | protected $redis; 26 | 27 | public function init() 28 | { 29 | RedisPool::addServer(array("F1"=>array('127.0.0.1',6379))); 30 | $redis=RedisPool::getRedis("F1"); 31 | } 32 | 33 | public function push($msg) 34 | { 35 | $redis->rpush($this->getKey(),$this->package($msg)); 36 | } 37 | 38 | public function pop($msg) 39 | { 40 | $this->unpackage($redis->lpop($this->getKey())); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/phpmq/RedisPool.php: -------------------------------------------------------------------------------- 1 | $data){ 11 | self::$servers[$alias]=$data; 12 | } 13 | 14 | } 15 | 16 | public static function getRedis($alias,$select=0) 17 | { 18 | if(!array_key_exists($alias,self::$connections)){ 19 | $redis=new Redis(); 20 | $redis->connect(self::$servers[$alias][0],self::$servers[$alias][1]); 21 | self::$connections[$alias]=$redis; 22 | if(isset(self::$servers[$alias][2]) && self::$servers[$alias][2]!=""){ 23 | self::$connections[$alias]->auth(self::$servers[$alias][2]); 24 | } 25 | } 26 | self::$connections[$alias]->select($select); 27 | return self::$connections[$alias]; 28 | 29 | } 30 | 31 | 32 | 33 | 34 | 35 | 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/phpmq/UserMQ.php: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/phpmq/listen.php: -------------------------------------------------------------------------------- 1 | pop(); 9 | if ($msg!=null){ 10 | 11 | } 12 | 13 | } 14 | 15 | 16 | 17 | ?> 18 | -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/phpmq/reg.php: -------------------------------------------------------------------------------- 1 | getMessage); 16 | } 17 | */ 18 | $conf=array( 19 | 'FA'=>array('127.0.0.1',6379) 20 | ); 21 | 22 | RedisPool::addServer($conf); 23 | $redis= RedisPool::getRedis('FA'); 24 | $username=$_POST["username"]; 25 | $password=$_POST["password"]; 26 | $data=array(); 27 | $data["username"]=$username; 28 | $data["password"]=$password; 29 | require '../../lib/UserMQ.php'; 30 | UserMQ:MQ()->push($data); 31 | // $sql = "insert into tb_user values(null,?,?)"; 32 | // $stmt = $pdo->prepare($sql); 33 | // $stmt->execute(array($username,$password)); 34 | 35 | $redis->set("string:user:".$username,$password); 36 | 37 | //$redis->rpush("list:users",$username); 38 | } 39 | 40 | 41 | ?> 42 | 43 | 44 | 45 |
46 | username:
47 | password:
48 | 49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/redis-3.0.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/12 trait和单例/redis-3.0.0.tar.gz -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/redislogin.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/12 trait和单例/redislogin.tar.gz -------------------------------------------------------------------------------- /cto笔记/12 trait和单例/作业.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/12 trait和单例/作业.txt -------------------------------------------------------------------------------- /cto笔记/13 进程和线程.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/13 进程和线程.txt -------------------------------------------------------------------------------- /cto笔记/14 CTO第十四次课程.zip.tdlex: -------------------------------------------------------------------------------- 1 | [Property] 2 | IsTptFirstTask=0 3 | -------------------------------------------------------------------------------- /cto笔记/15 数据库优化原理.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/15 数据库优化原理.txt -------------------------------------------------------------------------------- /cto笔记/16 mysql主从.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/16 mysql主从.txt -------------------------------------------------------------------------------- /cto笔记/17 mysql自建索引.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/17 mysql自建索引.txt -------------------------------------------------------------------------------- /cto笔记/19 中文分词技术实现.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/19 中文分词技术实现.txt -------------------------------------------------------------------------------- /cto笔记/1CTO第一天课程/第一天资料及软件/CTO训练营.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/1CTO第一天课程/第一天资料及软件/CTO训练营.pptx -------------------------------------------------------------------------------- /cto笔记/1CTO第一天课程/第一天资料及软件/CTO训练营2.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/1CTO第一天课程/第一天资料及软件/CTO训练营2.pptx -------------------------------------------------------------------------------- /cto笔记/1CTO第一天课程/第一天资料及软件/Ubuntu服务器端下载地址.txt: -------------------------------------------------------------------------------- 1 | http://releases.ubuntu.com/14.04.1/ubuntu-14.04.1-server-amd64.iso -------------------------------------------------------------------------------- /cto笔记/1CTO第一天课程/第一天资料及软件/putty.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/1CTO第一天课程/第一天资料及软件/putty.zip -------------------------------------------------------------------------------- /cto笔记/2 CTO第二天课程.非对称秘钥.txt: -------------------------------------------------------------------------------- 1 | 1.选择 LTS 版本 2 | 2.远程连接配通 3 | 3.apt-get update 更新 4 | 使用apt-get时必需使用管理员权限 5 | 6 | 7 | 注意 : 服务器默认不要使用root进行远程登录 8 | 切换root用户的方法 9 | sudo su 10 | (无需再次输入 sudo)使用 apt-get install vim 安装vim 编辑器 11 | 12 | 开启远程管理 需要安装 openssh-server (apt-get install openssh-server) 13 | 安装完以后 ,/etc/init.d/ssh start 14 | mac 通过ssh进行远程连接服务器 (ssh cyl@192.168.123.3) 15 | .ssh 16 | 使用 ifconfig命令 可以查看服务器的IP地址 17 | 18 | 无密码登入: 19 | 20 | 1) .ssh目录的权限必须是700 21 | 22 | 2) .ssh/authorized_keys文件权限必须是600 23 | 24 | linux或 mac下 生成密钥对的命令是 ssh-keygen -t rsa 默认生成路径在家目录的.ssh目录下 25 | 26 | 27 | 28 | 关闭密码登录,确保服务器安全(关闭密码登录之前,一定要能够正常使用密钥登录) 29 | 30 | 31 | 32 | 在用户的家目录下的.ssh目录(如果目录不存在就创建一个)authorized_keys 文件,并将生成的公钥文件的内容放到里面,就可以在本地使用密钥登录服务器 33 | 34 | 35 | 为了保障服务器安全,我们要将密码登录关闭 36 | 37 | 找到 /etc/ssh/sshd_config 修改 PasswordAuthentication yes(如果前面有# ,则需要把注释给去掉) 把yes 改成 no 38 | 39 | 40 | ssh 端口默认为 22 ,把端口号修改为大于一千的数值 41 | 42 | 43 | 44 | 假设,我们有一个商城项目 开发团队有三个小组,每个小组需要在自己本组内测试模块代码,如果测试通过则与其它小组合并代码并在本地服务器进行内部测试,内部测试再通过,将代码上传到公网服务器进行测试,经过一致两周的测试,没有严重问题,则将公网服务器中的代码推向产品服务器。 45 | 46 | -------------------------------------------------------------------------------- /cto笔记/20 数据库分表与分库方式方法.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/20 数据库分表与分库方式方法.txt -------------------------------------------------------------------------------- /cto笔记/21 缓存.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/21 缓存.txt -------------------------------------------------------------------------------- /cto笔记/23 生成静态注意细节.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/23 生成静态注意细节.txt -------------------------------------------------------------------------------- /cto笔记/24 mongodb.txt: -------------------------------------------------------------------------------- 1 | RDBMS 2 | 1.假定数据时结构明确的,数据时密集的 3 | 2.属性之间有关联 4 | 3.需要高度一致性 5 | 4.事务的处理和支持 6 | 7 | 8 | 9 | 10 | 11 | 12 | 某些情况下,关系型数据库暴露缺点 13 | 1.数据结构并不明确 14 | 2.数据结构变化中 15 | 3.单个数据库文件不宜过大 16 | 海量稀疏数据 17 | 18 | 19 | 面向列的数据库 20 | 按照数据属性进行保存,每个属性作为一个列 21 | 有两个直接的优点 22 | 1.增加字段 23 | 2.当某些数据为空的时候 24 | 3.列于列之间的对应关系通过行键来表示 25 | 26 | 27 | 28 | 29 | 函数式编成 30 | [{"10000":"Gao"},{"430000":"Chen"},{"21000":"Lee"}.......]; 31 | 32 | 33 | 互联网数据总量 34 | 接近1/2 YB 35 | 36 | 1024 B =1k 37 | 1024k = 1M 38 | 1024M = 1G 39 | 1024G = 1T 40 | 1024T = 1P 41 | 1024P = 1E 42 | 1024E = 1Z 43 | 1024Z = 1Y 44 | 45 | 46 | GPG Key 47 | 48 | 49 | sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 50 | 51 | 52 | 53 | echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list 54 | 55 | 56 | sudo apt-get update 57 | 58 | 59 | 60 | sudo apt-get install mongodb-org 61 | MongoDB Use 62 | start 63 | 64 | 65 | sudo service mongod start 66 | or 67 | sudo /etc/init.d/mongod start 68 | 69 | check 70 | 71 | sudo vim /var/log/mongodb/mongod.log 72 | 73 | 74 | 75 | sudo service mongod stop 76 | or 77 | sudo /etc/init.d/mongod stop 78 | 79 | 80 | sudo service mongod restart 81 | or 82 | sudo /etc/init.d/mongod restart -------------------------------------------------------------------------------- /cto笔记/3 隔离/架构图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/3 隔离/架构图.jpg -------------------------------------------------------------------------------- /cto笔记/3 隔离/课堂笔记.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/3 隔离/课堂笔记.txt -------------------------------------------------------------------------------- /cto笔记/4 git/CTO训练营Git.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/4 git/CTO训练营Git.ppt -------------------------------------------------------------------------------- /cto笔记/4 git/CTO训练营Git.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/4 git/CTO训练营Git.pptx -------------------------------------------------------------------------------- /cto笔记/4 git/Git 常用命令.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/4 git/Git 常用命令.docx -------------------------------------------------------------------------------- /cto笔记/4 git/GitHubSetup.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/4 git/GitHubSetup.exe -------------------------------------------------------------------------------- /cto笔记/4 git/笔记.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/4 git/笔记.txt -------------------------------------------------------------------------------- /cto笔记/5 composer/CTO训练营之组件化开发和依赖管理.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/5 composer/CTO训练营之组件化开发和依赖管理.ppt -------------------------------------------------------------------------------- /cto笔记/5 composer/学习笔记.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/5 composer/学习笔记.txt -------------------------------------------------------------------------------- /cto笔记/6 composer示例.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/6 composer示例.txt -------------------------------------------------------------------------------- /cto笔记/7 nigix知识.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/7 nigix知识.txt -------------------------------------------------------------------------------- /cto笔记/8 测试驱动phpunit-book.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/8 测试驱动phpunit-book.pdf -------------------------------------------------------------------------------- /cto笔记/9 mariadb/CTO训练营-数据库.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/9 mariadb/CTO训练营-数据库.pptx -------------------------------------------------------------------------------- /cto笔记/9 mariadb/笔记.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/cto笔记/9 mariadb/笔记.txt -------------------------------------------------------------------------------- /cto笔记/redis-dump.txt: -------------------------------------------------------------------------------- 1 | redis合并多个 dump.rdb 2 | 3 | 下载redis-dump文档地址:https://github.com/delano/redis-dump 4 | 5 | apt-get install ruby 6 | 7 | apt-get install ruby1.9.1-dev (yum instal ruby-devel) 8 | 9 | apt-get install rubygems 10 | 11 | gem install redis-dump 12 | 13 | 下载过程中提示 Error installing redis-dump: ERROR: Failed to build gem native extension. 14 | 15 | 添加 ruby1.9.1-dev包就可以解决这个问题了:apt-get install ruby1.9.1-dev 16 | -------------------------------------------------------------------------------- /cto笔记/yii2学习.txt: -------------------------------------------------------------------------------- 1 | ##Yii2 Lesson 1 安装框架并创建我们的第一个应用程序 2 | 3 | 1. 在官网下载basic模板, 通过压缩包安装, 下载地址 http://www.yiiframework.com/download/ 4 | 2. 然后解压, 将basic放到服务器根目录 5 | 3. 访问localhost/basic/web 发现没权限, 将basic/runtime 和 basic/web/assets basic/models basic/controllers basic/views (为了gii生成代码) 目录的读写权限给everyone 6 | 4. 然后访问发现非法配置, 修改config/web.php 将cookieValidationKey的value随便加一些字符串就行 7 | 8 | ##Yii2 Lesson 2 路由 9 | 10 | 1. 查看controllers, model, views/layouts views/site views/site/index.php 11 | 2. 修改首页视图内容, views/site/index.php 将

Congratulations!

修改为

Yii is Easy!

再刷新首页看一下 12 | 3. http://localhost/basic/web/index.php?r=site%2Fabout site是控制器, about是方法 13 | 4. 找到controllers/SiteController.php 发现里面有index, about, login方法等 14 | 5. 想在SiteController添加一个方法 15 | 16 | ``` 17 | public function actionHello() { 18 | return $this->render('hello'); 19 | } 20 | ``` 21 | 22 | 6. 在views/site/下面添加一个hello.php 23 | ``` 24 |

Welcome to Yii2

25 | ``` 26 | 27 | 7. 访问http://localhost/basic/web/index.php?r=site/hello 验证一下是否输出了我们想要的视图内容 28 | 8. 如果想要从控制器中传值到视图中, 修改控制器 29 | SiteController.php 30 | ``` 31 | public function actionHello() { 32 | $name = 'MaxwellDu'; 33 | return $this->render('hello', ['name' => $name]); 34 | } 35 | ``` 36 | 37 | hello.php 38 | ``` 39 |

Welcome to Yii2

40 | 41 | ``` 42 | 43 | ##Yii2 Lesson 3 Yii2中的表单 44 | 1. 创建一个model\UserForm.php 45 | ``` 46 | load(Yii::$app->request->post()) && $model->validate()) 75 | { 76 | //todo 77 | } else { 78 | return $this->render('userForm', ['model' => $model]); 79 | } 80 | } 81 | ``` 82 | 83 | 3.写一个视图文件 84 | views\site\userForm.php 85 | ``` 86 | 91 | 92 | 93 | 94 | field($model, 'name'); ?> 95 | field($model, 'email'); ?> 96 | 97 | 'btn btn-success']); ?> 98 | ``` 99 | 100 | 4. 验证后传递一个session, 提示正确, 修改控制器 101 | ``` 102 | 103 | public function actionUser() 104 | { 105 | $model = new UserForm; 106 | 107 | if($model->load(Yii::$app->request->post()) && $model->validate()) 108 | { 109 | //todo 110 | Yii::$app->session->setFlash('success', 'You have entered the data correctly'); 111 | } 112 | return $this->render('userForm', ['model' => $model]); 113 | 114 | } 115 | ``` 116 | 117 | 5. 视图文件中输出一下返回的session内容 118 | ``` 119 | 124 | 125 | session->getFlash('success')) { 127 | echo Yii::$app->session->getFlash('success'); 128 | } 129 | ?> 130 | 131 | 132 | 133 | field($model, 'name'); ?> 134 | field($model, 'email'); ?> 135 | 136 | 'btn btn-success']); ?> 137 | ``` 138 | 139 | ##Yii2 Lesson 4 连接数据库和ActiveRecords 140 | 141 | 1. 先将上节课的输出美化一下, 将视图文件的输出换成以下代码 142 | ``` 143 | session->getFlash('success')) { 145 | echo "
".Yii::$app->session->getFlash('success')."
"; 146 | } 147 | ?> 148 | ``` 149 | 150 | 2.配置数据库, config/db.php 151 | ``` 152 | 'yii\db\Connection', 156 | 'dsn' => 'mysql:host=127.0.0.1;dbname=yii2easy', 157 | 'username' => 'root', 158 | 'password' => 'root', 159 | 'charset' => 'utf8', 160 | ]; 161 | ``` 162 | 163 | 3. 连接mysql, 创建一个数据库 164 | mysql -uroot -proot 165 | create database yii2easy; 166 | use yii2easy; 167 | 168 | create table users (user_id int not null primary key auto_increment, username varchar(100), password varchar(32)); 169 | insert into users(username, password) values ('abc', 'jkljkl'); 170 | insert into users(username, password) values ('def', 'fdsfds'); 171 | 172 | create table posts (post_id int not null auto_increment primary key, post_title varchar(100), post_description text, author_id int, index(author_id)); 173 | 174 | 添加一个外键约束, posts的author_id关联用户表的user_id 175 | alter table `posts` add foreign key (`author_id`) references `users` (`user_id`) on delete restrict on update restrict; 176 | 177 | 178 | 4. 创建ActiveRecord文件, models\Users.php 179 | ``` 180 | all(); 206 | 207 | $this->render('index', ['users' => $users]); 208 | } 209 | } 210 | ``` 211 | 212 | 5. 创建视图文件 views/user/index.php 213 | ``` 214 | username."
"; 218 | } 219 | 220 | ?> 221 | ``` 222 | 223 | 224 | ##Yii2 Lesson 5 Gii模块的CRUD操作 225 | 226 | 1. 配置, basic模板默认已经配置好了, 在web.php的最下面 227 | ``` 228 | if (YII_ENV_DEV) { 229 | // configuration adjustments for 'dev' environment 230 | $config['bootstrap'][] = 'debug'; 231 | $config['modules']['debug'] = 'yii\debug\Module'; 232 | 233 | $config['bootstrap'][] = 'gii'; 234 | $config['modules']['gii'] = 'yii\gii\Module'; 235 | } 236 | ``` 237 | 238 | 2. 访问http://localhost/basic/web/index.php?r=gii 239 | 240 | 3. 生成model, 在table name里面输入 posts, 然后点击预览, 生成 241 | 242 | 4. 生成crud, 243 | 在model class中输入 app\models\Posts 244 | Search model class 输入 app\models\PostsSearch 245 | controller class 中输入 app\controllers\PostsController 246 | 预览, 生成 247 | 248 | 5. 路由去查看 http://localhost/basic/web/index.php?r=posts/index 尝试执行增删改查 249 | 250 | 251 | ##Yii2 Lesson 6 访问控制 252 | 253 | 1. 找到 controllers/PostController.php 中的这这段代码 254 | ``` 255 | 256 | public function behaviors() 257 | { 258 | return [ 259 | 'verbs' => [ 260 | 'class' => VerbFilter::className(), 261 | 'actions' => [ 262 | 'delete' => ['post'], 263 | ], 264 | ], 265 | ]; 266 | } 267 | ``` 268 | 269 | 2. 导入 访问控制类 270 | use yii\filters\AccessControl; 271 | 272 | 3. 将上面的代码添加内容, 现在如下 273 | ``` 274 | public function behaviors() 275 | { 276 | return [ 277 | 'access' => [ 278 | 'class' => AccessControl::className(), 279 | 'only' => ['create', 'update'], 280 | 'rules' => [ 281 | [ 282 | 'allow' => true, 283 | 'roles' => ['@'] 284 | ], 285 | ] 286 | ], 287 | 'verbs' => [ 288 | 'class' => VerbFilter::className(), 289 | 'actions' => [ 290 | 'delete' => ['post'], 291 | ], 292 | ], 293 | ]; 294 | } 295 | ``` 296 | 297 | 4. http://localhost/basic/web/index.php?r=posts%2Findex 访问这个可以正常, 点击创建, 就会跳到登录页面 298 | 输入用户名密码, admin admin登录即可发布 299 | 300 | 5. 查看某条记录 http://localhost/basic/web/index.php?r=posts%2Fview&id=1 301 | 访问到的是postsController 控制器中的actionView方法, 后面的id会传到方法的参数里面, 用来查找model 302 | 303 | 6. 比如说查看一条不存在的记录 http://localhost/basic/web/index.php?r=posts%2Fview&id=100 304 | 305 | 7. 查看创建的地址, 控制器, 模型, 视图文件, http://localhost/basic/web/index.php?r=posts%2Fcreate 306 | 307 | 308 | ##Yii Lesson 7 安装高级模板 309 | 310 | 1. 在官网下载压缩包, 高级模板的压缩包 311 | 312 | 2. 切换到根目录 cd /Library/WebServer/Documents/advanced 313 | 314 | 3. 执行初始化 php init 315 | 选0 316 | yes 317 | 318 | 看输出, 做了些什么事情 319 | 320 | 4. 配置数据库, common\config\main-local.php 321 | 'db' => [ 322 | 'class' => 'yii\db\Connection', 323 | 'dsn' => 'mysql:host=127.0.0.1;dbname=advanced_yii2', 324 | 'username' => 'root', 325 | 'password' => 'root', 326 | 'charset' => 'utf8', 327 | ], 328 | 329 | 5. 创建数据库 330 | create database advanced_yii2; 331 | 332 | 6. 执行数据库迁移 333 | ./yii migrate 334 | 335 | 7. 现在访问首页可以正常了 http://localhost/advanced/backend/web/index.php?r=site%2Flogin 336 | 337 | 8. 注册第一个用户 maxwelldu maxwell@du.com maxwelldu 338 | 然后自动登录了 339 | 340 | 341 | ##Yii Lesson 8 高级模板 定制化注册表单 342 | 343 | 344 | http://localhost/advanced/frontend/web/index.php?r=site%2Fsignup 345 | 1. 找到 site控制器, signup方法, SignupForm表单, views/site/signup.php 视图 模型里面会用到 common\models\User.php 346 | 347 | 2. 修改表结构, 添加一个first_name 和 last_name 348 | alter table `user` add `first_name` varchar(100) not null after `id`; 349 | alter table `user` add `last_name` varchar(100) not null after `first_name`; 350 | 351 | 3.我们需要修改 frontend/models/SignupForm.php 352 | 添加两个属性 353 | public $first_name; 354 | public $last_name; 355 | 356 | 添加两个规则 357 | ['first_name', 'required'], 358 | ['last_name', 'required'], 359 | 360 | 4. 在views/site/signup.php中的表单中添加两个 361 | field($model, 'first_name') ?> 362 | field($model, 'last_name') ?> 363 | 364 | 可以打开注册页面看一下 365 | 366 | 5. 然后我们要在注册的时候将内容赋值 367 | 在frontend/models/SignupForm.php中添加 368 | $user->first_name = $this->first_name; 369 | $user->last_name = $this->last_name; 370 | 371 | 6. 打开注册页面, 填写内容就可以注册了 372 | first_name 和 last_name 都会被保存起来 373 | 374 | 7. 自定义消息 375 | ['first_name', 'required', 'message' => 'have to fill this field.'], 376 | 377 | 378 | ##Yii Lesson 9 高级模板 CRUD 生成器, 通过Gii工具 379 | 380 | 381 | 1. 建三张表, 并设置好外键约束 382 | -- 383 | -- 表的结构 `branches` 384 | -- 385 | 386 | CREATE TABLE IF NOT EXISTS `branches` ( 387 | `branch_id` int(11) NOT NULL AUTO_INCREMENT, 388 | `companies_company_id` int(11) NOT NULL, 389 | `branch_name` varchar(100) NOT NULL, 390 | `branch_address` varchar(255) NOT NULL, 391 | `branch_created_date` datetime NOT NULL, 392 | `branch_status` enum('active','inactive') NOT NULL, 393 | PRIMARY KEY (`branch_id`), 394 | KEY `companies_company_id` (`companies_company_id`) 395 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 396 | 397 | -- -------------------------------------------------------- 398 | 399 | -- 400 | -- 表的结构 `companies` 401 | -- 402 | 403 | CREATE TABLE IF NOT EXISTS `companies` ( 404 | `company_id` int(11) NOT NULL AUTO_INCREMENT, 405 | `company_name` varchar(100) NOT NULL, 406 | `company_email` varchar(100) NOT NULL, 407 | `company_address` varchar(255) NOT NULL, 408 | `company_created_date` datetime NOT NULL, 409 | `company_status` enum('active','inactive') NOT NULL, 410 | PRIMARY KEY (`company_id`) 411 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 412 | 413 | -- -------------------------------------------------------- 414 | 415 | -- 416 | -- 表的结构 `departments` 417 | -- 418 | 419 | CREATE TABLE IF NOT EXISTS `departments` ( 420 | `department_id` int(11) NOT NULL AUTO_INCREMENT, 421 | `branches_branch_id` int(11) NOT NULL, 422 | `department_name` varchar(100) NOT NULL, 423 | `companies_company_id` int(11) NOT NULL, 424 | `department_created_date` datetime NOT NULL, 425 | `department_status` enum('active','inactive') NOT NULL, 426 | PRIMARY KEY (`department_id`), 427 | KEY `branches_branch_id` (`branches_branch_id`), 428 | KEY `companies_company_id` (`companies_company_id`) 429 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 430 | -- 431 | -- 限制导出的表 432 | -- 433 | 434 | -- 435 | -- 限制表 `branches` 436 | -- 437 | ALTER TABLE `branches` 438 | ADD CONSTRAINT `branches_ibfk_1` FOREIGN KEY (`companies_company_id`) REFERENCES `companies` (`company_id`); 439 | 440 | -- 441 | -- 限制表 `departments` 442 | -- 443 | ALTER TABLE `departments` 444 | ADD CONSTRAINT `departments_ibfk_2` FOREIGN KEY (`companies_company_id`) REFERENCES `companies` (`company_id`), 445 | ADD CONSTRAINT `departments_ibfk_1` FOREIGN KEY (`branches_branch_id`) REFERENCES `branches` (`branch_id`); 446 | 447 | 448 | 2. http://localhost/advanced/backend/web/index.php?r=gii 登录maxwelldu maxwelldu 449 | 450 | 3. 创建模型 451 | table name companies 452 | namespace backend\models 453 | 454 | 然后是 branches 455 | 然后是 departments 456 | 457 | 4. 创建CRUD 458 | backend\models\Companies 459 | backend\models\CompaniesSearch 460 | backend\controllers\CompaniesController 461 | 462 | 然后分别是branches 和 departments 463 | 464 | 5. 打开公司的首页 465 | http://localhost/advanced/backend/web/index.php?r=companies%2Findex 466 | 467 | 点击创建公司 468 | http://localhost/advanced/backend/web/index.php?r=companies%2Fcreate 469 | 470 | 在最后一个公司状态里面会看到一个Active和Inactive选项, 原因是因为我们数据库里面定义的是枚举 471 | 472 | 6. 发现创建时间是需要手动填写的, 找到backend/views/companies/_form.php 473 | 将这个字段控制给删除 474 | 475 | 7. 修改控制器, 创建公司的那个action 476 | ``` 477 | public function actionCreate() 478 | { 479 | $model = new Companies(); 480 | 481 | if ($model->load(Yii::$app->request->post()) && $model->save()) { 482 | return $this->redirect(['view', 'id' => $model->company_id]); 483 | } else { 484 | return $this->render('create', [ 485 | 'model' => $model, 486 | ]); 487 | } 488 | } 489 | ``` 490 | 491 | 修改为以下代码 492 | 493 | ``` 494 | public function actionCreate() 495 | { 496 | $model = new Companies(); 497 | 498 | if ($model->load(Yii::$app->request->post())) { 499 | $model->company_created_date = date('Y-m-d h:m:s'); 500 | $model->save(); 501 | return $this->redirect(['view', 'id' => $model->company_id]); 502 | } else { 503 | return $this->render('create', [ 504 | 'model' => $model, 505 | ]); 506 | } 507 | } 508 | ``` 509 | 510 | 8. 为了让状态字段显示的更友好, 打开backend/views/companies/_form.php中的 511 | field($model, 'company_status')->dropDownList([ 'active' => 'Active', 'inactive' => 'Inactive', ], ['prompt' => '']) ?> 512 | 最后的 prompt填上Status 513 | 514 | 9. 为了让查询的地方不显示id, 打开 backend/views/companies/index.php 中将gridview中的company_id 给注释起来即可 515 | $dataProvider, 517 | 'filterModel' => $searchModel, 518 | 'columns' => [ 519 | ['class' => 'yii\grid\SerialColumn'], 520 | 521 | // 'company_id', 522 | 'company_name', 523 | 'company_email:email', 524 | 'company_address', 525 | 'company_created_date', 526 | // 'company_status', 527 | 528 | ['class' => 'yii\grid\ActionColumn'], 529 | ], 530 | ]); ?> 531 | 532 | 10. 再看branches 533 | http://localhost/advanced/backend/web/index.php?r=branches%2Findex 534 | 535 | company id 先填我们创建的记录 1 536 | 537 | 11. 将branches_created_at 删除, 将状态添加一个状态提示, index里面将id隐藏, 将创建分支的方法像上面一样修改一下 538 | 539 | 12. 创建完一个branch以后看首页, 540 | 541 | http://localhost/advanced/backend/web/index.php?r=branches%2Findex 542 | 543 | 我们看到这个分支上面显示的公司的是id, 而不是公司的名称, 我们打开backend/models/Branches.php看到有个方法是 getCompaniesCompany() 是获取公司的一条记录 544 | 545 | 所以我们可以在backend/views/branch/index.php中的 gridview的字段companies_company_id 修改为 companiesCompany.company_name 546 | 547 | 再回去刷新, 发现显示的是公司的名称了 548 | 549 | 13. 最后再将部门相关的内容修改一下 550 | 551 | http://localhost/advanced/backend/web/index.php?r=departments%2Findex 552 | 553 | 修改控制器的添加方法 554 | 在_form.php中将创建时间删除, 将状态添加一个提示 555 | 后面将branch_id 修改为dropdownlist 556 | 557 | 添加一条记录 558 | 559 | index.php中将department_id删除 560 | 561 | 修改为后 562 | ``` 563 | 564 | $dataProvider, 566 | 'filterModel' => $searchModel, 567 | 'columns' => [ 568 | ['class' => 'yii\grid\SerialColumn'], 569 | 570 | 'companiesCompany.company_name', 571 | 'branchesBranch.branch_name', 572 | 'department_name', 573 | 574 | 'department_created_date', 575 | // 'department_status', 576 | 577 | ['class' => 'yii\grid\ActionColumn'], 578 | ], 579 | ]); ?> 580 | ``` 581 | 582 | ##Yii2 Lesson 10 下拉列表, 内容来自于数据库 583 | 584 | 在backend/views/branches/_form.php中 585 | 使用两个类 586 | 587 | use yii\helpers\ArrayHelper; 588 | use \backend\models\Companies; 589 | 590 | 将 591 | field($model, 'companies_company_id')->textInput() ?> 592 | 替换成以下 593 | 594 | field($model, 'companies_company_id')->dropDownList( 595 | ArrayHelper::map(Companies::find()->all(), 'company_id', 'company_name'), 596 | ['prompt' => 'select company'] 597 | ) ?> 598 | 599 | 600 | 将显示的标签内容换一下, 换成公司名 601 | 打开backend/models/branches.php 602 | 在attributeLabels中字段对应的值修改为company name 603 | 604 | 后面的departments相关的是一样的修改, 很简单, 自己操作一下 605 | 606 | 607 | ##Yii2 Lesson 11 搜索关联表从GridView里面 608 | 609 | 修改分支的index.php 610 | 将 611 | 'companiesCompany.company_name', 612 | 替换成 613 | [ 614 | 'attribute' => 'companies_company_id', 615 | 'value' => 'companiesCompany.company_name', 616 | ], 617 | 618 | 访问 619 | http://localhost/advanced/backend/web/index.php?r=branches%2Findex 620 | 621 | 发现出现了搜索框, 但是我们输入abc, 发现提示说公司名需要为整数, 原因是我们数据库存储的是整数 622 | 623 | 我们需要做的第一件事情是将 BranchesSearch模型中的rules中的第一个整数限制给去掉, companies_company_id 624 | 625 | 将 companies_company_id 添加到第二行的规则当中, 添加为safe 626 | 627 | 628 | 由于搜索会走到models/branchesSearch模型 629 | 找到里面的search方法, 将 630 | public function search($params) 631 | { 632 | $query = Branches::find(); 633 | 634 | $dataProvider = new ActiveDataProvider([ 635 | 'query' => $query, 636 | ]); 637 | 638 | $this->load($params); 639 | 640 | if (!$this->validate()) { 641 | // uncomment the following line if you do not want to any records when validation fails 642 | // $query->where('0=1'); 643 | return $dataProvider; 644 | } 645 | 646 | $query->andFilterWhere([ 647 | 'branch_id' => $this->branch_id, 648 | 'companies_company_id' => $this->companies_company_id, 649 | 'branch_created_date' => $this->branch_created_date, 650 | ]); 651 | 652 | $query->andFilterWhere(['like', 'branch_name', $this->branch_name]) 653 | ->andFilterWhere(['like', 'branch_address', $this->branch_address]) 654 | ->andFilterWhere(['like', 'branch_status', $this->branch_status]); 655 | 656 | return $dataProvider; 657 | } 658 | 替换成 659 | 660 | 661 | public function search($params) 662 | { 663 | $query = Branches::find(); 664 | 665 | $dataProvider = new ActiveDataProvider([ 666 | 'query' => $query, 667 | ]); 668 | 669 | $this->load($params); 670 | 671 | if (!$this->validate()) { 672 | // uncomment the following line if you do not want to any records when validation fails 673 | // $query->where('0=1'); 674 | return $dataProvider; 675 | } 676 | 677 | $query->joinWith('companiesCompany'); 678 | 679 | $query->andFilterWhere([ 680 | 'branch_id' => $this->branch_id, 681 | 'branch_created_date' => $this->branch_created_date, 682 | ]); 683 | 684 | $query->andFilterWhere(['like', 'branch_name', $this->branch_name]) 685 | ->andFilterWhere(['like', 'branch_address', $this->branch_address]) 686 | ->andFilterWhere(['like', 'branch_status', $this->branch_status]) 687 | ->andFilterWhere(['like', 'companies.company_name', $this->companies_company_id]); 688 | return $dataProvider; 689 | } 690 | 691 | ##Yii Lesson 12 创建模块 692 | 693 | 提前在backend/下面创建一个 modules目录 694 | mkdir modules 695 | chmod 777 modules 696 | 697 | 698 | 打开 699 | http://localhost/advanced/backend/web/index.php?r=gii 700 | 701 | 点击Module的创建 702 | 703 | Module Class 704 | backend\modules\settings\Settings 705 | 706 | Module ID 707 | settings 708 | 709 | 预览, 生成 710 | 711 | 拷贝一下模块 712 | ``` 713 | 'settings' => [ 714 | 'class' => 'backend\modules\settings\Settings', 715 | ], 716 | ``` 717 | 718 | 打开backend/config/main.php 719 | 看到里面有一个modules的配置, 里面为空 720 | 721 | 访问settings模块 722 | http://localhost/advanced/backend/web/index.php?r=settings 723 | 724 | 725 | 我们如果要在settings模块里面生成model 726 | 打开gii, 生成model 727 | companies 728 | Companies 729 | backend\modules\settings\models 730 | 731 | 生成其他的model是一样的 732 | 733 | 如果要生成CRUD 734 | backend\modules\settings\models\Companies 735 | backend\modules\settings\models\CompaniesSearch 736 | backend\modules\settings\controllers\CompaniesController 737 | @backend/modules/settings/views/companies 738 | 739 | 生成之后想要访问 740 | http://localhost/advanced/backend/web/index.php?r=settings/companies 741 | 742 | 743 | ##Yii Lesson 13 Bootstrap 样式的 Datepicker [未完成] 744 | 745 | https://github.com/maxwelldu/yii2-date-picker-widget 746 | 747 | 在网站根目录下面执行: 748 | 749 | composer require 2amigos/yii2-date-picker-widget:~1.0 750 | 751 | 给公司表中添加一个字段 752 | ALTER TABLE `companies` ADD `company_start_date` DATE NOT NULL AFTER `company_address`; 753 | 754 | 755 | 756 | 757 | 758 | #Yii Lesson 14 自动建议下拉列表搜索[未完成] 759 | 760 | 打开backend/views/branches/_form.php 761 | 762 | https://github.com/maxwelldu/yii2-widget-select2 763 | 764 | #Yii2 Lesson 15 时间选择器在gridview的过滤字段中 [未完成] 765 | 766 | 767 | ##Yii2 Lesson 16 Ajax搜索在GridView中 768 | 769 | 在backend/views/branches/index.php中 770 | 771 | use yii\widgets\Pjax; 772 | 773 | 然后在gridview的前后加上 begin 和 end 774 | ``` 775 | $dataProvider, 777 | 'filterModel' => $searchModel, 778 | 'columns' => [ 779 | ['class' => 'yii\grid\SerialColumn'], 780 | [ 781 | 'attribute' => 'companies_company_id', 782 | 'value' => 'companiesCompany.company_name', 783 | ], 784 | 785 | 'branch_name', 786 | 'branch_address', 787 | 'branch_created_date', 788 | // 'branch_status', 789 | 790 | ['class' => 'yii\grid\ActionColumn'], 791 | ], 792 | ]); ?> 793 | ``` 794 | 795 | 修改后如下 796 | ``` 797 | 798 | $dataProvider, 800 | 'filterModel' => $searchModel, 801 | 'columns' => [ 802 | ['class' => 'yii\grid\SerialColumn'], 803 | [ 804 | 'attribute' => 'companies_company_id', 805 | 'value' => 'companiesCompany.company_name', 806 | ], 807 | 808 | 'branch_name', 809 | 'branch_address', 810 | 'branch_created_date', 811 | // 'branch_status', 812 | 813 | ['class' => 'yii\grid\ActionColumn'], 814 | ], 815 | ]); ?> 816 | 817 | ``` 818 | 819 | ##Yii2 Lesson 17 上传文件到服务器上 [现在不感兴趣] 820 | 821 | 822 | ##Yii2 Lesson 18 RBAC 第一部分 823 | 824 | 建表语句: 825 | 826 | drop table if exists `auth_assignment`; 827 | drop table if exists `auth_item_child`; 828 | drop table if exists `auth_item`; 829 | drop table if exists `auth_rule`; 830 | 831 | create table `auth_rule` 832 | ( 833 | `name` varchar(64) not null, 834 | `data` text, 835 | `created_at` integer, 836 | `updated_at` integer, 837 | primary key (`name`) 838 | ) engine InnoDB; 839 | 840 | create table `auth_item` 841 | ( 842 | `name` varchar(64) not null, 843 | `type` integer not null, 844 | `description` text, 845 | `rule_name` varchar(64), 846 | `data` text, 847 | `created_at` integer, 848 | `updated_at` integer, 849 | primary key (`name`), 850 | foreign key (`rule_name`) references `auth_rule` (`name`) on delete set null on update cascade, 851 | key `type` (`type`) 852 | ) engine InnoDB; 853 | 854 | create table `auth_item_child` 855 | ( 856 | `parent` varchar(64) not null, 857 | `child` varchar(64) not null, 858 | primary key (`parent`, `child`), 859 | foreign key (`parent`) references `auth_item` (`name`) on delete cascade on update cascade, 860 | foreign key (`child`) references `auth_item` (`name`) on delete cascade on update cascade 861 | ) engine InnoDB; 862 | 863 | create table `auth_assignment` 864 | ( 865 | `item_name` varchar(64) not null, 866 | `user_id` integer not null, 867 | `created_at` integer, 868 | primary key (`item_name`, `user_id`), 869 | foreign key (`item_name`) references `auth_item` (`name`) on delete cascade on update cascade 870 | ) engine InnoDB; 871 | 872 | 873 | 在backend/config/main.php 中的components中添加一项 874 | 'authManager' => [ 875 | 'class' => 'yii\rbac\DbManager', 876 | 'defaultRoles' => ['guest'], 877 | ], 878 | 879 | 880 | 打开backend/controllers/BranchesController.php 881 | 引入 882 | use yii\web\ForbiddenHttpException; 883 | 884 | 将创建的方法加上一个判断 885 | public function actionCreate() 886 | { 887 | if( Yii::$app->user->can( 'create-branch' ) ) 888 | { 889 | $model = new Branches(); 890 | 891 | if ($model->load(Yii::$app->request->post())) { 892 | $model->branch_created_date = date('Y-m-d h:i:s'); 893 | $model->save(); 894 | return $this->redirect(['view', 'id' => $model->branch_id]); 895 | } else { 896 | return $this->render('create', [ 897 | 'model' => $model, 898 | ]); 899 | } 900 | } else 901 | { 902 | throw new ForbiddenHttpException; 903 | } 904 | 905 | } 906 | 907 | 908 | 909 | 910 | 911 | ##Yii Lesson 20 依赖于下拉列表 912 | 在添加部门的时候, 将公司id做成下拉列表, 913 | 打开_form.php修改成如下即可 914 | field($model, 'companies_company_id')->dropDownList( 915 | ArrayHelper::map(Companies::find()->all(), 'company_id', 'company_name'), 916 | ['prompt' => 'select company'] 917 | ) ?> 918 | 919 | 下面的分支, 我们需要基于上面的公司, 显示当前公司的分支, 这个如何做 920 | 将这个字段改写成这样 921 | 922 | field($model, 'companies_company_id')->dropDownList( 923 | ArrayHelper::map(Companies::find()->all(), 'company_id', 'company_name'), 924 | [ 925 | 'prompt' => 'select company', 926 | 'onChange' => ' 927 | $.post("index.php?r=branches/lists&id='.'"+$(this).val(), function( data ) { 928 | $( "select#departments-branches_branch_id" ).html( data ); 929 | });' 930 | ] 931 | ) ?> 932 | 933 | 打开浏览器, 测试一下改变的时候是否会请求 934 | 935 | 在BranchController里面添加一个方法 936 | public function actionLists($id) 937 | { 938 | $countBranches = Branches::find() 939 | ->where(['companies_company_id' => $id]) 940 | ->count(); 941 | 942 | $branches = Branches::find() 943 | ->where(['companies_company_id' => $id]) 944 | ->all(); 945 | 946 | if($countBranches>0) { 947 | foreach($branches as $branch) { 948 | echo ""; 949 | } 950 | } else { 951 | echo ""; 952 | } 953 | } 954 | 955 | 956 | 关于branched也修改为dropdownlist 957 | field($model, 'branches_branch_id')->dropDownList( 958 | ArrayHelper::map(Branches::find()->all(), 'branch_id', 'branch_name'), 959 | ['prompt' => 'select branch'] 960 | ) ?> 961 | 962 | 963 | 964 | ##Yii2 Lesson 21 带附件发送邮件 [加载不了视频] 965 | 966 | 967 | ##Yii2 Lesson 22 在GridView中给行添加类样式 968 | 969 | 在/backend/views/branches/index.php文件中 970 | 在gridview 中的filterModel下面添加以下代码 971 | 972 | 'rowOptions' => function($model){ 973 | if($model->branch_status == 'inactive') 974 | { 975 | return ['class' => 'danger']; 976 | } else { 977 | return ['class' => 'success']; 978 | } 979 | }, 980 | 981 | 982 | ##Yii2 Lesson 23 为forms弹出一个模式窗口 983 | 984 | 使用bootstrap 985 | 986 | 在backend/views/branches/index.php中 987 | 引入 988 | use yii\bootstrap\Modal; 989 | use yii\helpers\Url; 990 | 991 | 将创建分支的链接改为以下代码 992 | 993 |

994 | Url::to('index.php?r=branches/create'), 'class' => 'btn btn-success', 'id' => 'modalButton']) ?> 995 |

996 | 997 | '

Branches

', 1000 | 'id' => 'modal', 1001 | 'size' => 'modal-lg', 1002 | ]); 1003 | echo "
"; 1004 | 1005 | Modal::end(); 1006 | ?> 1007 | 1008 | 1009 | 改完后发现点击之后还是没有效果, 原因是因为没有加载js 1010 | 1011 | 打开backend/assets/AppAsset.php 1012 | 1013 | 在js里面导入一个 1014 | 1015 | public $js = [ 1016 | 'js/main.js', 1017 | ]; 1018 | 1019 | 在web目录里面新建一个js目录, 里面创建一个main.js文件 1020 | 内容写上 1021 | $(function(){ 1022 | alert("fdsaf"); 1023 | }); 1024 | 1025 | 打开页面看是否能够弹出 1026 | 1027 | 然后将内容修改为如下 1028 | 1029 | $(function(){ 1030 | // get the click of the create form 1031 | $('#modalButton').click(function(){ 1032 | $('#modal').modal('show') 1033 | .find('#modalContent') 1034 | .load($(this).attr('value')); 1035 | }); 1036 | }); 1037 | 1038 | 1039 | 刷新页面发现可以打开了, 但是有头部和底部 1040 | 1041 | 我们打开backend/controllers/branchesController.php 1042 | 找到create方法 1043 | render方法换成renderAjax 1044 | 1045 | return $this->renderAjax('create', [ 1046 | 'model' => $model, 1047 | ]); 1048 | 1049 | 1050 | ##Yii2 Lesson 24 用Ajax从表格中获得数据 1051 | 1052 | 先创建一张位置表 1053 | CREATE TABLE `locations` ( 1054 | `location_id` int(11) NOT NULL AUTO_INCREMENT, 1055 | `zip_code` varchar(20) NOT NULL, 1056 | `city` varchar(100) NOT NULL, 1057 | `province` varchar(100) NOT NULL, 1058 | PRIMARY KEY (`location_id`) 1059 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1060 | 1061 | 1062 | 再创建一张customers表 1063 | CREATE TABLE `customers` ( 1064 | `customer_id` int(11) NOT NULL AUTO_INCREMENT, 1065 | `customer_name` varchar(100) NOT NULL, 1066 | `zip_code` varchar(20) NOT NULL, 1067 | `city` varchar(100) NOT NULL, 1068 | `province` varchar(100) NOT NULL, 1069 | PRIMARY KEY (`customer_id`) 1070 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1071 | 1072 | 1073 | 通过gii生成两个model 1074 | 1075 | 再生成crud 1076 | 1077 | backend\models\Customers 1078 | backend\models\CustomersSearch 1079 | backend\controllers\CustomersController 1080 | 1081 | 1082 | backend\models\Locations 1083 | backend\models\LocationsSearch 1084 | backend\controllers\LocationsController 1085 | 1086 | http://localhost/advanced/backend/web/index.php?r=customers%2Fcreate 1087 | 1088 | 需要做的事情是在添加客户的时候, 选择一个zip code, 自动从locations表中将省市给填充起来 1089 | 1090 | http://localhost/advanced/backend/web/index.php?r=locations%2Fcreate 1091 | 先填充一些地址信息 1092 | 1111 1093 | Colombo 1094 | Westerm 1095 | 1096 | 2222 1097 | Galle 1098 | Southern 1099 | 1100 | 再回到 1101 | http://localhost/advanced/backend/web/index.php?r=customers%2Fcreate 1102 | 1103 | 将zip_code改成dropdownlist 1104 | /backend/views/customers/_form.php 1105 | 将 1106 | field($model, 'zip_code')->textInput(['maxlength' => 20]) ?> 1107 | 1108 | 替换成 1109 | 1110 | field($model, 'zip_code')->dropDownList( 1111 | ArrayHelper::map(Locations::find()->all(), 'location_id', 'zip_code'), 1112 | [ 1113 | 'prompt' => 'select location', 1114 | 'id' => 'zipCode', 1115 | ] 1116 | ) ?> 1117 | 1118 | 在文件末尾加上js 1119 | registerJs($script); 1132 | ?> 1133 | 1134 | 1135 | 在backend/controllers/LocationsController中添加一个方法 1136 | 1137 | public function actionGetCityProvince($zipId) 1138 | { 1139 | $location = Locations::findOne($zipId); 1140 | echo Json::encode($location); 1141 | } 1142 | 1143 | 1144 | 1145 | ##Yii Lesson 25 使用检查框给用户赋权限 1146 | 1147 | 创建Model 1148 | 1149 | auth_item 1150 | auth_assignment 1151 | auth_item_child 1152 | auth_rule 1153 | 1154 | 希望在前台注册用户的时候可以勾选权限 1155 | 1156 | 修改frontend/models/SignupForm.php 1157 | 添加一个属性 1158 | public $permissions; 1159 | 1160 | 修改控制器, 将auth_item给查询出来, 传到页面 1161 | 引用后台的model 1162 | use backend\models\AuthItem; 1163 | 1164 | 1165 | public function actionSignup() 1166 | { 1167 | $model = new SignupForm(); 1168 | $authItems = AuthItem::find()->all(); 1169 | if ($model->load(Yii::$app->request->post())) { 1170 | if ($user = $model->signup()) { 1171 | if (Yii::$app->getUser()->login($user)) { 1172 | return $this->goHome(); 1173 | } 1174 | } 1175 | } 1176 | 1177 | return $this->render('signup', [ 1178 | 'model' => $model, 1179 | 'authItems' => $authItems, 1180 | ]); 1181 | } 1182 | 1183 | 1184 | 在前台添加一个检查框列表 1185 | use yii\helpers\ArrayHelper; 1186 | 1187 | 1190 | field($model, 'permissions')->checkboxList($authItems); ?> 1191 | 1192 | 1193 | 在创建用户的时候添加授权 1194 | 1195 | frontend/models/SignupForm.php 1196 | 1197 | 1198 | public function signup() 1199 | { 1200 | if ($this->validate()) { 1201 | $user = new User(); 1202 | $user->first_name = $this->first_name; 1203 | $user->last_name = $this->last_name; 1204 | $user->username = $this->username; 1205 | $user->email = $this->email; 1206 | $user->setPassword($this->password); 1207 | $user->generateAuthKey(); 1208 | $user->save(); 1209 | // let add the permissions 1210 | $permissionList = $_POST['SignupForm']['permissions']; 1211 | foreach ($permissionList as $value) 1212 | { 1213 | $newPermission = new AuthAssignment; 1214 | $newPermission->user_id = $user->id; 1215 | $newPermission->item_name = $value; 1216 | $newPermission->save(); 1217 | } 1218 | 1219 | return $user; 1220 | 1221 | } 1222 | 1223 | return null; 1224 | } 1225 | 1226 | 1227 | 1228 | 1229 | ##Yii2 Lesson 26 自定义规则 [前面composer安装失败, 就没有添加字段] 1230 | 1231 | ##Yii2 Lesson 27 复杂的表单 1232 | 1233 | 创建公司的同时创建一个分支 1234 | 1235 | 1236 | ##Yii2 Lesson 28 1237 | 1238 | ##Yii2 Lesson 29 1239 | 1240 | ##Yii2 Lesson 30 1241 | 1242 | 1243 | 1244 | 1245 | -------------------------------------------------------------------------------- /function.php: -------------------------------------------------------------------------------- 1 | 0 && $expire < time()) { 35 | return ''; 36 | } 37 | $len = strlen($data); 38 | $l = strlen($key); 39 | $char = $str = ''; 40 | for ($i = 0; $i < $len; $i++) { 41 | if ($x == $l) $x = 0; 42 | $char .= substr($key, $x, 1); 43 | $x++; 44 | } 45 | for ($i = 0; $i < $len; $i++) { 46 | if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) { 47 | $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1))); 48 | }else{ 49 | $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1))); 50 | } 51 | } 52 | return base64_decode($str); 53 | } 54 | } 55 | 56 | if (! function_exists('format_output')) { 57 | 58 | function format_output($returnData = null, $return = array()) { 59 | 60 | $return = array_merge($return,['data'=>$returnData]); 61 | 62 | $setlog = setLog($return,$_REQUEST ? $_REQUEST['_url'] : 'null'); 63 | 64 | echo json_encode($return,JSON_UNESCAPED_UNICODE); 65 | 66 | exit; 67 | 68 | return; 69 | } 70 | } 71 | 72 | if (! function_exists('setLog')) { 73 | function setLog($data,$_url){ 74 | $new_line = "\r\n"; 75 | $str = "生成时间:" . date("Y-m-d H:i:s"). $new_line; 76 | $str .= "请求URL:" . $_url. $new_line; 77 | $str .= "返回数据:" . json_encode($data,JSON_UNESCAPED_UNICODE) . $new_line; 78 | $str .= "请求IP:" .get_real_ip(). $new_line; 79 | $str .= $new_line; 80 | $file_path = Config::get('logPath','/logs/api_logs/'); 81 | $file_path = rtrim($file_path, "/"); 82 | $filename = $file_path.'/'.date('Ymd').'/'.date("H").".log"; 83 | 84 | _write_file($filename, $str); 85 | } 86 | } 87 | 88 | if (! function_exists('_write_file')) { 89 | function _write_file($filename = '', $str = '', $mode = 'a+') { 90 | $result = FALSE; 91 | //是否新建目录 92 | $dirname = dirname($filename); 93 | if (!file_exists($dirname)) { 94 | mkdir($dirname, 0777, TRUE); 95 | } 96 | $file = fopen($filename, $mode); 97 | // 排它性的锁定 98 | if (flock($file, LOCK_EX)) { 99 | fwrite($file, $str); 100 | // release lock 101 | flock($file, LOCK_UN); 102 | $result = TRUE; 103 | } 104 | fclose($file); 105 | return $result; 106 | } 107 | } 108 | 109 | if (! function_exists('get_real_ip')) { 110 | function get_real_ip($type = 0) 111 | { 112 | $type = $type ? 1 : 0; 113 | static $ip = NULL; 114 | if ($ip !== NULL) return $ip[$type]; 115 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { 116 | $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); 117 | $pos = array_search('unknown',$arr); 118 | if(false !== $pos) unset($arr[$pos]); 119 | $ip = trim($arr[0]); 120 | }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { 121 | $ip = $_SERVER['HTTP_CLIENT_IP']; 122 | }elseif (isset($_SERVER['REMOTE_ADDR'])) { 123 | $ip = $_SERVER['REMOTE_ADDR']; 124 | } 125 | // IP地址合法验证 126 | $long = sprintf("%u",ip2long($ip)); 127 | $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); 128 | return $ip[$type]; 129 | } 130 | } 131 | 132 | if (! function_exists('arraytoXml')) { 133 | function arraytoXml ($data,$root = "xml") 134 | { 135 | $xml = '<'.$root.'>'; 136 | 137 | foreach ($data as $key => $value) 138 | { 139 | $xml .= "<$key>" . htmlentities($value) . ""; 140 | } 141 | 142 | return $xml .= ''; 143 | } 144 | } 145 | 146 | 147 | function diffStr($str1,$str2) 148 | { 149 | $sArr1 = str_split($str1); 150 | $sArr2 = str_split($str2); 151 | 152 | $num1 = count($sArr1); 153 | $num2 = count($sArr2); 154 | 155 | $aNew = array(); 156 | 157 | if($num1 > $num2){ 158 | foreach($sArr1 as $k=>$val){ 159 | if($num2 > $k && $val != $sArr2[$k]){ 160 | $aNew[] = array('s1'=>$val,'s2'=>$sArr2[$k]); 161 | }elseif($num2 <= $k){ 162 | $aNew[] = array("s1"=>$val); 163 | } 164 | } 165 | }elseif($num1 < $num2){ 166 | foreach($sArr2 as $k=>$val){ 167 | if($num1 > $k && $val != $sArr1[$k]){ 168 | $aNew[] = array('s1'=>$sArr1[$k],'s2'=>$val); 169 | }elseif($num1 <= $k){ 170 | $aNew[] = array("s2"=>$val); 171 | } 172 | } 173 | }elseif($num1 == $num2){ 174 | foreach($sArr1 as $k=>$val){ 175 | if($val != $sArr2[$k]){ 176 | $aNew[] = array('s1'=>$val,'s2'=>$sArr2[$k]); 177 | } 178 | } 179 | } 180 | 181 | return $aNew; 182 | } 183 | -------------------------------------------------------------------------------- /ioc.php: -------------------------------------------------------------------------------- 1 | test(); 16 | } 17 | } 18 | 19 | class MysqlAdapter 20 | { 21 | 22 | public function test () 23 | { 24 | echo "i am MysqlAdapter test"; 25 | } 26 | } 27 | 28 | class app 29 | { 30 | 31 | public static function run ($instance, $method) 32 | { 33 | if (! method_exists($instance, $method)) 34 | 35 | return null; 36 | 37 | $reflector = new ReflectionMethod($instance, $method); 38 | 39 | $parameters = [ 40 | 1 41 | ]; 42 | 43 | foreach ($reflector->getParameters() as $key => $parameter) 44 | { 45 | 46 | $class = $parameter->getClass(); 47 | 48 | if ($class) 49 | { 50 | array_splice($parameters, $key, 0, [ 51 | new $class->name() 52 | ]); 53 | } 54 | } 55 | call_user_func_array([ 56 | $instance, 57 | $method 58 | ], $parameters); 59 | } 60 | } 61 | 62 | app::run(new Database(), 'test'); 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /nginx: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # chkconfig: 2345 55 25 3 | # Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and 4 | # run 'update-rc.d -f nginx defaults', or use the appropriate command on your 5 | # distro. For CentOS/Redhat run: 'chkconfig --add nginx' 6 | 7 | ### BEGIN INIT INFO 8 | # Provides: nginx 9 | # Required-Start: $all 10 | # Required-Stop: $all 11 | # Default-Start: 2 3 4 5 12 | # Default-Stop: 0 1 6 13 | # Short-Description: starts the nginx web server 14 | # Description: starts nginx using start-stop-daemon 15 | ### END INIT INFO 16 | 17 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 18 | DESC="nginx daemon" 19 | NAME=nginx 20 | DAEMON=/webserver/nginx/sbin/$NAME 21 | CONFIGFILE=/webserver/nginx/conf/$NAME.conf 22 | PIDFILE=/logs/nginx/$NAME.pid 23 | SCRIPTNAME=/etc/init.d/$NAME 24 | 25 | set -e 26 | [ -x "$DAEMON" ] || exit 0 27 | 28 | do_start() { 29 | $DAEMON -c $CONFIGFILE || echo -n "nginx already running" 30 | } 31 | 32 | do_stop() { 33 | kill -INT `cat $PIDFILE` || echo -n "nginx not running" 34 | } 35 | 36 | do_reload() { 37 | kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload" 38 | } 39 | 40 | case "$1" in 41 | start) 42 | echo -n "Starting $DESC: $NAME" 43 | do_start 44 | echo "." 45 | ;; 46 | stop) 47 | echo -n "Stopping $DESC: $NAME" 48 | do_stop 49 | echo "." 50 | ;; 51 | reload|graceful) 52 | echo -n "Reloading $DESC configuration..." 53 | do_reload 54 | echo "." 55 | ;; 56 | restart) 57 | echo -n "Restarting $DESC: $NAME" 58 | do_stop 59 | do_start 60 | echo "." 61 | ;; 62 | *) 63 | echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 64 | exit 3 65 | ;; 66 | esac 67 | 68 | exit 0 69 | -------------------------------------------------------------------------------- /shell/rsync/README.md: -------------------------------------------------------------------------------- 1 | ##多服务器同步代码 2 | 3 | 4 | ##安装 5 | 6 | ``` 7 | sudo apt-get install rsync 注:在debian、ubuntu 等在线安装方法; 8 | yum install rsync 注:Fedora、Redhat 等在线安装方法; 9 | ``` 10 | 11 | 12 | >服务端的基本配置 13 | 14 | ``` 15 | secrets file = /etc/rsyncd.secrets 16 | motd file = /etc/rsyncd.motd 17 | uid = root 18 | gid = root 19 | use chroot = no 20 | max connections = 15 21 | log file = /logs/rsync/rsyncd.log 22 | pid file = /logs/rsync/rsyncd.pid 23 | lock file = /logs/rsync/rsync.lock 24 | hosts allow = 10.99.101.110 25 | hosts deny = * 26 | # Remote sync configuration module 27 | [t1] 28 | comment = testsync directory 29 | read only = false 30 | path = /tmp/rsync 31 | 32 | 33 | ``` 34 | 35 | 客户端使用命令 36 | ``` 37 | rsync -vzrtopg --exclude-from="/codes/vmall_test/exclude.list" --delete /codes/vmall_test/admin/ rsync@192.168.1.1::t1 38 | ``` 39 | >说明:--exclude-from 不同步的文件 --delete 服务端强制与客户端文件保持一致 /codes/vmall_test/admin 需要同步的目录 40 | rsync@192.168.1.1::t1 同步服务端的t1模块 41 | 42 | 43 | ###生产环境可示例test_push_code.sh来结合svn等部署多服务器 44 | -------------------------------------------------------------------------------- /shell/rsync/test_push_code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -p "Please input your Package name:" Pname 4 | 5 | MPWD=/codes/vmall_test 6 | 7 | UPWD=$MPWD/$Pname 8 | 9 | logdir=`date +%Y%m%d`/`date +%H`/$Pname 10 | 11 | cd $Pname 12 | 13 | svn up --username sky --password xxxxxx 14 | 15 | sleep 2s 16 | 17 | cd .. 18 | 19 | if [ -d $UPWD ] ; then 20 | 21 | 22 | IpList=`cat iplist.txt |awk '{print $1}'` 23 | 24 | for i in $IpList 25 | 26 | do 27 | 28 | if [ ! -d $logdir ] ; then 29 | 30 | mkdir -p $logdir 31 | 32 | fi 33 | echo ${i} 34 | echo "==========starting==========" 35 | rsync -vzrtopg --exclude-from="/codes/vmall_test/exclude.list" --delete $UPWD/ rsync@${i}::t${Pname} >> ${logdir}/${i}.log 36 | 37 | sleep 2s 38 | 39 | echo "The rsync with $i is complete" 40 | echo "==========End==========" 41 | 42 | done 43 | 44 | else 45 | 46 | echo "The $Pname not exist" 47 | 48 | fi 49 | -------------------------------------------------------------------------------- /shell/shell笔记/10.1shell概述.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.1shell概述.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.2shell脚本运行方式.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.2shell脚本运行方式.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.3.1历史命令与补全能.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.3.1历史命令与补全能.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.3.2别名与快捷键.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.3.2别名与快捷键.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.3.3输入和输出重定向.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.3.3输入和输出重定向.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.3.4多命令顺序执行与管道符.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.3.4多命令顺序执行与管道符.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.3.5通配符和其他特殊符号.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.3.5通配符和其他特殊符号.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.4.1用户自定义变量.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.4.1用户自定义变量.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.4.2环境变量.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.4.2环境变量.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.4.3位置参数变量.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.4.3位置参数变量.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.4.4预定义变量.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.4.4预定义变量.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.5.1数值运算与运算符.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.5.1数值运算与运算符.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.5.2变量测试与内容替换.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.5.2变量测试与内容替换.txt -------------------------------------------------------------------------------- /shell/shell笔记/10.6.环境变量配置文件.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/10.6.环境变量配置文件.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.1正则表达式.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.1正则表达式.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.2.1字符串截取-cut.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.2.1字符串截取-cut.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.2.2字符串截取-printf.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.2.2字符串截取-printf.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.2.3字符截取命令-awk.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.2.3字符截取命令-awk.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.2.4字符截取命令-sed.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.2.4字符截取命令-sed.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.3字符处理命令.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.3字符处理命令.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.4条件判断.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.4条件判断.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.5.1if语句.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.5.1if语句.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.5.2case语句.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.5.2case语句.txt -------------------------------------------------------------------------------- /shell/shell笔记/11.5.3for循环.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sky-L/note/04c60787347cab530d786b7c6b1c0d351c47944a/shell/shell笔记/11.5.3for循环.txt -------------------------------------------------------------------------------- /shell/task/README.md: -------------------------------------------------------------------------------- 1 | ###服务器跑php进程,减少页面交互 2 | 3 | >通过手动执行`run_job.sh`,会自动执行`job.sh` 4 | -------------------------------------------------------------------------------- /shell/task/auto_crate_crontab: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | configFile=cron_config 3 | #php执行文件目录 4 | php=/webserver/php/bin/php 5 | project=/opt/application/vmall_task 6 | 7 | a=`cat $configFile | awk '{if($1 && $2){ 8 | len=split($2, posarr, "=") 9 | filename=posarr[len]?posarr[len]:posarr[len-1] 10 | lastname=posarr[len-1] 11 | print "" $1 "/"lastname"_"filename"\n" 12 | }else if($1){ 13 | filename=posarr[len]?posarr[len]:posarr[len-1] 14 | print "" $1"\n" 15 | } 16 | }'` 17 | 18 | dir=`pwd` 19 | for D in $a 20 | do 21 | findNum=`echo $D | awk -F'/' '{print NF-1}'` 22 | if [ $findNum == 1 ]; 23 | then 24 | param=$D 25 | fi 26 | str=' 27 | #!/usr/bin/env bash\n 28 | CRON_NAME="cron"\n 29 | CRON_EXEC="'$php'"\n 30 | CRON_FILE="'$project'/'$param'.php"\n 31 | #CRON_ARGV=""\n 32 | SLEEP_TIME=3\n 33 | . common/cron.sh' 34 | if [ ! -d "$D" ]; 35 | then 36 | /bin/mkdir -p "$dir/$D" 37 | fi 38 | if [ ! -f "$dir/$D/job.sh" ]; 39 | then 40 | echo "$dir/$D/job.sh" 41 | echo -e $str >> "$dir/$D/job.sh" 42 | fi 43 | 44 | done 45 | -------------------------------------------------------------------------------- /shell/task/cron.sh: -------------------------------------------------------------------------------- 1 | #do not modify 2 | ROOT=`dirname $0` 3 | cd $ROOT 4 | ROOT=`pwd` 5 | echo $ROOT >> /tmp/xxx 6 | 7 | CRON_LOG=${ROOT}/${CRON_NAME}.log 8 | CRON_PID=${ROOT}/${CRON_NAME}.pid 9 | CRON_LOCK=${ROOT}/${CRON_NAME}.lock 10 | CRON_JOB_PID=${ROOT}/${CRON_NAME}_job.pid 11 | 12 | start () { 13 | echo "starting..." 14 | if [ -f $CRON_LOCK ] 15 | then 16 | return 1 17 | else 18 | touch $CRON_LOCK 19 | if [ $? != 0 ] 20 | then 21 | exit 1 22 | fi 23 | trap 'rm $CRON_LOCK' EXIT 24 | echo $$ > $CRON_PID 25 | while true 26 | do 27 | $CRON_EXEC $CRON_FILE $CRON_ARGV >> $CRON_LOG 2>&1 & PID=$! 28 | echo $PID > $CRON_JOB_PID 29 | wait $PID 30 | RET=$? 31 | NOW=`date` 32 | echo "${NOW}:$CRON_NAME exit with code $RET" >> $CRON_LOG 33 | if [[ $SLEEP_TIME > 0 ]] 34 | then 35 | sleep $SLEEP_TIME 36 | fi 37 | done 38 | fi 39 | } 40 | 41 | stop_pid_file () { 42 | PID_FILE=$1 43 | if [ -f $PID_FILE ] 44 | then 45 | PID=`cat $PID_FILE` 46 | ps $PID >/dev/null 2>/dev/null 47 | if [ $? == 0 ] 48 | then 49 | kill $PID 50 | return 0 51 | fi 52 | fi 53 | return 1 54 | } 55 | 56 | stop () { 57 | stop_pid_file "$CRON_PID" 58 | RET=$? 59 | stop_pid_file "$CRON_JOB_PID" 60 | RET_JOB=$? 61 | if [[ $RET == 0 && $RET_JOB == 0 ]] 62 | then 63 | echo "stop ok" 64 | fi 65 | } 66 | 67 | status () { 68 | if [ -f $CRON_PID ] 69 | then 70 | PID=`cat $CRON_PID` 71 | ps $PID >/dev/null 2>/dev/null 72 | if [ $? == 0 ] 73 | then 74 | echo "running..." 75 | else 76 | echo "not running" 77 | fi 78 | else 79 | echo "not running" 80 | fi 81 | } 82 | 83 | case "$1" in 84 | start) 85 | $1 86 | RETVAL=$? 87 | ;; 88 | stop) 89 | $1 90 | RETVAL=$? 91 | ;; 92 | restart) 93 | stop 94 | sleep 1 95 | start 96 | RETVAL=$? 97 | ;; 98 | status) 99 | $1 100 | ;; 101 | *) 102 | echo $"Usage: $0 {start|stop|restart|status}" 103 | RETVAL=2 104 | esac 105 | 106 | exit $RETVAL 107 | -------------------------------------------------------------------------------- /shell/task/cron_config: -------------------------------------------------------------------------------- 1 | action/AuctionAction 2 | action/AuctionOrder 3 | action/AuctionOrder_finish 4 | action/cancleCouponOrder 5 | action/confirmReceipt 6 | action/CheckFalshSaleAction 7 | action/FallshSaleAction 8 | action/NotifyAction 9 | action/UpdatePayAction 10 | action/MessagePushAction -------------------------------------------------------------------------------- /shell/task/job.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | CRON_NAME="cron" 3 | CRON_EXEC="/webserver/php/bin/php" 4 | CRON_FILE="/opt/application/vmall_task/action/MessagePushAction.php" 5 | #CRON_ARGV="" 6 | SLEEP_TIME=3 7 | . common/cron.sh 8 | -------------------------------------------------------------------------------- /shell/task/run_jobs.sh: -------------------------------------------------------------------------------- 1 | ROOT=`dirname $0` 2 | cd $ROOT 3 | ROOT=`pwd` 4 | 5 | for F in `find . -type f -iname "job.sh"` 6 | do 7 | /bin/sh $F start & 8 | done 9 | 10 | -------------------------------------------------------------------------------- /shell/task/stop_jobs.sh: -------------------------------------------------------------------------------- 1 | ROOT=`dirname $0` 2 | cd $ROOT 3 | ROOT=`pwd` 4 | 5 | for F in `find . -type f -iname "job.sh"` 6 | do 7 | /bin/sh $F stop 8 | done 9 | 10 | -------------------------------------------------------------------------------- /shell/task/test_push_code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -p "Please input your Package name:" Pname 4 | 5 | MPWD=/codes/vmall_test 6 | 7 | UPWD=$MPWD/$Pname 8 | 9 | logdir=`date +%Y%m%d`/`date +%H`/$Pname 10 | 11 | cd $Pname 12 | 13 | svn up --username skylee --password xxxxx 14 | 15 | sleep 2s 16 | 17 | cd .. 18 | 19 | if [ -d $UPWD ] ; then 20 | 21 | 22 | IpList=`cat iplist.txt |awk '{print $1}'` 23 | 24 | for i in $IpList 25 | 26 | do 27 | 28 | if [ ! -d $logdir ] ; then 29 | 30 | mkdir -p $logdir 31 | 32 | fi 33 | echo ${i} 34 | echo "==========starting==========" 35 | rsync -vzrtopg --exclude-from="/codes/vmall_test/exclude.list" --delete $UPWD/ rsync@${i}::t${Pname} >> ${logdir}/${i}.log 36 | 37 | sleep 2s 38 | 39 | echo "The rsync with $i is complete" 40 | echo "==========End==========" 41 | 42 | done 43 | 44 | else 45 | 46 | echo "The $Pname not exist" 47 | 48 | fi 49 | -------------------------------------------------------------------------------- /spl.md: -------------------------------------------------------------------------------- 1 | 2 | ###类作为数组访问 3 | ``` 4 | class config implements ArrayAccess 5 | { 6 | static $config = null; 7 | 8 | private $configArr; 9 | 10 | private function __construct() 11 | 12 | public static function instance() 13 | { 14 | if(self::$config == null){ 15 | self::$config = new config(); 16 | } 17 | return self::$config; 18 | 19 | } 20 | 21 | public function offsetExists($offset = '') 22 | { 23 | 24 | } 25 | public function offsetGet($offset = '') 26 | { 27 | return $this->configArr[$offset]; 28 | } 29 | public function offsetSet($offset, $value) 30 | { 31 | 32 | } 33 | 34 | public function offsetUnset($offset = '') 35 | { 36 | 37 | } 38 | 39 | } 40 | 41 | $test = config::instance(); 42 | 43 | $test['test'] = 'test';//自动调用offsetSet 44 | if(isset($test['test']))//自动调用offsetExists 45 | { 46 | echo $test['test'];//自动调用offsetGet 47 | echo '
'; 48 | unset($test['test']);//自动调用offsetUnset 49 | var_dump($test['test']); 50 | } 51 | 52 | 53 | ``` 54 | -------------------------------------------------------------------------------- /vhost.md: -------------------------------------------------------------------------------- 1 | ## nginx转发请求 2 | 3 | ``` 4 | 5 | server { 6 | listen 80; 7 | server_name example.com; 8 | 9 | location / { 10 | proxy_set_header X-Real-IP $remote_addr; 11 | proxy_set_header Host $http_host; 12 | proxy_pass http://127.0.0.1:2368; 13 | } 14 | } 15 | 16 | ``` 17 | ## apache转发请求 18 | 19 | ``` 20 | 21 | ServerAdmin 管理员邮箱 22 | ServerName localhost 23 | ServerAlias localhost 24 | ProxyPass http://127.0.0.1:9999 25 | 26 | 27 | ``` 28 | 29 | 30 | ## apache支持php 31 | 32 | `AddHandler application/x-httpd-php .php` 33 | 34 | ## nginx支持php 35 | 36 | ``` 37 | location ~ ^(.+\.php)(.*)$ 38 | { 39 | fastcgi_split_path_info ^(.+\.php)(.*)$; 40 | include fastcgi.conf; 41 | fastcgi_pass 127.0.0.1:9000; 42 | fastcgi_index index.php; 43 | fastcgi_param PATH_INFO $fastcgi_path_info; 44 | } 45 | ``` 46 | --------------------------------------------------------------------------------