Blog

  • Model-View-Controller

    Model-View-Controller

    CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.

    The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.
    The View is the information that is being presented to a user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of “page”.
    The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.

    CodeIgniter has a fairly loose approach to MVC since Models are not required. If you don’t need the added separation, or find that maintaining models requires more complexity than you want, you can ignore them and build your application minimally using Controllers and Views. CodeIgniter also enables you to incorporate your own existing scripts, or even develop core libraries for the system, enabling you to work in a way that makes the most sense to you.
    • 模型 包含与您的数据库和其他数据结构相关的所有代码。如果您具有一个名为 pages 的表,则您具有一个模型,其中具有用于从表中选择、创建、更新和删除记录的函数。
    • 视图 包含所有显示和 UI 元素 — JavaScript 代码、Cascading Style Sheets (CSS)、HTML 甚至 PHP。
    • 控制器 将一切联系在一起。控制器中的每个函数表示一个目的地或路线。如果您具有一个名为 /about 的目的地,则控制器将具有一个名为 about() 的函数。
  • python sleep

    在调试代码的时候要分析 block

    可以用 sleep 使程序 block 一段时间

    #!/usr/bin/python
    import time
    
    print "Start : %s" % time.ctime()
    time.sleep( 5 )
    print "End : %s" % time.ctime()
    
  • php调试-写变量到文件

    写变量到文件

    $myfile = fopen("./testfile.txt", "w");
    $txt = "Jane Doe\n";
    fwrite($myfile, $txt);
    fwrite($myfile, $query);
    fclose($myfile);
    
  • python获取昨天日期时间戳

    snippet

    import datetime
    yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
    yesterday_formatted = yesterday.strftime("%Y-%m-%d")

    python 生成时间戳

    import time
    now = int(time.time())
  • git通过https方式访问时保存认证

    从 github 上更新代码,用的方式为 https方式。如果 git 客户端 >= 1.7.9,使用如下方式缓存密码

    git config --global credential.helper cache

    默认缓存 900s( 15 min),设置 1 小时

    git config --global credential.helper "cache --timeout=3600"

    如果 git 客户端 < 1.7.9 使用命令

    git config remote.origin.url https://you:[email protected]/you/example.git

    或直接编辑文件 .git/config, 在 username 后加上你的密码

    [remote "origin"]
            fetch = +refs/heads/*:refs/remotes/origin/*
            url = https://username:[email protected]/jpuyy/myproxy.git

    参考:
    http://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using-https-github

  • nginx location proxy_pass URI问题

    对于配置 nginx proxy_pass,对于请求的 URI 最后面的 slah 即 / 有无需要注意。

    例子

    请求 jpuyy.com/compare/mid/222.do
    proxy_pass 目标是 http://192.168.2.2:8082/compare/mid/222.do

    测试一:proxy_pass 最后面有 /

    location ^~ /compare/ {
        proxy_pass http://192.168.2.2:8082/;
        # 有 /,将从 /compare/ 右做为请求与 proxy_pass 进行拼接, request to http://192.168.2.2:8082/mid/222.do
    }

    测试二:proxy_pass 最后无 /

    location ^~ /compare/ {
        proxy_pass http://192.168.2.2:8082;
        # 无 /,将从/compare/左侧最开始做为请求与 proxy_pass 进行拼接, request to http://192.168.2.2:8082/compare/mid/222.do
    }

    这样测试一会报 404 错,证明要采用测试二。

    例子

    请求 jpuyy.com/news/abc.xml
    proxy_pass 目标为 http://192.168.2.2:80/news/abc.xml

    location /news/abc.xml {
        proxy_pass http://192.168.2.2:80/news/abc.xml;
    }