欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

PhpStorm集成Drupal Drush命令行工具

shiping1 的头像

PhpStorm集成Drupal Drush命令行工具

分类: Drupal,ToolsLi Xi @ 8:25 下午

本教程主要讲解在Windows下的PHPStorm IDE集成Drupal Drush命令行工具,你也可以作为Linux下的一个参照样本。

在看本文之前可以看看PHPStorm相关的文章:

Drush 是一个为Drupal设计的命令行shell 和脚本接口。

安装 Drush

主要讲解Windows下如何安装Drush命令。

Drush官方提供了Drush Windows Installer安装应用程序。

可以通过http://www.drush.org/drush_windows_installer下载最新的版本。在安装时,注意安装时同时选择把Drush注册环境变量。

安装完成后Drush 默认安装在:C:\ProgramData\Drush\drush.bat

在Windows 默认的CMD命令窗口,输入drush命令,执行出以下结果:

Windows_install_Drush 在Windows CMD输入Drush 后执行命令并显示帮助信息

图1 在Windows CMD输入Drush 后执行命令并显示帮助信息

当你没有看到任何错误信息和显示正确的Drush帮助信息表示Drush 在Windows下安装成功!

PhpStorm 集成 Drush

PhpStorm IDE的命令行工具支持Drush 5.8和更高版本。

为了配置Drush作为一个命令行工具在PHPStorm IDE开发环境中,请打开 Settings | Command Line Tool Support ,增加新的命令行工具可以点击“加号”图标

PHPStorm-Drush-Comand-Tool-Support PhpStorm命令行工具支持Drush

图2 PhpStorm命令行工具支持Drush

Drush 命令行工具提供了命令自动补全。并且所有的输出会直接显示在PhpStorm命令行工具控制台。

现在你可以启动命令行工具,通过选择Tools | Run Command… 或按Ctrl + Shift + X 快捷键(Cmd-Shift-X 在Mac OS X)。

PHPStorm-Drush-Comand-Tools-Console PHPStorm在Command Line Tools Console 输入drush后会自动补全命令

图3 在Command Line Tools Console 输入drush后会自动补全命令,回车后即可运行命令。

PhpStorm 项目中使用 Drush

当你所在的项目为Drupal时,在Command Line Tools Console 输入以下几个命令测试一下:

 

1、清除Drupal 缓存

在Command Line Tools Console 输入drush cc,在输入 1 ,运行结果为如下:

> C:\ProgramData\Drush\drush.bat cc
Enter a number to choose which cache to clear.
[0]  :  Cancel        
[1]  :  all           
[2]  :  drush         
[3]  :  theme-registry
[4]  :  menu          
[5]  :  css-js        
[6]  :  block         
[7]  :  module-list   
[8]  :  theme-list    
[9]  :  registry      

1
‘all’ cache was cleared in E:/USB/wnmp/www/drupal-7.22#default         [success]

Process finished with exit code 0 at 20:04:02.
Execution time: 11,256 ms.

或者直接在Command Line Tools Console 输入drush cc all其中 all 为类型(Type),可以为Cancel、all、drush、theme-registry、menu、css-js、block、module-list、theme-list和registry,运行结果为如下:

> C:\ProgramData\Drush\drush.bat cc all
‘all’ cache was cleared in E:/USB/wnmp/www/drupal-7.22#default         [success]

Process finished with exit code 0 at 20:07:23.
Execution time: 9,677 ms.

2、下载Drupal 模块

在Command Line Tools Console 输入drush dl token,在输入 1 运行结果为如下:

> C:\ProgramData\Drush\drush.bat dl token
Project token (7.x-1.5) downloaded to                                  [success]
E:/USB/wnmp/www/drupal-7.22/sites/all/modules/contrib/token.

Process finished with exit code 0 at 20:10:06.
Execution time: 44,300 ms.

Drush 实现命令行来操作Drupal,用起来挺方便的,不用每次去网站后台操作了。

如果你有什么问题,请在评论中留言!


查看更多: PhpStorm集成Drupal Drush命令行工具 | LixiPHP - 专注于建设高品质网站! http://blog.lixiphp.com/phpstorm-integrate-drush/#ixzz2oeD06fxv

来自 http://blog.lixiphp.com/phpstorm-integrate-drush/#axzz2oZjG6300
普通分类: