3
2

More than 5 years have passed since last update.

Composerの概要、Composerを使うまでの手順

Posted at

概要

インストール方法

前提

  • PHP 5.3.2+以上(Composerは頻繁にアップデートされているそうなので要チェック)
  • Composerを使うためのphp.iniの設定
    • extension=php_openssl.dllのコメントを外して有効化する

手順

使い方

インストール後はphp composer.phar installの代わりにcomposer installで使えるようになる

例えばTwigを使う

コマンドcomposer require twig/twig:1.*
composer.jsonファイルがなければ勝手に作られる

コマンドの実行結果

daichi>composer require twig/twig:1.*
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing twig/twig (v1.15.0)
    Downloading: 100%

Writing lock file
Generating autoload files

test.phpを作成する

<?php
require 'vendor/autoload.php';

$loader = new Twig_Loader_String();
$twig = new Twig_Environment($loader);

echo $twig->render('Hello {{ name }}!', array('name' => 'Fabien'));

実行結果
Hello Fabien!

3
2
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
3
2