php [cakephp:DropShell]删除所有应用程序表以进行开发。 #cakephp

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [cakephp:DropShell]删除所有应用程序表以进行开发。 #cakephp相关的知识,希望对你有一定的参考价值。

<?php 
namespace App\Shell;

use Cake\Console\Shell;
use Cake\ORM\TableRegistry;
use Cake\Auth\DefaultPasswordHasher;
use Cake\Datasource\ConnectionManager;
use Cake\Filesystem\Folder;
use Cake\Filesystem\File;

/**
 * DropShell Class.
 *
 * ShellClass of cake shell command 'drop'.
 * Drop all application tables for development. 
 *
 * @access public
 * @author hyano@ampware.jp
 * @category Batch processing
 * @package Shell
 */
class DropShell extends Shell
{


  /** 
   * Initialize instance for all methods.
   * @param  void
   * @return void
   */
  public function initialize() {
    parent::initialize();
    $this->Hasher     = new DefaultPasswordHasher();
    $this->Connection = ConnectionManager::get('default');
  }

  
  /**
   * Printing welcome messages.
   * @param  void
   * @return void
   */
  public function startup() {
    // If you want to output welcome messages, override parent method like this.
    // parent::initialize();
  }


  /** 
   * Main command for `$ bin/cake example`.
   * Method runs when executed without sub-command or args.
   * @param  void
   * @return void
   */
  public function main() {
    $isContinue = $this->in('Want to continue the process ?', ['y', 'N'], 'N');
    if ($isContinue !== 'y') $this->abort('Process was canceled.');
    if (empty($this->Connection)) $this->abort('Fatal: Missing DB connection.');
    $tables = $this->Connection->schemaCollection()->listTables();
    $tables = implode(', ', $tables);
    $this->Connection->query('SET FOREIGN_KEY_CHECKS=0');
    $this->Connection->query('DROP TABLE '.$tables);
    $this->Connection->query('SET FOREIGN_KEY_CHECKS=1');
    $this->out('success!');
  }


}

以上是关于php [cakephp:DropShell]删除所有应用程序表以进行开发。 #cakephp的主要内容,如果未能解决你的问题,请参考以下文章

cakephp烤

从 url 中删除控制器名称不适用于 cakephp 中的多个控制器

在 MacOS 上安装 PHP intl 扩展 [关闭]

php [cakephp:mysqldump] mysqldumpのcakephp実装サンプル。#php #cakephp #mysql

php [cakephp:Paginator示例] CakePHP上PaginatorComponent的示例代码。 #cakephp

如何在 cakephp4 中使用 Admad cakephp-glide 删除 Glide 缓存?