OSDN Git Service

- newly implemented Ethna_View_Json.php
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Sat, 11 Apr 2009 06:18:04 +0000 (06:18 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Sat, 11 Apr 2009 06:18:04 +0000 (06:18 +0000)
- parameter passing enabled from Ethna_ActionClass to Ethna_ViewClass

Idea_Extended_ViewClass/Ethna.php
Idea_Extended_ViewClass/class/Ethna_Controller.php
Idea_Extended_ViewClass/class/Ethna_ViewClass.php
Idea_Extended_ViewClass/class/View/Ethna_View_Json.php [new file with mode: 0644]

index a078ad8..2e1c516 100644 (file)
@@ -80,6 +80,7 @@ require_once ETHNA_BASE . '/class/Ethna_Generator.php';
 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';
index 7f32a64..a6cca56 100644 (file)
@@ -986,12 +986,22 @@ class Ethna_Controller
         }
 
         // コントローラで遷移先を決定する(オプション)
-        $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();
         }
 
index b6970f0..5bfa65c 100644 (file)
@@ -117,8 +117,11 @@ class Ethna_ViewClass
      *  ここで設定する(例:セレクトボックス等)
      *
      *  @access public
+     *  @param  mixed  $params  アクションクラスから返された引数 
+     *                          array('forward_name', $param) の形でアクション
+     *                          から値を返すことで、$params に値が渡されます。
      */
-    function preforward()
+    function preforward($params = NULL)
     {
     }
     // }}}
diff --git a/Idea_Extended_ViewClass/class/View/Ethna_View_Json.php b/Idea_Extended_ViewClass/class/View/Ethna_View_Json.php
new file mode 100644 (file)
index 0000000..888ba24
--- /dev/null
@@ -0,0 +1,52 @@
+<?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);
+    }
+}
+// }}}
+?>