Action.php

浏览该文件的文档。
00001 <?php
00003 // FleaPHP Framework
00004 //
00005 // Copyright (c) 2005 - 2007 FleaPHP.org (www.fleaphp.org)
00006 //
00007 // 许可协议,请查看源代码中附带的 LICENSE.txt 文件,
00008 // 或者访问 http://www.fleaphp.org/ 获得详细信息。
00010 
00031 class FLEA_Controller_Action
00032 {
00038     var $_controllerName = null;
00039 
00045     var $_actionName = null;
00046 
00052     var $_dispatcher = null;
00053 
00059     var $components = array();
00060 
00066     var $_renderCallbacks = array();
00067 
00075     function FLEA_Controller_Action($controllerName)
00076     {
00077         $this->_controllerName = $controllerName;
00078 
00079         foreach ((array)$this->components as $componentName) {
00080             $this->{$componentName} =& $this->_getComponent($componentName);
00081         }
00082     }
00083 
00091     function & _getComponent($componentName)
00092     {
00093         static $instances = array();
00094 
00095         if (!isset($instances[$componentName])) {
00096             $componentClassName = FLEA::getAppInf('component.' . $componentName);
00097             FLEA::loadClass($componentClassName);
00098             $instances[$componentName] =& new $componentClassName($this);
00099         }
00100         return $instances[$componentName];
00101     }
00102 
00109     function __setController($controllerName, $actionName)
00110     {
00111         $this->_controllerName = $controllerName;
00112         $this->_actionName = $actionName;
00113     }
00114 
00120     function __setDispatcher(& $dispatcher)
00121     {
00122         $this->_dispatcher =& $dispatcher;
00123     }
00124 
00130     function & _getDispatcher()
00131     {
00132         if (!is_object($this->_dispatcher)) {
00133             $this->_dispatcher =& FLEA::getSingleton(FLEA::getAppInf('dispatcher'));
00134         }
00135         return $this->_dispatcher;
00136     }
00137 
00147     function _url($actionName = null, $args = null, $anchor = null)
00148     {
00149         return url($this->_controllerName, $actionName, $args, $anchor);
00150     }
00151 
00158     function _forward($controllerName = null, $actionName = null)
00159     {
00160         $this->_dispatcher->setControllerName($controllerName);
00161         $this->_dispatcher->setActionName($actionName);
00162         $this->_dispatcher->dispatching();
00163     }
00164 
00170     function & _getView()
00171     {
00172         $viewClass = FLEA::getAppInf('view');
00173         if ($viewClass != 'PHP') {
00174             return FLEA::getSingleton($viewClass);
00175         } else {
00176             $view = false;
00177             return $view;
00178         }
00179     }
00180 
00187     function _executeView($__flea_internal_viewName, $data = null)
00188     {
00189         $viewClass = FLEA::getAppInf('view');
00190         if ($viewClass == 'PHP') {
00191             if (strtolower(substr($__flea_internal_viewName, -4)) != '.php') {
00192                 $__flea_internal_viewName .= '.php';
00193             }
00194             $view = null;
00195             foreach ((array)$this->_renderCallbacks as $callback) {
00196                 call_user_func_array($callback, array(& $data, & $view));
00197             }
00198             if (is_array($data)) { extract($data); }
00199             include($__flea_internal_viewName);
00200         } else {
00201             $view =& $this->_getView();
00202             foreach ((array)$this->_renderCallbacks as $callback) {
00203                 call_user_func_array($callback, array(& $data, & $view));
00204             }
00205             if (is_array($data)) { $view->assign($data); }
00206             $view->display($__flea_internal_viewName);
00207         }
00208     }
00209 
00215     function _isPOST()
00216     {
00217         return strtolower($_SERVER['REQUEST_METHOD']) == 'post';
00218     }
00219 
00225     function _isAjax()
00226     {
00227         $r = isset($_SERVER['HTTP_X_REQUESTED_WITH']) ? strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) : '';
00228         return $r == 'xmlhttprequest';
00229     }
00230 
00241     function _registerEvent($controlName, $event, $action, $attribs = null)
00242     {
00243         $ajax =& FLEA::initAjax();
00244         return $ajax->registerEvent($controlName, $event,
00245                 url($this->_controllerName, $action), $attribs);
00246     }
00247 
00253     function _registerRenderCallback($callback)
00254     {
00255         $this->_renderCallbacks[] = $callback;
00256     }
00257 }

Generated at Sat Feb 2 15:18:50 2008 for FleaPHP by  doxygen 1.5.3