Skip to content
オープンソース・ワークショップ 永原 篤 edited this page Mar 11, 2022 · 14 revisions

オリジナル・プラグインの開発方法

Connect-CMS では、プラグインを開発して追加することもできます。
オリジナル・プラグインを開発して追加することで、機能を向上させ、便利なサイトや特別な業務サイトを作るることが可能です。

注意点

ファイルの文字コードは、UTF-8 を使用してください。
※ 半角英数のみの場合は、エディタが Shift_JIS と表示する場合もありますが、それは問題ありません。

改行コードは LF を使用してください。
※ Github にアップロードする際のポイントです。CRLF でも、動作はすると思います。

概要

バケツ、ページ、フレームの理解
https://manual.connect-cms.jp/blueprint/index/index/index.html
※ DB定義では、バケツを表すDBテーブルと、記事を表すDBテーブルの2つを作成します。

Option プラグインで作成する。
※ Option プラグインは今後、マニュアルを追加

進め方
□ migration コマンドでDB 定義のひな型を生成するところは、コマンドを実行してみる。
□ その他のファイルは、Sample プラグインのファイルをひとつずつコピーしてきて、解説していく。
以下の説明で、○○ ファイルを作成。とある部分は、コピーしてくる。と読み替えながら進める。
□ 動かしてみる。

DB 定義の作成(DB 定義の生成)

--- Migration でDB 定義の生成(オプションプラグイン用)

> php artisan make:migration create_samples_table --path=database/migrations_option  
Created Migration: YYYY_MM_DD_HHiiss_create_samples_table

※ database\migrations_option\YYYY_MM_DD_HHiiss_create_samples_table.php が作成される。

> php artisan make:migration create_sample_posts_table --path=database/migrations_option  
Created Migration: YYYY_MM_DD_HHiiss_create_sample_posts_table

※ database\migrations_option\YYYY_MM_DD_HHiiss_create_sample_posts_table.php が作成される。

DB 定義の作成(Migration ファイルの修正)

samples テーブル

  • 必要なカラムの追加
$table->integer('bucket_id');  
$table->string('bucket_name', 255)->comment('バケツ名');  
  • 標準のtimestamps()を削除
//$table->timestamps();  
  • Connect-CMSのテーブルサフィックスを追加
$table->integer('created_id')->nullable();  
$table->string('created_name', 255)->nullable();  
$table->timestamp('created_at')->nullable();  
$table->integer('updated_id')->nullable();  
$table->string('updated_name', 255)->nullable();  
$table->timestamp('updated_at')->nullable();  
$table->integer('deleted_id')->nullable();  
$table->string('deleted_name', 255)->nullable();  
$table->timestamp('deleted_at')->nullable();  

sample_posts テーブル

  • 必要なカラムの追加
$table->integer('sample_id');
$table->string('title', 255)->comment('タイトル');
$table->text('content')->nullable()->comment('内容');  
  • 標準のtimestamps()を削除
//$table->timestamps();  
  • Connect-CMSのテーブルサフィックスを追加
$table->integer('created_id')->nullable();  
$table->string('created_name', 255)->nullable();  
$table->timestamp('created_at')->nullable();  
$table->integer('updated_id')->nullable();  
$table->string('updated_name', 255)->nullable();  
$table->timestamp('updated_at')->nullable();  
$table->integer('deleted_id')->nullable();  
$table->string('deleted_name', 255)->nullable();  
$table->timestamp('deleted_at')->nullable();  

DB 定義の作成(Migration ファイルの実行)

C:\SitesLaravel\connect-cms\htdocs\connect-cms>php artisan migrate --path=database/migrations_option
Migrating: 2022_03_10_221356_create_samples_table
Migrated:  2022_03_10_221356_create_samples_table (0.03 seconds)
Migrating: 2022_03_11_091238_create_sample_posts_table
Migrated:  2022_03_11_091238_create_sample_posts_table (0.03 seconds)

※ これで、データベースが生成されます。
※ データベースを見るツールは各自で勉強してください。

Clone this wiki locally