AgentSkillsCN

pw-ddev-cli

通过 ddev 使用 ProcessWire CLI——运行 PHP 脚本、引导 ProcessWire API、借助 Tracy 进行调试,以及直接执行数据库查询。适用于在 ProcessWire ddev 项目中运行 PHP 代码、编写 CLI 脚本,或直接对数据库进行查询时使用。

SKILL.md
--- frontmatter
name: pw-ddev-cli
description: ProcessWire CLI usage via ddev — running PHP scripts, bootstrapping the PW API, debugging with Tracy, and direct database queries. Use when executing PHP in a ProcessWire ddev project, writing CLI scripts, or querying the database directly.

ProcessWire CLI via ddev

All PHP CLI commands must run through ddev to use the web container's PHP interpreter.

Basic Commands

bash
ddev php script.php          # Run PHP script
ddev php --version           # Check PHP version
ddev exec php script.php     # Execute in web container
ddev ssh                     # Interactive shell

Bootstrapping ProcessWire

Include ./index.php from project root to get the full PW API ($pages, $page, $config, $sanitizer, etc.).

All CLI script files must be placed in ./cli_scripts/.

bash
# Inline one-liner
ddev exec php -r "namespace ProcessWire; include('./index.php'); echo PHP_EOL.'Count: '.pages()->count('template=product');"
bash
# Script file
ddev php cli_scripts/myscript.php

One-liner rules:

  • Use functions API (pages(), templates(), modules()) to avoid bash $ variable expansion
  • Escape local variables with \$var
  • Prefix output with PHP_EOL to separate from RockMigrations log noise

Reference Files