<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FullCalendar  |  takeHo（たけほ）のへなちょこ台帳</title>
	<atom:link href="https://blog.takeho.com/tag/fullcalendar/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.takeho.com</link>
	<description>いわゆる自由帳ってところです。</description>
	<lastBuildDate>Thu, 12 Dec 2024 08:08:25 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6</generator>

<image>
	<url>https://blog.takeho.com/wp-content/uploads/2024/08/icon-150x150.png</url>
	<title>FullCalendar  |  takeHo（たけほ）のへなちょこ台帳</title>
	<link>https://blog.takeho.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Yii2でFullCalendarを簡単に導入する方法</title>
		<link>https://blog.takeho.com/how-to-easily-implement-fullcalendar-in-yii2/</link>
					<comments>https://blog.takeho.com/how-to-easily-implement-fullcalendar-in-yii2/#respond</comments>
		
		<dc:creator><![CDATA[たけほ]]></dc:creator>
		<pubDate>Wed, 11 Dec 2024 03:03:00 +0000</pubDate>
				<category><![CDATA[Yii2]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[FullCalendar]]></category>
		<guid isPermaLink="false">https://blog.takeho.com/?p=579</guid>

					<description><![CDATA[Yii2フレームワークを使用して開発していると、カレンダーを使ったイベント管理が必要になることがあります。そのような場合に便利なツールが、JavaScriptベースのライブラリであるFullCalendarです。本記事で [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Yii2フレームワークを使用して開発していると、カレンダーを使ったイベント管理が必要になることがあります。そのような場合に便利なツールが、JavaScriptベースのライブラリである<strong>FullCalendar</strong>です。本記事では、FullCalendarをYii2プロジェクトに簡単に導入し、基本的なカレンダー表示を実現する方法をご紹介します。</p>



<h2 class="wp-block-heading">FullCalendarとは</h2>



<p>FullCalendarは、イベントのスケジュールやカレンダー表示を簡単に実装できる人気のJavaScriptライブラリです。レスポンシブ対応やさまざまなカスタマイズオプションを備えており、Googleカレンダーのような体験を提供できます。</p>



<h2 class="wp-block-heading">Yii2プロジェクトへの導入手順</h2>



<h3 class="wp-block-heading">拡張機能からインポート</h3>



<p>「yiitwofullcalendar」は、Yii2でFullCalendarを手軽に扱うための拡張です。これを使用することで、イベントの表示やカレンダーの基本的な設定が簡単に行えます。</p>



<p>Composerを使用して「yiitwofullcalendar」をインストールします。</p>



<pre class="wp-block-code"><code>php composer.phar require edofre/yii2-fullcalendar "@dev"</code></pre>



<p>Composerが依存関係を解決してインストールを完了したら、すぐに利用できます。</p>



<h3 class="wp-block-heading">カレンダーの表示</h3>



<p>次に、カレンダーを表示する基本的なコードを用意します。ここでは、<code>site/index</code>アクションでカレンダーを表示する例を示します。</p>



<h4 class="wp-block-heading">コントローラーの設定</h4>



<p><code><strong>controllers/SiteController.php</strong></code>で、イベントデータを渡す処理を記述します。</p>



<pre class="wp-block-code"><code>public function actionIndex()
{
    $events = &#91;
        &#91;
            'title' => 'イベント1',
            'start' => '2024-12-15',
        ],
        &#91;
            'title' => 'イベント2',
            'start' => '2024-12-18',
            'end' => '2024-12-20',
        ],
    ];

    return $this->render('index', &#91;'events' => $events]);
}</code></pre>



<h4 class="wp-block-heading">ビューの設定</h4>



<p><code><strong>views/site/index.php</strong></code>に、カレンダーを表示するコードを追加します。</p>



<pre class="wp-block-code"><code>&lt;?php
use yii2fullcalendar\yii2fullcalendar;

echo yii2fullcalendar::widget(&#91;
    'options' => &#91;
        'id' => 'calendar',
    ],
    'clientOptions' => &#91;
        'locale' => 'ja',
        'initialView' => 'dayGridMonth',
        'headerToolbar' => &#91;
            'left' => 'prev,next today',
            'center' => 'title',
            'right' => 'dayGridMonth,timeGridWeek,timeGridDay',
        ],
    ],
    'events' => $events, // コントローラーから渡されたイベントデータ
]);
?></code></pre>



<p>上記のコードでは、<code>events</code>キーに渡したデータがカレンダーに表示されます。</p>



<h2 class="wp-block-heading">カスタマイズ例</h2>



<h3 class="wp-block-heading">イベントのクリック処理を追加</h3>



<p>イベントをクリックした際にアラートを表示する機能を追加する例です。</p>



<pre class="wp-block-code"><code>'clientEvents' => &#91;
    'eventClick' => new \yii\web\JsExpression('function(event) {
        alert("イベントタイトル: " + event.title);
    }'),
],</code></pre>



<h3 class="wp-block-heading">Ajaxで動的にイベントを取得</h3>



<p>イベントを動的に取得するには、<code>events</code>キーにURLを指定します。</p>



<pre class="wp-block-code"><code>'events' => \yii\helpers\Url::to(&#91;'/event/get-events']),</code></pre>



<p>コントローラーで、指定したURLに対応するアクションを作成し、イベントデータを返します。</p>



<pre class="wp-block-preformatted">public function actionGetEvents()<br>{<br>    \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;<br>    return [<br>        [<br>            'title' => '動的イベント',<br>            'start' => date('Y-m-d'),<br>        ],<br>    ];<br>}</pre>



<h2 class="wp-block-heading">まとめ</h2>



<p>「yiitwofullcalendar」を使えば、Yii2プロジェクトでFullCalendarを簡単に利用できます。デフォルト機能を活用するだけでなく、カスタマイズすることで、より実用的なカレンダーを実装可能です。</p>



<p>スケジュール管理やイベント一覧を手軽に追加したい方は、ぜひ試してみてください！</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.takeho.com/how-to-easily-implement-fullcalendar-in-yii2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
