Table of Contents
安装
创建你的项目
启用webtools
集成PhpStrom代码提示

Phalcon 入门

Jun 20, 2016 pm 12:33 PM

Phalcon和Yaf一样,都是C写的PHP扩展,性能相对于Laravel、Yii等框架相对快一些。Phalcon相对于Yaf来说,优势在于有完善的一套体系,例如代码生成,缓存,ORM,队列等。Yaf其实就是一个简单的MVC,不过毕竟着重点不一样,Yaf其实搭配一些ORM,缓存,一些基本的项目也就足够用了。这里我们不探讨那个框架更好,还是直入主题,一起来看看Phalcon究竟如何使用。

安装

官方文档中有很多种操作系统的安装方法,其实很简单就是一个扩展,只需要找到相应的PHP版本,把扩展添加到php.ini中即可。Mac OS X

brewsearchphpxx-phalconbrewinstallphpxx-phalcon
Copy after login

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
Copy after login

这一步操作很简单 在github打包下载phalcon-tools,我在下载的时候发现没反应,就直接在github上下载好,rename下放到指定位置就行了

接下来就是配置环境变量

exportPATH=$PATH:/Users/scott/phalcon-toolsexportPTOOLSPATH=/Users/scott/phalcon-tools
Copy after login

这种方法只是临时生效,我用的是zsh,所以我直接把这段话放到了.zshrc中,每次打开终端都会生效,方便了许多,如果你是其他系统,只需要配置相应的环境变量即可。

ln -s ~/phalcon-tools/phalcon.php ~/phalcon-tools/phalconchmod +x ~/phalcon-tools/phalcon
Copy after login

这里要注意你的路径是否正确,然后你就可以测试一下是否成功,打开终端,输入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)
Copy after login

接下来,切换到你的workspace,生成你的项目

phalconprojectproject-name
Copy after login

然后通过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
Copy after login

会出现以下提示,并在public目录下生成webtools.php

Success: Webtools successfully enabled!

注意:如果你是通过xxx.com/webtools.php

会出现js 和 css加载不上的问题,因为默认配置文件中的路径是http://host/phalcon/***

需要修改/app/config/config.php application 中的 baseUrl 修改为“/”即可

然后需要重新禁用,再启用webtools

phalconwebtoolsdisablephalconwebtoolsenable
Copy after login

集成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 of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

See all articles