ComposerでCodeigniter3とIon-Authライブラリを導入する方法

CodeIgniter

パッケージ管理ツールのComposerを使用してCodeigniter3のインストールした上で認証ライブラリであるIon-Authのセットアップ方法を説明しています。

インストール

Codeigniterのインストール

次のComposerコマンドでCodeigniter3をインストールします、

# composer create-project kenjis/codeigniter-composer-installer <インストール先ディレクトリ名>

Ion-Authのインストール

次のComposerコマンドでIon-Authをインストールします。

# cd <インストール先ディレクトリ名>
# php bin/install.php ion-auth 2

データベースの設定

データベースのスキーマを管理する機能を追加します。

コマンド実行ファイルの作成

以下のファイルを/application/controllers/内に設置します。

Migrate.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Migrate extends CI_Controller {

    function __construct()
    {   
        parent::__construct();
        if(! $this->input->is_cli_request()) {
            show_404();
            exit;
        }   
        $this->load->library('migration');
    }   

    function current()
    {   
        if ($this->migration->current()) {
            log_message('error', 'Migration Success.');
        } else {
            log_message('error', $this->migration->error_string());
        }   
    }   

    function rollback($version)
    {   
        if ($this->migration->version($version)) {
            log_message('error', 'Migration Success.');
        } else {
            log_message('error', $this->migration->error_string());
        }   
    }   

    function latest()
    {   
        if ($this->migration->latest()) {
            log_message('error', 'Migration Success.');
        } else {
            log_message('error', $this->migration->error_string());
        }   
    }

}
マイグレーションの設定
application/config/migration.phpを次のように編集します。

<?
// マイグレーションを有効化
$config['migration_enabled'] = TRUE;
// シーケンス番号で管理
$config['migration_type'] = 'sequential';

コメント

タイトルとURLをコピーしました