phalcon-自用小例子

    xiaoxiao2026-04-11  6

    phalcon安装

    这里就不再说明windows下phalcon怎么安装了,ubuntu请自行加上 sudo

    通用平台下安装指定的软件包:

    # Ubuntu sudo apt-get install php5-dev libpcre3-dev gcc make php5-mysql # CentOS sudo yum install php-devel pcre-devel gcc make

    创建扩展:

    git clone --depth=1 git://github.com/phalcon/cphalcon.git cd cphalcon/build ./install 添加扩展到你的php配置文件:

    extension=phalcon.so 然后重启php-fpm

    service php-fpm restart

    PhalconTools工具

    phpstrom是通过IDEA定制的php开发工具,也是官方推荐的开发工具

    首先我们要下载phalcon-devtools包并且解压

    下载地址:phalcon-devtools

    也可以在 教程代码库:http://git.oschina.net/wenzhenxi/Phalcon-tutorial本篇教程代码中下载

    phpstrom导入下载好的开发工具

    如上图所示,右键单击“External Libraries”,选择“Configure PHP Include Paths”,弹出如下操作框:

    单点“+”按钮,在弹出的操作框中,选择到刚才phalcon-devtools的解压目录,然后双击选中“/ide/任一Phalcon版本/Phalcon/”目录,点击“应用”和“确定”即可。如上图所示,我选择的是2.0.8版本。

    phpstorm自动提示Phalcon语法

    log-日志

    use Phalcon\Logger\Adapter\File as FileAdapter; $logger = new FileAdapter("../Runtime/log/2016-2/20160203.log"); //初始化文件地址 $logger->log("This is a message"); //写入普通log $logger->log("This is an error", \Phalcon\Logger::ERROR); //写入error信息 $logger->error("This is another error"); //于上一句同义 // 开启事务 $logger->begin(); // 添加消息 $logger->alert("This is an alert"); $logger->error("This is another error"); // 保存消息到文件中 $logger->commit(); <?php use Phalcon\Logger; use Phalcon\Logger\Multiple as MultipleStream; use Phalcon\Logger\Adapter\File as FileAdapter; use Phalcon\Logger\Adapter\Stream as StreamAdapter; $logger = new MultipleStream(); $logger->push(new FileAdapter('test.log')); $logger->push(new StreamAdapter('php://stdout')); $logger->log("This is a message"); $logger->log("This is an error", Logger::ERROR); $logger->error("This is another error"); use Phalcon\Logger\Formatter\Line as LineFormatter; // 修改日志格式 $formatter = new LineFormatter("[
    转载请注明原文地址: https://yun.8miu.com/read-146528.html
    最新回复(0)