phpの最近のブログ記事

Zend FrameWorkを使用してみる事にしたがテンプレートエンジンはSmartyを使いたい
そこで調べてみると出来るみたい
このサイト参考にチャレンジ開始
http://wadslab.net/2008/03/zend_view_smarty/
・Smartyラッパーの作成
  application/lib/ViewSmarty.phpを作成
  内容は参考サイトより



require_once 'Zend/View/Interface.php';
require_once 'Smarty/Smarty.class.php';

class ViewSmarty implements Zend_View_Interface
{
protected $_smarty;

public function __construct($tmplPath = null, $extraParams = array())
{
$this->_smarty = new Smarty;

if (null !== $tmplPath) {
$this->setScriptPath($tmplPath);
}

foreach ($extraParams as $key => $value) {
$this->_smarty->$key = $value;
}

$this->_smarty->default_modifiers=array('sanitize');
}

public function getEngine()
{
return $this->_smarty;
}

public function setScriptPath($path)
{
if (is_readable($path)) {
$this->_smarty->template_dir = $path;
return;
}

throw new Exception('無効なパスが指定されました:'.$path);
}

public function getScriptPaths()
{
return array($this->_smarty->template_dir);
}

public function setBasePath($path, $prefix = 'Zend_View')
{
return $this->setScriptPath($path);
}

public function addBasePath($path, $prefix = 'Zend_View')
{
return $this->setScriptPath($path);
}

public function __set($key, $val)
{
$this->_smarty->assign($key, $val);
}

public function __get($key)
{
return $this->_smarty->get_template_vars($key);
}

public function __isset($key)
{
return (null !== $this->_smarty->get_template_vars($key));
}

public function __unset($key)
{
$this->_smarty->clear_assign($key);
}

public function assign($spec, $value = null)
{
if (is_array($spec)) {
$this->_smarty->assign($spec);
return;
}

$this->_smarty->assign($spec, $value);
}

public function clearVars()
{
$this->_smarty->clear_all_assign();
}

public function render($name)
{
return $this->_smarty->fetch($name);
}

public function getVars()
{
$vars = $this->_smarty->get_template_vars();
unset($vars["SCRIPT_NAME"]);
return $vars;
}
}




・templates,template_cの作成
  application/templates

  application/template_c




・ViewRendererアクションヘルパーに組み込まずに使用


$this->_helper->viewRenderer->setNoRender(true);
$tmplete_dir = "path";
$opt = array(
 "compile_dir" => "path"
);
$view = new ViewSmarty($tmplete_dir, $opt);
$view->assign("bar", "bar");
$rendered = $view->render('index.tpl');
print $rendered



・ViewSmartyクラスをViewRendererアクションヘルパーに組み込みは以下のエラー理由が分からず断念


Warning: Smarty error: unable to read resource: "index.tpl" in Smarty.class.php on line 1092


Quote!(引用する!) はてなブックマークに追加
前回php-openid-1.2.3を使用しOpenIDプロバイダーを立ち上げました。

php-openidではOpenIDの形式が
http://domain/openid/?user=hamapin

このような形式なので、個人的に
http://domain/openid/hamapin

こうしたいな
と言うことで変更します。

方法としてmod_rewriteを使用し変更したいのですが、php-openidではCGIパラメタとPATH_INFOを兼用しているので、ちょっと僕のmod_rewrite知識ではむずかしいな。
http://domain/openid/?user=hamapin
http://domain/openid/index.php/serve
など


index.phpの変更
CGIパラメタ(user=hamapin)を取得する箇所を、REQUEST_URIから取得するように変更

common.phpの変更
Openid形式作成箇所をhttp://domain/openid/hamapinこの形式で作成するように変更

ちょっと邪道ですが






Quote!(引用する!) はてなブックマークに追加

OpenIDプロバイダーをある理由で立ち上げたいと思っています。
そこでPHP Standalone OpenID Serverを試します。

■ダウンロード

http://www.openidenabled.com/files/php-server/files/PHP-server-1.1.zip
http://openidenabled.com/files/php-openid/packages/php-openid-1.2.3.zip

■必要なも

Smarty
PEAR DB

■インストール

インストール環境
ディレクトリ:/var/www/htdocs/openid
URL:http://domain/openid

解凍
unzip PHP-server-1.1.zip
unzip php-openid-1.2.3.zip

インストール
mv php-openid-123/* /var/www/htdocs/openid
mv PHP-server-1.1/src/* /var/www/htdocs/openid
mv PHP-server-1.1/templates* /var/www/htdocs
chmod 777 /var/www/htdocs/templates_c
mkdir /var/www/htdocs/src
mv /var/www/htdocs/openid/openid/fonts /var/www/htdocs/src

データベースの作成(MySQL)
mysql -u root -p
mysql> create database php_openid_server;
mysql> grant all privileges on php_openid_server.* to openid@localhost identified by "passwd";
mysql> flush privileges;

config.phpの設定
変更部分
define('SMARTY_DIR', 'xxxxxx');
$storage_parameters = array('username' => 'openid',
'password' => '',
'database' => 'php_openid_server',
'hostspec' => 'localhost');

■確認

OpenIDの発行
http://domain/openid/

外部からに認証
https://www.choix.jp/login
にOpenIDでログインする
これを、どう料理するか考えよう!!
Quote!(引用する!) はてなブックマークに追加

プロフィール

Tomoki Kuriki

コツコツやれば良い事あるさ!!

横浜天気

2008年8月: 月別アーカイブ

ウェブページ

アルバム

Twitter

このアーカイブについて

このページには、過去に書かれたブログ記事のうちphpカテゴリに属しているものが含まれています。

前のカテゴリはOCCPです。

次のカテゴリはPostgresです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。