• 个人技术博客 α


    个 人 技 术 博 客 α

    Date Log
    2017/11/9 simple version

    Part · 0 简 要 目 录

    • Part · 1 团 队 项 目 简 介

    • Part · 2 PHP 求 学 之 路

    • Part · 3 CI 框 架 探 索

    • Part · 4 Github 探 索


    Part · 1 团队项目简介

    背 景

    WonderLand立项报告:http://www.cnblogs.com/andwho/p/7598662.html

    开 发 环 境

    工 具:wampserver、sublime
    语 言:PHP


    Part · 2 PHP 求 学 之 路

    入 门 教 程:http://www.imooc.com/learn/54

    入门教程是关于PHP入门基础语法的介绍,语法整体学习下来最大的感受是类似C、C++语法,其中还包含了wampserver环境的配置【灰常重要】

    进 阶 教 程:http://www.imooc.com/learn/26

    进阶教程主要深入学习了PHP中关于数组、类和面向对象、session和cookie等知识的使用,其中在开发过程大量使用try catch的代码结构

    部 分 学 习 内 容

    • 自 定 义 网 站 根 目 录

    Step · 1:open httpd.conf

    Step · 2 - 1:search DocumentRoot and change file name
    Step · 2 - 2:search Directory and change file name

    Step · 3:open wampmanager.ini search menu.left and change some code

    Step · 4:open wampmanager.tpl search menu.left and change some code

    Step · 5:open httpd-vhosts.conf and change root

    Step · 6:restart wampserver

    • 神 奇 的 foreach
    //(1)只取值,不取下标
    <?php
        foreach (数组 as 值)
        {
            //执行的任务
        }
    ?>
    //(2)同时取下标和值
    <?php
        foreach (数组 as 下标 => 值)
        {
            //执行的任务
        }
    ?>
    
    • 巧用 session
      使用session缓存登录信息等

    • try catch 代 码 结 构

    try
    {
        //可能出现错误或异常的代码
        //catch表示捕获,Exception是php已定义好的异常类
    }
    catch(Exception $e)
    {
        //对异常处理,方法:
        //1、自己处理
        //2、不处理,将其再次抛出
    }
    

    Part · 3 CI 框 架 探 索

    教 程:https://chuanke.baidu.com/v1253098-100758-169407.html

    Demo 实 例:https://github.com/Distancess/Test

    代 码 规 范:http://codeigniter.org.cn/user_guide/general/styleguide.html

    部 分 学 习 内 容

    • 表 单 验 证

    使 用 手 册:http://codeigniter.org.cn/user_guide/libraries/form_validation.html
    法 一

    //载入表单验证类
    $this->load->library('form_validation');
    //语法
    $this->form_validation->set_rules('field','label','rules');
    //示例
    $this->form_validation->set_rules('type','类型','required|integer');
    //执行验证
    $status=$this->form_validation->run();
    

    法 二:通 过 创 建 规 则 集 来 执 行 验 证
    /application/config 下创建一个 form_validation.php里面写入规则集,通过执行 $this->form_validation->run('article'); 来调用

    <?php
    //定义通用规则集
    $config=array(
    	'form1'=>array(
    		array(
    			'field'=>'title',
    			'label'=>'标题',
    			'rules'=>'required|min_length[5]'
    		),
            ···
    	),
    	'form2'=>array(
    		array(
    			'field'=>'title',
    			'label'=>'标题',
    			'rules'=>'required|min_length[5]'
    		),
            ···
    	),
    	···
    ?>
    
    • 文 件 上 传 类 和 缩 略 图

    使 用 手 册:http://codeigniter.org.cn/user_guide/libraries/file_uploading.html#id3

    文 件 上 传 类
    语 法

    //配 置
    $config['upload_path']      = '';//文件路径
    $config['allowed_types']    = '';//允许的文件格式
    $config['max_size']         = '';//允许大小
    $config['file_name']        = '';//文件名
    
    //载 入 上 传 类
    $this->load->library('upload',$config);
    
    //执 行 上 传
    $this->upload->do_upload('');//上传表单名
    

    示 例

    //配 置
    $config['upload_path']      = './uploads/';
    $config['allowed_types']    = 'gif|jpg|png';
    $config['max_size']     = '10000';
    $config['file_name'] = time().mt_rand(1000,9999);
    
    //载 入 上 传 类
    $this->load->library('upload',$config);
    
    //执 行 上 传
    $status=$this->upload->do_upload('thumb');
    if (!$status) {
    	error('必须上传图片');
    }
    $wrong=$this->upload->display_errors();
    if ($wrong) 
    {
    	error($wrong);
    }
    

    缩 略 图
    使用手册:http://codeigniter.org.cn/user_guide/libraries/image_lib.html

    语 法

    //配 置
    $arr['source_image'] = $info['full_path'];//源图片
    $arr['create_thumb'] = FALSE;//预览图像
    $arr['maintain_ratio'] = TRUE;//纵横比
    $arr['width']     = 200;//宽
    $arr['height']   = 200;//高
    
    //载 入 缩 略 图 类
    $this->load->library('image_lib', $config);
    
    //执 行 缩 放 动 作
    $status=$this->image_lib->resize();
    
    

    示 例

    //缩 略 图
    $arr['source_image'] = $info['full_path'];
    $arr['create_thumb'] = FALSE;
    $arr['maintain_ratio'] = TRUE;
    $arr['width']     = 200;
    $arr['height']   = 200;
    
    //载 入 缩 略 图 类
    $this->load->library('image_lib', $config);//config定义在文件上传类中
    
    //执 行 缩 放 动 作
    $status=$this->image_lib->resize();
    if (!$status) 
    {
    	error('缩略图动作失败');
    }
    
    • 分 页

    使 用 手 册:http://codeigniter.org.cn/user_guide/libraries/pagination.html

    语 法

    //载 入 分 页 类
    $this->load->library('pagination');
    
    //每 页 显 示 数
    $perPage=3;
    
    //配 置 项 目 设 置
    $config['base_url']    = '';//分页页地址
    $config['total_rows']  = '';//总的行数
    $config['per_page']    =  $perPage;
    $config['uri_segment'] = 4;//页偏移
    $config['first_link']  = '第一页';
    $config['prev_link']   = '上一页';
    $config['next_link']   = '下一页';
    $config['last_link']   = '最后一页';
    
    //载 入 配 置
    $this->pagination->initialize($config);
    
    //创 建 分 页 链 接
    $data['links']=$this->pagination->create_links();
    
    //获 取 偏 移 量 进 行 分 页
    $offset=$this->uri->segment(4);
    $this->db->limit($perPage,$offset);
    
    • 数 据 库 操 作

    使 用 手 册:http://codeigniter.org.cn/user_guide/database/configuration.html


    Part · 4 Github 探 索

    使 用 教 程:抱 紧 西 瓜 学 长 大 腿

    部 分 学 习 内 容

    版 本 回 退
    语 法

    //xxxxx填入当前想回退的版本SHA
    git reset --hard xxxxx
    git push -f -u origin
    

    示 例

    冲 突 解 决
    参 考 一:http://www.cnblogs.com/schaepher/p/4970291.html
    参 考 二:

    示 例

    END.

  • 相关阅读:
    接下来是沉重的一堆任务啊!
    wxPython入门(一)
    一个比较好玩的东西——硬链接
    Python打印本机IP
    voddown.py v0.3 基本上就这样吧
    Python的正则表达式
    【转】Python命名习惯
    bat命令
    试用了GIMP的Smart remove selection,结果有些失望啊,哈哈
    STM32学习笔记(1)——搭建库函数工程
  • 原文地址:https://www.cnblogs.com/distances/p/7774249.html
Copyright © 2020-2023  润新知