在 Claude Code 中直接建立 Craft CMS 自訂模組
何時使用: 需要建立新模組,但不想手動複製現有模組當範本時。
步驟
-
描述模組的用途Use craftcms-claude-skills. Create a new module called 'Inventory' that registers a custom element type for warehouse items.✓ 已複製→ Claude 建立 modules/inventory/ 目錄,包含 src/Inventory.php、elements/WarehouseItem.php 及設定項目
-
完成接入設定Register the module in config/app.php and add the bootstrap entry.✓ 已複製→ 顯示設定檔差異;執行 craft setup/check 時模組可正常載入
-
新增元素查詢Add a WarehouseItemQuery class with a custom 'sku' parameter that filters on the content table.✓ 已複製→ 查詢類別包含正確的 WHERE 子句,而非雜亂的原始 SQL
結果: 一個符合 Pixel & Tonic 開發規範的可運行 Craft 模組——可直接進行第一次資料庫遷移。
注意事項
- Claude 產出 Craft 3/4 風格的程式碼 — 每次提示都明確指定 Craft CMS 5——API 介面已有所變動