是否可以自定义 bake (CakePHP 3) 添加的操作?
Is it possibile customize the actions added by bake (CakePHP 3)?
我希望能够在不使用 "view" 操作的情况下烘焙控制器和视图。
是否有任何参数或方法可以跳过甚至自定义烘焙命令的操作?
我发现我可以使用事件来修改 bake 的行为。
将以下代码添加到bootstrap_cli.php
use Cake\Event\Event;
use Cake\Event\EventManager;
use Cake\Utility\Hash;
// put all 'use' statements at the top of the file
EventManager::instance()->on(
'Bake.beforeRender.Controller.controller',
function (Event $event) {
$view = $event->getSubject();
if(!empty($view->viewVars['actions'])) {
$messages = $view->viewVars['actions'];
$del_val = 'view';
if (($key = array_search($del_val, $messages)) !== false) {
unset($messages[$key]);
echo "\n";
echo '====== NOTICE ======' . "\n";
echo 'Removed view action.' . "\n";
echo '====================' . "\n";
}
$view->viewVars['actions'] = $messages;
}
}
);
更多信息位于:https://book.cakephp.org/3.0/en/bake/development.html
我希望能够在不使用 "view" 操作的情况下烘焙控制器和视图。 是否有任何参数或方法可以跳过甚至自定义烘焙命令的操作?
我发现我可以使用事件来修改 bake 的行为。
将以下代码添加到bootstrap_cli.php
use Cake\Event\Event;
use Cake\Event\EventManager;
use Cake\Utility\Hash;
// put all 'use' statements at the top of the file
EventManager::instance()->on(
'Bake.beforeRender.Controller.controller',
function (Event $event) {
$view = $event->getSubject();
if(!empty($view->viewVars['actions'])) {
$messages = $view->viewVars['actions'];
$del_val = 'view';
if (($key = array_search($del_val, $messages)) !== false) {
unset($messages[$key]);
echo "\n";
echo '====== NOTICE ======' . "\n";
echo 'Removed view action.' . "\n";
echo '====================' . "\n";
}
$view->viewVars['actions'] = $messages;
}
}
);
更多信息位于:https://book.cakephp.org/3.0/en/bake/development.html