Phalcon 入门
Phalcon和Yaf一样,都是C写的PHP扩展,性能相对于Laravel、Yii等框架相对快一些。Phalcon相对于Yaf来说,优势在于有完善的一套体系,例如代码生成,缓存,ORM,队列等。Yaf其实就是一个简单的MVC,不过毕竟着重点不一样,Yaf其实搭配一些ORM,缓存,一些基本的项目也就足够用了。这里我们不探讨那个框架更好,还是直入主题,一起来看看Phalcon究竟如何使用。
安装
官方文档中有很多种操作系统的安装方法,其实很简单就是一个扩展,只需要找到相应的PHP版本,把扩展添加到php.ini中即可。Mac OS X
brewsearchphpxx-phalconbrewinstallphpxx-phalcon
xx代表php对应的版本,本文中的php版本为5.5。一般来讲,brew 会安装在 /usr/local/Cellar/php55-phalcon,并且生成/usr/local/etc/php/5.5/conf.d/ext-phalcon.ini
如果你已经指定额外配置文件路径 Scan this dir for additional .ini files => /usr/local/etc/php/5.5/conf.d
那么直接php -m 查看下扩展是否安装成功就OK了
Linux
如果能用yum、apt-get,那么和mac下基本类似,实在不行就找到对应版本的.so文件 添加到php扩展即可。
Windows
同上找到相应版本的.dll添加php 扩展
创建你的项目
这里我们直接用phalcon提供的tools来生成,首先要安装tools,官方提供了各种系统的安装,这里简单介绍下mac下的安装。
wget -q --no-check-certificate -O phalcon-tools.ziphttp://github.com/phalcon/phalcon-devtools/zipball/masterunzip -q phalcon-tools.zipmvphalcon-phalcon-devtools-* phalcon-tools
这一步操作很简单 在github打包下载phalcon-tools,我在下载的时候发现没反应,就直接在github上下载好,rename下放到指定位置就行了
接下来就是配置环境变量
exportPATH=$PATH:/Users/scott/phalcon-toolsexportPTOOLSPATH=/Users/scott/phalcon-tools
这种方法只是临时生效,我用的是zsh,所以我直接把这段话放到了.zshrc中,每次打开终端都会生效,方便了许多,如果你是其他系统,只需要配置相应的环境变量即可。
ln -s ~/phalcon-tools/phalcon.php ~/phalcon-tools/phalconchmod +x ~/phalcon-tools/phalcon
这里要注意你的路径是否正确,然后你就可以测试一下是否成功,打开终端,输入phalcon commands
$ phalconcommands PhalconDevTools (2.0.8) Availablecommands: commands (aliasof: list, enumerate) controller (aliasof: create-controller) model (aliasof: create-model) all-models (aliasof: create-all-models) project (aliasof: create-project) scaffold (aliasof: create-scaffold) migration (aliasof: create-migration) webtools (aliasof: create-webtools)
接下来,切换到你的workspace,生成你的项目
phalconprojectproject-name
然后通过nginx或者apache将路径指向入口文件/public/,通过浏览器访问会出现
Congratulations!You’re now flying with Phalcon. Great things are about to happen!
This page is located at views/index/index.volt
启用webtools
切换到你的项目中,然后输入
phalconwebtoolsenable
会出现以下提示,并在public目录下生成webtools.php
Success: Webtools successfully enabled!
注意:如果你是通过xxx.com/webtools.php
会出现js 和 css加载不上的问题,因为默认配置文件中的路径是http://host/phalcon/***
需要修改/app/config/config.php application 中的 baseUrl 修改为“/”即可
然后需要重新禁用,再启用webtools
phalconwebtoolsdisablephalconwebtoolsenable
集成PhpStrom代码提示
在你的project下面的External Libraries上点击右键找到Configure PHP Include Path,选中后找到Include path 西面的“+”图标
选中/phalcon-tools/ide/2.0.9/Phalcon路径,确定即可。
这样一来,编译器再也不会提醒错误,还有提醒功能,开发效率明显提高!
官方文档地址:https://docs.phalconphp.com/en/latest/index.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
