0

私は CodeIgniter を初めて使用し、ライブラリを使用して、現在取り組んでいるアプリケーションのイベントを管理しようとしています。少しグーグルした後、以下に記載されているライブラリが最高のものであることがわかりました。

https://github.com/ericbarnes/CodeIgniter-Events/blob/master/libraries/events.php

しかし、私はそれを使用する方法がわかりません..まあ、ユーザーがイベントを追加、表示、更新、および削除できるコードを少しコーディングしました。しかし、ユーザーがイベントを追加した場合にイベントを管理したいイベントの時間が終了すると、イベントはビュー部分から自動的に非表示になるはずです...上記のlibarayでそれを行うことはできますか?? または誰でも私に最高のイベントライブラリを教えてください....

4

1 に答える 1

2

私はあなたが何か間違っていると思います。そのライブラリは、イベントを処理するように設計されています。特に、アプリケーションで処理したい何かが発生したときにアプリケーションに通知するように設計されています。

あなたの質問に基づいて、パーティー、会議などのイベントを管理できる機能を実装したいと思います。

フレームワーク (および追加のライブラリ) は開発プロセスを簡素化するためのツールキットにすぎないため、すぐに使用できるソリューションはほとんど見つかりません。

クイックスタートを提供するために、私はあなたのために何かを組み立てました。CodeIgniter は、カレンダー システムを作成する作業を簡素化しようとするカレンダー ライブラリを提供します。

それでは、3 つのファイルを作成しましょう。カレンダー テンプレートのコントローラー、モデル、およびビューファイル。

アプリケーション/コントローラー/calendar.php

<?php

class Calendar extends CI_Controller{

    /**
     * The constructor loads our calendar library and passes 
     * our custom calendar template to it. Also we load 
     * the calendar model where the events will be pulled from
     * later on.
     */

    public function __construct()
    {
        parent::__construct();

        $calendar_conf['template'] = $this->load->view('calendar_template', null, true);
        $this->load->library('calendar', $calendar_conf);

        $this->load->model('calendar_model');
    }

    /**
     * Pulls events from our Calendar_Model and displays the
     * events
     */

    public function index()
    {
        $year = date('Y');
        $month = date('m');

        $events = $this->calendar_model->get_events($year, $month);
        echo $this->calendar->generate($year, $month, $events);

    }

}

アプリケーション/モデル/calendar_model.php

<?php

class Calendar_Model extends CI_Model{

    private $events = array(
        '2013' => array(
            '07' => array(
                3  => 'Meeting with Mr. Smith',
                7  => 'Big Party tonight bro!',
                13 => 'Something Big will happen here ;)',
            )
        )
    );

    /**
     * Gets events of a given year and month
     * your probably want to pull your events 
     * from a database.
     */

    public function get_events($y, $m)
    {
        if(!isset($this->events[$y][$m]))
            return null;
        return $this->events[$y][$m];
    }

}

最後に、カレンダー テンプレートを作成しましょう

アプリケーション/ビュー/calendar_template.php

{table_open}<table border="0" cellpadding="0" cellspacing="4">{/table_open}

{heading_row_start}<tr>{/heading_row_start}

{heading_previous_cell}<th><a href="{previous_url}">&lt;&lt;</a></th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th><a href="{next_url}">&gt;&gt;</a></th>{/heading_next_cell}

{heading_row_end}</tr>{/heading_row_end}

{week_row_start}<tr>{/week_row_start}
{week_day_cell}<td>{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}

{cal_row_start}<tr>{/cal_row_start}
{cal_cell_start}<td>{/cal_cell_start}

{cal_cell_content}<a href="#" title="{content}">{day}</a>{/cal_cell_content}
{cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}

{cal_cell_no_content}{day}{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="highlight">{day}</div>{/cal_cell_no_content_today}

{cal_cell_blank}&nbsp;{/cal_cell_blank}

{cal_cell_end}</td>{/cal_cell_end}
{cal_row_end}</tr>{/cal_row_end}

{table_close}</table>{/table_close}

コントローラーは、イベント データが保存されているモデルを読み込み、そのデータを CI のネイティブ カレンダー ライブラリに渡します。次に、カレンダー自体を表示します。モデル自体は、イベント データを保持し、イベントの読み取りと (ここでは実装されていませんが、必要に応じて) 書き込みを行うメソッドを提供することに専念しています。

最後に、カレンダー テンプレートとして機能するビューファイルを作成します。CodeIgniter によって提供されるテンプレート変数を使用します。ここで読むことができます: http://ellislab.com/codeigniter/user-guide/libraries/calendar.html

もちろん、これはカレンダー アプリケーションのごく一部にすぎません。たとえば、イベントはデータの文字列以上を保持することはできません。CodeIgniter に慣れてきたら、ネイティブのカレンダー クラスを拡張して、配列を格納できるようにしたいと思うかもしれません。

でも今は良いスタートだと思います。これについてさらに質問がある場合は、遠慮なく質問してください。

ハッピーコーディング!

于 2013-07-11T08:11:31.850 に答える