require_once ETHNA_BASE . '/class/Ethna_UrlHandler.php';
require_once ETHNA_BASE . '/class/Ethna_Util.php';
require_once ETHNA_BASE . '/class/Ethna_ViewClass.php';
+require_once ETHNA_BASE . '/class/View/Ethna_View_Json.php';
require_once ETHNA_BASE . '/class/View/Ethna_View_List.php';
require_once ETHNA_BASE . '/class/Ethna_Plugin.php';
require_once ETHNA_BASE . '/class/Ethna_Renderer.php';
}
// コントローラで遷移先を決定する(オプション)
- $forward_name = $this->_sortForward($action_name, $forward_name);
+ $forward_name_params = $this->_sortForward($action_name, $forward_name);
+
+ // Viewへの引数があれば取り出す
+ $preforward_params = array();
+ if (is_array($forward_name_params)) {
+ $forward_name = array_shift($forward_name_params);
+ $preforward_params = $forward_name_params;
+ }
+ else {
+ $forward_name = $forward_name_params;
+ }
if ($forward_name != null) {
$view_class_name = $this->getViewClassName($forward_name);
$this->view =& new $view_class_name($backend, $forward_name, $this->_getForwardPath($forward_name));
- $this->view->preforward();
+ call_user_func_array(array($this->view, 'preforward'), $preforward_params);
$this->view->forward();
}
* ここで設定する(例:セレクトボックス等)
*
* @access public
+ * @param mixed $params アクションクラスから返された引数
+ * array('forward_name', $param) の形でアクション
+ * から値を返すことで、$params に値が渡されます。
*/
- function preforward()
+ function preforward($params = NULL)
{
}
// }}}
--- /dev/null
+<?php
+// vim: foldmethod=marker
+/**
+ * Ethna_View_Json.php
+ *
+ * @author Masaki Fujimoto <takaoka@beatcraft.com>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @package Ethna
+ * @version $Id$
+ */
+
+// {{{ Ethna_View_Json
+/**
+ * JSON を出力するビューの実装
+ *
+ * @author Yoshinari Takaoka <takaoka@beatcraft.com>
+ * @access public
+ * @package Ethna
+ */
+class Ethna_View_Json extends Ethna_ViewClass
+{
+ /**#@+
+ * @access private
+ */
+
+ /**#@-*/
+
+ /**
+ * Jsonを出力する
+ *
+ * @access public
+ * @param array $encode_param 出力するJSONにエンコードする値
+ */
+ function preforward($encode_param = array())
+ {
+ $client_enc = $this->ctl->getClientEncoding();
+ if (mb_enabled() && strcasecmp('UTF-8', $client_enc) != 0) {
+ mb_convert_variables('UTF-8', $client_enc, $encode_param);
+ }
+ $encoded_param = json_encode($encode_param);
+
+ header('Content-Type: application/json; charset=UTF-8');
+ echo $encoded_param;
+ }
+
+ function forward()
+ {
+ exit(0);
+ }
+}
+// }}}
+?>