Source for file ViewClass.php
Documentation is available at ViewClass.php
// vim: foldmethod=marker
* @author Masaki Fujimoto <fujimoto@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @version $Id: 4188accafabceee2638da3820d394bb0a50a45df $
* @author Masaki Fujimoto <fujimoto@php.net>
/** @protected object Ethna_Controller Controllerオブジェクト */
/** @protected object Ethna_Backend backendオブジェクト */
/** @protected object Ethna_Config 設定オブジェクト */
/** @protected object Ethna_I18N i18nオブジェクト */
/** @protected object Ethna_Logger ログオブジェクト */
/** @protected object Ethna_Plugin プラグインオブジェクト */
/** @protected object Ethna_ActionError アクションエラーオブジェクト */
/** @protected object Ethna_ActionError アクションエラーオブジェクト(省略形) */
/** @protected object Ethna_ActionForm アクションフォームオブジェクト */
/** @protected object Ethna_ActionForm アクションフォームオブジェクト(省略形) */
/** @protected array アクションフォームオブジェクト(helper) */
/** @protected array helperでhtmlのattributeにはしないパラメータの一覧 */
/** @protected object Ethna_Session セッションオブジェクト */
/** @protected string 遷移名 */
/** @protected string 遷移先テンプレートファイル名 */
/** @protected boolean 配列フォームを呼んだカウンタをリセットするか否か */
/** @var string レイアウト(HTMLの外枠を記述するファイル)のテンプレートファイルを指定(拡張子は除く) */
/** @var boolean レイアウトテンプレートの使用フラグ */
/** @var boolean デフォルトのヘッダ出力を使用するか否か */
/** ヘッダ出力を改造する場合はfalseにする */
/** @var array default header */
'Cache-Control' =>
'no-cache, no-store, must-revalidate',
* Ethna_ViewClassのコンストラクタ
* @param object Ethna_Backend $backend backendオブジェクト
* @param string $forward_name ビューに関連付けられている遷移名
* @param string $forward_path ビューに関連付けられているテンプレートファイル名
public function __construct($backend, $forward_name, $forward_path)
$c =
$backend->getController();
* テンプレートに設定する値でコンテキストに依存しないものは
* @param mixed $params アクションクラスから返された引数
* array('forward_name', $param) の形でアクション
* から値を返すことで、$params に値が渡されます。
* 特殊な画面を表示する場合を除いて特にオーバーライドする必要は無い
* (preforward()のみオーバーライドすれば良い)
$this->default_header['Content-Type'] =
'text/html; charset=' .
$this->ctl->getClientEncoding();
// check : layout file existance
$renderer->setProp('content', $content);
if (isset
($_SERVER['REQUEST_URI'])) {
$uri_hash =
md5($_SERVER['REQUEST_URI']);
$e =
$renderer->perform($layout, $uri_hash);
$e =
$renderer->perform($layout);
echo
'<h1>Rendering error:</h1>';
echo
'<h2>Message: ' .
$e->getMessage() .
'</h2>';
* 配列指定の場合、header => value の形式
* 文字列で指定する場合は、ヘッダ出力をそのまま指定
public function header($status)
foreach ($status as $key =>
$status) {
header ($key .
": " .
$status);
101 =>
"Switching Protocols",
203 =>
"Non-Authoritative Information",
206 =>
"Partial Content",
300 =>
"Multiple Choices",
301 =>
"Moved Permanently",
307 =>
"Temporary Redirect",
402 =>
"Payment Required",
405 =>
"Method Not Allowed",
407 =>
"Proxy Authentication Required",
408 =>
"Request Time-out",
411 =>
"Length Required",
412 =>
"Precondition Failed",
413 =>
"Request Entity Too Large",
414 =>
"Request-URI Too Large",
415 =>
"Unsupported Media Type",
416 =>
"Requested range not satisfiable",
417 =>
"Expectation Failed",
500 =>
"Internal Server Error",
501 =>
"Not Implemented",
503 =>
"Service Unavailable",
504 =>
"Gateway Time-out"
header("HTTP/1.1: {$status} {$codes[$status]}");
* @param string リダイレクト先(URL)
* @param int HTTPステータスコード (3xx)
public function redirect($url, $staus_code =
302)
$this->header(array('Location' =>
$url));
* レイアウトテンプレートのファイル名を設定します。
* レイアウトテンプレートは、HTML の外枠を設定するのに使用します。
* @param string $filename レイアウトファイル名
// check layout file existance
* レイアウトテンプレートファイル名を取得します。
* @return string レイアウトテンプレートのファイル名
// {{{ getCurrentForwardName()
* テンプレートファイルが存在するか否かを返します。
* @param string $filename チェック対象のテンプレートファイル
* @return boolean 指定したテンプレートファイルが存在すればtrue
if ($renderer->templateExists($filename)) {
* エラーページ出力用のHTTPステータスコードを指定します。
* @param int HTTPステータスコード
public function error($code)
// template 以下に error404.tpl とかがあれば,
// preforward で $this->error(404); とかすればいい
// {{{ addActionFormHelper
* helperアクションフォームオブジェクトを設定する
* @param string $action アクション名
* @param boolean $dynamic_helper 動的フォームヘルパを呼ぶか否か
if ($action ===
$ctl->getCurrentActionName()) {
$form_name =
$ctl->getActionFormName($action);
if ($form_name ===
null) {
$this->logger->log(LOG_WARNING,
'action form for the action [%s] not found.', $action);
// 動的フォームを設定するためのヘルパメソッドを呼ぶ
$af->setFormDef_ViewHelper();
// {{{ clearActionFormHelper
* helperアクションフォームオブジェクトを削除する
// {{{ _getHelperActionForm
* アクションフォームオブジェクト(helper)を取得する
* $action === null で $name が指定されているときは、$nameの定義を
* @param string action 取得するアクション名
* @param string name 定義されていることを期待するフォーム名
* @return object Ethna_ActionFormまたは継承オブジェクト
$this->logger->log(LOG_WARNING,
'helper action form for action [%s] not found',
$def =
$this->af->getDef($name);
// $this->helper_action_form を順に調べる
$def =
$af->getDef($name);
$this->logger->log(LOG_WARNING,
'action form defining form [%s] not found', $name);
* フォームヘルパ用、内部フォームカウンタをリセットする
* 指定されたフォーム項目に対応するフォーム名(w/ レンダリング)を取得する
$def =
$af->getDef($name);
if ($def ===
null || isset
($def['name']) ===
false) {
* submitボタンを取得する(送信先アクションで受け取るよう
* 定義されていないときに、たんにsubmitボタンを作るのに使う)
if (isset
($params['type']) ===
false) {
$params['type'] =
'submit';
* 指定されたフォーム項目に対応するフォームタグを取得する
$def =
$af->getDef($name);
if (isset
($def['form_type']) ===
false) {
// 配列フォームが何回呼ばれたかを保存するカウンタ
if (isset
($def['type']) &&
is_array($def['type'])) {
static $form_counter =
array();
if ($this->reset_counter) {
$this->reset_counter =
false;
if (isset
($form_counter[$action]) ===
false) {
$form_counter[$action] =
array();
if (isset
($form_counter[$action][$name]) ===
false) {
$form_counter[$action][$name] =
0;
$def['_form_counter'] =
$form_counter[$action][$name]++
;
switch ($def['form_type']) {
$input =
$this->_getFormInput_Button($name, $def, $params);
* フォームタグを取得する(type="form")
if (isset
($params['method']) ===
false) {
$params['method'] =
'post';
// {{{ _getSelectorOptions
* select, radio, checkbox の選択肢を取得する
if (isset
($params['option'])) {
$source =
$params['option'];
} else if (isset
($def['option'])) {
$source =
$def['option'];
if (count($split) ===
1) {
$method_or_property =
$split[0];
$options =
$af->$method_or_property();
$options =
$af->$method_or_property;
$mgr =
$this->backend->getManager($split[0]);
$attr_list =
$mgr->getAttrList($split[1]);
foreach ($attr_list as $key =>
$val) {
$options[$key] =
$val['name'];
$this->logger->log(LOG_WARNING,
'selector option is not valid. [actionform=%s, option=%s]',
// {{{ _getFormInput_Button
* フォームタグを取得する(type="button")
$params['type'] =
'button';
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($params['value']) ===
false) {
if (isset
($def['name'])) {
$params['value'] =
$def['name'];
if (isset
($params['value']) &&
is_array($params['value'])) {
$params['value'] =
$params['value'][0];
// {{{ _getFormInput_Checkbox
* チェックボックスタグを取得する(type="check")
$params['type'] =
'checkbox';
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($def['option']) &&
is_array($def['option'])) {
$options =
$def['option'];
if (isset
($params['default'])) {
$current_value =
$params['default'];
} else if (isset
($def['default'])) {
$current_value =
$def['default'];
$current_value =
array();
if (isset
($params['separator'])) {
$separator =
$params['separator'];
foreach ($options as $key =>
$value) {
$params['id'] =
$name .
'_' .
$i++
;
if (in_array((string)
$key, $current_value, true)) {
$params['checked'] =
'checked';
unset
($params['checked']);
// <input type="checkbox" />
// <label for="id">..</label>
$input_tag .
$value, false);
// {{{ _getFormInput_File
* フォームタグを取得する(type="file")
$params['type'] =
'file';
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
// {{{ _getFormInput_Hidden
* フォームタグを取得する(type="hidden")
$params['type'] =
'hidden';
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($params['value'])) {
$value =
$params['value'];
} else if (isset
($params['default'])) {
$value =
$params['default'];
} else if (isset
($def['default'])) {
$value =
$def['default'];
if ($def['_form_counter'] <
count($value)) {
$params['value'] =
$value[$def['_form_counter']];
$params['value'] =
$value;
// {{{ _getFormInput_Password
* フォームタグを取得する(type="password")
$params['type'] =
'password';
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($params['value'])) {
$value =
$params['value'];
} else if (isset
($params['default'])) {
$value =
$params['default'];
} else if (isset
($def['default'])) {
$value =
$def['default'];
if ($def['_form_counter'] <
count($value)) {
$params['value'] =
$value[$def['_form_counter']];
$params['value'] =
$value;
// maxlength と フォーム定義のmax連携はサポートしない
// @see http://sourceforge.jp/ticket/browse.php?group_id=1343&tid=16325
// {{{ _getFormInput_Radio
* ラジオボタンタグを取得する(type="radio")
$params['type'] =
'radio';
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($def['option']) &&
is_array($def['option'])) {
$options =
$def['option'];
if (isset
($params['default'])) {
$current_value =
$params['default'];
} else if (isset
($def['default'])) {
$current_value =
$def['default'];
if (isset
($params['separator'])) {
$separator =
$params['separator'];
foreach ($options as $key =>
$value) {
$params['id'] =
$name .
'_' .
$i++
;
if (strcmp($current_value,$key) ===
0) {
$params['checked'] =
'checked';
unset
($params['checked']);
// <input type="radio" />
// <label for="id">..</label>
$input_tag .
$value, false);
// {{{ _getFormInput_Select
* セレクトボックスタグを取得する(type="select")
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($def['option']) &&
is_array($def['option'])) {
$options =
$def['option'];
if (isset
($params['default'])) {
$current_value =
$params['default'];
} else if (isset
($def['default'])) {
$current_value =
$def['default'];
$current_value =
array(0 =>
0,);
if (isset
($params['separator'])) {
$separator =
$params['separator'];
foreach ($options as $key =>
$value) {
$attr =
array('value' =>
$key);
$def['_form_counter'] =
empty($def['_form_counter']) ?
0 :
$def['_form_counter'];
if (isset
($params['multiple']) &&
in_array((string)
$key, $current_value, true) ||
!isset
($params['multiple']) &&
$selected ===
false &&
strcmp($current_value[$def['_form_counter']], $key) ===
0) {
$attr['selected'] =
'selected';
if (isset
($params['emptyoption'])) {
$attr =
array('value' =>
'');
if ($selected ===
false) {
$attr['selected'] =
'selected';
$params['emptyoption']));
unset
($params['emptyoption']);
$element =
$separator .
implode($separator, $contents) .
$separator;
// {{{ _getFormInput_Submit
* フォームタグを取得する(type="submit")
$params['type'] =
'submit';
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($params['value']) ===
false) {
if (isset
($def['name'])) {
$params['value'] =
$def['name'];
$params['value'] =
$params['value'][0];
// {{{ _getFormInput_Textarea
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($params['value'])) {
$element =
$params['value'];
} else if (isset
($params['default'])) {
$element =
$params['default'];
} else if (isset
($def['default'])) {
$element =
$def['default'];
if ($def['_form_counter'] <
count($element)) {
$element =
$element[$def['_form_counter']];
// {{{ _getFormInput_Text
* フォームタグを取得する(type="text")
$params['type'] =
'text';
if (isset
($def['type'])) {
$params['name'] =
is_array($def['type']) ?
$name .
'[]' :
$name;
if (isset
($params['value'])) {
$value =
$params['value'];
} else if (isset
($params['default'])) {
$value =
$params['default'];
} else if (isset
($def['default'])) {
$value =
$def['default'];
if ($def['_form_counter'] <
count($value)) {
$params['value'] =
$value[$def['_form_counter']];
$params['value'] =
$value;
// maxlength と フォーム定義のmax連携はサポートしない
// @see http://sourceforge.jp/ticket/browse.php?group_id=1343&tid=16325
// {{{ _getFormInput_Html
foreach ($attr as $key =>
$value) {
} else if ($escape_element) {
$r .=
sprintf('>%s</%s>', $element, $tag);
* @return object Ethna_Renderer レンダラオブジェクト
$c =
$this->backend->getController();
$renderer =
$c->getRenderer();
$form_array =
$this->af->getArray();
$app_array =
$this->af->getAppArray();
$app_ne_array =
$this->af->getAppNEArray();
$renderer->setPropByRef('form', $form_array);
$renderer->setPropByRef('app', $app_array);
$renderer->setPropByRef('app_ne', $app_ne_array);
$renderer->setPropByRef('errors', $message_list);
$renderer->setPropByRef('session', $tmp_session);
$renderer->setProp('script',
$renderer->setProp('request_uri',
isset
($_SERVER['REQUEST_URI'])
$renderer->setProp('config', $this->config->get());
* @param object Ethna_Renderer レンダラオブジェクト
Documentation generated on Fri, 11 Nov 2011 03:59:25 +0900 by phpDocumentor 1.4.3