Help us understand the problem. What is going on with this article?

SmartyをComposerでインストールする

More than 5 years have passed since last update.

開発速度が心配されるSmartyですが、密かにComposerでセットアップする事ができる。展開したファイルからlibをコピーしてrequireという手順は実は必要なかった。
通常どおりcomposer.jsonを記述してcomposer installでセットアップされる。

composer.json
{
 "require": {
   "smarty/smarty": "dev-trunk"
 }
}

あとはComposerコマンドを起動する事で自動的にライブラリのセットアップを行う。

結果
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install
$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing smarty/smarty (dev-trunk)
    Checking out /trunk/@4746
Writing lock file
Generating autoload files

$ ls -l vendor/
total 4
-rw-r--r-- 1 vagrant vagrant 182 Jun 22 07:53 autoload.php
drwxr-xr-x 1 vagrant vagrant 238 Jun 22 07:53 composer
drwxr-xr-x 1 vagrant vagrant 102 Jun 22 07:50 smarty

これでSmartyクラスをオートロードして利用する事ができる。

index.php
<?php
require './vendor/autoload.php';
$smarty = new Smarty();
$smarty->display('hoge.tpl');
templates/hoge.tpl
This is rendered by {$smarty.version}

実行してみると無事にテンプレートがレンダリングされた。

This is rendered by Smarty-3.1-DEV

Smartyをまだ使っているにせよ、レガシーなrequireを一つ減らす事ができるのでComposerでインストールする事が望ましい。

参考
https://packagist.org/packages/smarty/smarty

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away