search

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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment