LoginSignup
0
0

More than 5 years have passed since last update.

symfonyでSSI

Last updated at Posted at 2016-01-15

symfonyの当たっていない静的なhtmlにログイン情報を表示しているヘッダー部など動的に切り替わる部分だけsymfony経由で出力したいってことありませんか?
SSIを利用してヘッダー部をsymfonyで出力すればできます。

その簡単?なやり方を紹介します。
下記のような構成のSymfonyアプリがあるとします。


- symfony_root/
 - web/
  - index.php ← ※1
 - apps/
  - frontend/
   - modules/
    - ssi/ ← SSI用のモジュール
     - actions/
      - actions.class.php ← executeHeader()が宣言されている

※1をコピペしてSSI用のphpファイルを作成し、修正します。


- htdocs/
 - ssi/
  - header.php
header.php
<?php
$_SERVER['REQUEST_URI'] = 'ssi/header';  //指定したモジュールおよびアクションを呼ばせるため
require_once(dirname(__FILE__).'/../../symfony_root/config/ProjectConfiguration.class.php'); //パスを調整
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
sfContext::createInstance($configuration)->dispatch();

.htaccessかhttpd.confにSSI設定

htdocs/.htaccess
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml

SSIを使ったhtmlの例

htdocs/index.shtml
<html>
<head>
  <title>SSIサンプル</title>
</head>
<body>
<!--#include virtual="/ssi/header.php" -->

  これはSSIサンプルです。

</body>
<html>
0
0
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
0
0