LoginSignup
14
12

More than 5 years have passed since last update.

CakePHP3のインストールおよびSmarty3の導入

Last updated at Posted at 2016-03-13

:smile: 2016/03/13時点における最新版を前提としています。
:smile: 本記事は、前記事にCakePHP3のインストール方法、およびサンプルを加筆したものです。
前記事はこちら:http://qiita.com/yukikikuchi/items/f64182288a6e23087c12


CakePHP3のインストール

方法1:zipファイルでダウンロード

php.iniに下記を追記(かなり重要)

php.ini
# Windowsの場合
extension=php_intl.dll

CakePHP3をダウンロード
https://github.com/cakephp/cakephp/tags
Downloadsリンクをクリックし、
画面下のcakephp-3-x-x.zipを選択。
WS010037.JPG

WS010038.JPG

任意のフォルダに展開
WS010029.JPG

方法2:Composerでダウンロード

php.iniに下記を追記(かなり重要)

php.ini
# Windowsの場合
extension=php_intl.dll
extension=php_openssl.dll

Composerダウンロード&インストール
https://getcomposer.org/

任意のフォルダ上で実行
composer create-project --prefer-dist cakephp/app ./

Apacheにドキュメントルートを設定

:smile: これでとりあえず動くようになりました。
:smile: ここからSmarty3を導入しましょう。

SmartyViewクラスをダウンロード

https://github.com/yukikikuchi/cakephp3-smartyview
をダウンロード

Smarty本体の設置

Smarty本家サイト
http://www.smarty.net/
からstableをとってくる
2016/03/13現在の最新版は3.1.29です。

app/vendor/smarty
にlib配下のファイルを配置

SmartyViewを使用できるようにする

app/src/View/
にSmartyView.php
を配置

AppControllerを修正

AppController.php
class AppController extends Controller {
    public $viewClass = 'App\View\SmartyView';
// 中略
}

レイアウトの修正

src/Template/Layout/default.tplを作成

default.tpl
{$this->fetch('content')}

:smile: これでSmarty3が有効になりました。
:smile: ここからはオマケです。サンプルを作ってみましょう。

画面を作ってみる

コントローラーを作成

src/Controller/SamplesController.php

<?php
namespace App\Controller;

class SamplesController extends AppController
{

    public function page()
    {
        $this->set('hoge', '変数の値');
    }
}

ビューを作成

src/Template/sample.tpl
This is tpl.<br>
smarty tag:{$smarty.now}<br>
hoge:{$hoge}<br>
escape:{'<>'|escape}<br>
helper:{$this->Html->link('tttt')}<br>

アクセス!
http://[ドメイン]/samples/page

:smile: いかがでしょうか。
:smile: お役に立てたら嬉しいです!

14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12