PHP - smarty2 から smarty3 へ - 最低限必要なこと
- 1. ライブラリの場所
- 2. コンストラクタ
1. ライブラリの場所
サーバによって「smarty」が展開される場所が異なるかと思います。
これは「FreeBSD 11.1」でのお話し。
サーバ側で /usr/local/etc/php.ini にパスを通しておけばいいっていうか本来そうしておかないといけないのですが。
require_once('/usr/local/share/smarty/Smarty.class.php');
と書いてあれば
require_once('/usr/local/share/smarty3-php56/Smarty.class.php');
こうなる・・・。っちゅうか、サーバでちゃんとパスを通して
require_once('Smarty.class.php');
が正解ですわな。
サーバで
vi /usr/local/etc/php.ini
で編集して
include_path = ".:/usr/local/share/smarty3-php52:その他のパス"
と書きます。これは、「php52」の話で、2019年9月23日時点で、「php72」を使っておりますので、現在は
include_path = ".:/usr/local/share/smarty3-php72:その他のパス"
となっております。
2. コンストラクタ
自前で、「Smarty」の派生クラスを作成している場合は
<?php
require_once('Smarty.class.php');
class MySmarty extends Smarty
{
public function __construct ()
{
テンプレートディレクトリの定義など・・・
}
public function __destruct ()
{
}
}
?>
以下の8行目の記述をしないとわけわかんないエラーが出ます。
<?php
require_once('Smarty.class.php');
class MySmarty extends Smarty
{
public function __construct ()
{
parent::__construct();
テンプレートディレクトリの定義など・・・
}
public function __destruct ()
{
}
}
?>
わたしの環境では以下のようなエラーメッセージ(apache)になっていました。
PHP Fatal error: Call to a member function create() on null in /usr/local/share/smarty3-php56/sysplugins/smarty_internal_templatecompilerbase.php on line 334
|
|