<?php
interface Zend_Controller_Action_Interface
{
/**
* Class constructor
*
* The request and response objects should be registered with the
* controller, as should be any additional optional arguments; these will be
* available via {@link getRequest()}, {@link getResponse()}, and
* {@link getInvokeArgs()}, respectively.
*
* When overriding the constructor, please consider this usage as a best
* practice and ensure that each is registered appropriately; the easiest
* way to do so is to simply call parent::__construct($request, $response,
* $invokeArgs).
*
* After the request, response, and invokeArgs are set, the
* {@link $_helper helper broker} is initialized.
*
* Finally, {@link init()} is called as the final action of
* instantiation, and may be safely overridden to perform initialization
* tasks; as a general rule, override {@link init()} instead of the
* constructor to customize an action controller's instantiation.
*
* @param Zend_Controller_Request_Abstract $request
* @param Zend_Controller_Response_Abstract $response
* @param array $invokeArgs Any additional invocation arguments
* @return void
*/
public function __construct(Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response,
array $invokeArgs = array());
/**
* Dispatch the requested action
*
* @param string $action Method name of action
* @return void
*/
public function dispatch($action);
}
<?php
require_once 'Zend/Controller/Action/HelperBroker.php';
require_once 'Zend/Controller/Action/Interface.php';
require_once 'Zend/Controller/Front.php';
abstract class Zend_Controller_Action implements Zend_Controller_Action_Interface
{
protected $_classMethods;
protected $_delimiters;
protected $_invokeArgs = array();
protected $_frontController;
protected $_request = null;
protected $_response = null;
public $viewSuffix = 'phtml';
public $view;
protected $_helper = null;
public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
{
$this->setRequest($request)
->setResponse($response)
->_setInvokeArgs($invokeArgs);
$this->_helper = new Zend_Controller_Action_HelperBroker($this);
$this->init();
}
public function init()
{
}
public function initView()
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
return $this->view;
}
require_once 'Zend/View/Interface.php';
if (isset($this->view) && ($this->view instanceof Zend_View_Interface)) {
return $this->view;
}
$request = $this->getRequest();
$module = $request->getModuleName();
$dirs = $this->getFrontController()->getControllerDirectory();
if (empty($module) || !isset($dirs[$module])) {
$module = $this->getFrontController()->getDispatcher()->getDefaultModule();
}
$baseDir = dirname($dirs[$module]) . DIRECTORY_SEPARATOR . 'views';
if (!file_exists($baseDir) || !is_dir($baseDir)) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Missing base view directory ("' . $baseDir . '")');
}
require_once 'Zend/View.php';
$this->view = new Zend_View(array('basePath' => $baseDir));
return $this->view;
}
public function render($action = null, $name = null, $noController = false)
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
return $this->_helper->viewRenderer->render($action, $name, $noController);
}
$view = $this->initView();
$script = $this->getViewScript($action, $noController);
$this->getResponse()->appendBody(
$view->render($script),
$name
);
}
public function renderScript($script, $name = null)
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
return $this->_helper->viewRenderer->renderScript($script, $name);
}
$view = $this->initView();
$this->getResponse()->appendBody(
$view->render($script),
$name
);
}
public function getViewScript($action = null, $noController = null)
{
if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {
$viewRenderer = $this->_helper->getHelper('viewRenderer');
if (null !== $noController) {
$viewRenderer->setNoController($noController);
}
return $viewRenderer->getViewScript($action);
}
$request = $this->getRequest();
if (null === $action) {
$action = $request->getActionName();
} elseif (!is_string($action)) {
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Invalid action specifier for view render');
}
if (null === $this->_delimiters) {
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
$wordDelimiters = $dispatcher->getWordDelimiter();
$pathDelimiters = $dispatcher->getPathDelimiter();
$this->_delimiters = array_unique(array_merge($wordDelimiters, (array) $pathDelimiters));
}
$action = str_replace($this->_delimiters, '-', $action);
$script = $action . '.' . $this->viewSuffix;
if (!$noController) {
$controller = $request->getControllerName();
$controller = str_replace($this->_delimiters, '-', $controller);
$script = $controller . DIRECTORY_SEPARATOR . $script;
}
return $script;
}
public function getRequest()
{
return $this->_request;
}
public function setRequest(Zend_Controller_Request_Abstract $request)
{
$this->_request = $request;
return $this;
}
public function getResponse()
{
return $this->_response;
}
public function setResponse(Zend_Controller_Response_Abstract $response)
{
$this->_response = $response;
return $this;
}
protected function _setInvokeArgs(array $args = array())
{
$this->_invokeArgs = $args;
return $this;
}
public function getInvokeArgs()
{
return $this->_invokeArgs;
}
public function getInvokeArg($key)
{
if (isset($this->_invokeArgs[$key])) {
return $this->_invokeArgs[$key];
}
return null;
}
public function getHelper($helperName)
{
return $this->_helper->{$helperName};
}
public function getHelperCopy($helperName)
{
return clone $this->_helper->{$helperName};
}
public function setFrontController(Zend_Controller_Front $front)
{
$this->_frontController = $front;
return $this;
}
public function getFrontController()
{
// Used cache version if found
if (null !== $this->_frontController) {
return $this->_frontController;
}
// Grab singleton instance, if class has been loaded
if (class_exists('Zend_Controller_Front')) {
$this->_frontController = Zend_Controller_Front::getInstance();
return $this->_frontController;
}
// Throw exception in all other cases
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Exception('Front controller class has not been loaded');
}
public function preDispatch()
{
}
public function postDispatch()
{
}
public function __call($methodName, $args)
{
require_once 'Zend/Controller/Action/Exception.php';
if ('Action' == substr($methodName, -6)) {
$action = substr($methodName, 0, strlen($methodName) - 6);
throw new Zend_Controller_Action_Exception(sprintf('Action "%s" does not exist and was not trapped in __call()', $action), 404);
}
throw new Zend_Controller_Action_Exception(sprintf('Method "%s" does not exist and was not trapped in __call()', $methodName), 500);
}
public function dispatch($action)
{
// Notify helpers of action preDispatch state
$this->_helper->notifyPreDispatch();
$this->preDispatch();
if ($this->getRequest()->isDispatched()) {
if (null === $this->_classMethods) {
$this->_classMethods = get_class_methods($this);
}
// If pre-dispatch hooks introduced a redirect then stop dispatch
// @see ZF-7496
if (!($this->getResponse()->isRedirect())) {
// preDispatch() didn't change the action, so we can continue
if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {
if ($this->getInvokeArg('useCaseSensitiveActions')) {
trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"');
}
$this->$action();
} else {
$this->__call($action, array());
}
}
$this->postDispatch();
}
// whats actually important here is that this action controller is
// shutting down, regardless of dispatching; notify the helpers of this
// state
$this->_helper->notifyPostDispatch();
}
public function run(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
{
if (null !== $request) {
$this->setRequest($request);
} else {
$request = $this->getRequest();
}
if (null !== $response) {
$this->setResponse($response);
}
$action = $request->getActionName();
if (empty($action)) {
$action = 'index';
}
$action = $action . 'Action';
$request->setDispatched(true);
$this->dispatch($action);
return $this->getResponse();
}
protected function _getParam($paramName, $default = null)
{
$value = $this->getRequest()->getParam($paramName);
if ((null === $value || '' === $value) && (null !== $default)) {
$value = $default;
}
return $value;
}
protected function _setParam($paramName, $value)
{
$this->getRequest()->setParam($paramName, $value);
return $this;
}
protected function _hasParam($paramName)
{
return null !== $this->getRequest()->getParam($paramName);
}
protected function _getAllParams()
{
return $this->getRequest()->getParams();
}
final protected function _forward($action, $controller = null, $module = null, array $params = null)
{
$request = $this->getRequest();
if (null !== $params) {
$request->setParams($params);
}
if (null !== $controller) {
$request->setControllerName($controller);
// Module should only be reset if controller has been specified
if (null !== $module) {
$request->setModuleName($module);
}
}
$request->setActionName($action)
->setDispatched(false);
}
protected function _redirect($url, array $options = array())
{
$this->_helper->redirector->gotoUrl($url, $options);
}
}
// 只是局部控制器;当初始化加载时,对这个控制器的所有动作有效:
$this->_helper->viewRenderer->setNoRender(true);
// 全局:
$this->_helper->removeHelper('viewRenderer');
// 也是全局,但需要和本地版本协作,以便繁殖这个控制器:
Zend_Controller_Front::getInstance()->setParam('noViewRenderer', true);
class FooController extends Zend_Controller_Action
{
public function barAction()
{
// disable autorendering for this action only:
$this->_helper->viewRenderer->setNoRender();
}
}
$this->getResponse()->setHeader('Content-Type', 'text/xml');
$this->getResponse()->appendBody($content);
// Use default value of 1 if id is not set
$id = $this->_getParam('id', 1);
// Instead of:
if ($this->_hasParam('id') {
$id = $this->_getParam('id');
} else {
$id = 1;
}
string render(string $action = null,
string $name = null,
bool $noController = false);
class MyController extends Zend_Controller_Action
{
public function fooAction()
{
// Renders my/foo.phtml
$this->render();
// Renders my/bar.phtml
$this->render('bar');
// Renders baz.phtml
$this->render('baz', null, true);
// Renders my/login.phtml to the 'form' segment of the
// response object
$this->render('login', 'form');
// Renders site.phtml to the 'page' segment of the response
// object; does not use the 'my/' subirectory
$this->render('site', 'page', true);
}
public function bazBatAction()
{
// Renders my/baz-bat.phtml
$this->render();
}
}
class MyController extends Zend_Controller_Action
{
public function __call($method, $args)
{
if ('Action' == substr($method, -6)) {
// If the action method was not found, render the error
// template
return $this->render('error');
}
// all other methods throw an exception
throw new Exception('Invalid method "'
. $method
. '" called',
500);
}
}
class MyController extends Zend_Controller_Action
{
public function indexAction()
{
$this->render();
}
public function __call($method, $args)
{
if ('Action' == substr($method, -6)) {
// If the action method was not found, forward to the
// index action
return $this->_forward('index');
}
// all other methods throw an exception
throw new Exception('Invalid method "'
. $method
. '" called',
500);
}
}
abstract class My_Base_Controller extends Zend_Controller_Action
{
public function initView()
{
if (null === $this->view) {
if (Zend_Registry::isRegistered('view')) {
$this->view = Zend_Registry::get('view');
} else {
$this->view = new Zend_View();
$this->view->setBasePath(dirname(__FILE__) . '/../views');
}
}
return $this->view;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有