Browse Source

...

tags/2.0.0-beta
Qiang Xue 13 years ago
parent
commit
5cd9ddc6cc
  1. 64
      framework/base/Controller.php
  2. 58
      framework/base/ErrorHandler.php

64
framework/base/Controller.php

@ -10,55 +10,19 @@
namespace yii\base;
/**
* Controller is the base class for {@link CController} and {@link CWidget}.
* Controller is the base class for classes containing controller logic.
*
* It provides the common functionalities shared by controllers who need to render views.
* Controller implements the action life cycles, which consist of the following steps:
*
* Controller also implements the support for the following features:
* <ul>
* <li>{@link CClipWidget Clips} : a clip is a piece of captured output that can be inserted elsewhere.</li>
* <li>{@link CWidget Widgets} : a widget is a self-contained sub-controller with its own view and model.</li>
* <li>{@link COutputCache Fragment cache} : fragment cache selectively caches a portion of the output.</li>
* </ul>
* 1. [[authorize]]
* 2. [[beforeAction]]
* 3. [[beforeRender]]
* 4. [[afterRender]]
* 5. [[afterAction]]
*
* To use a widget in a view, use the following in the view:
* <pre>
* $this->widget('path.to.widgetClass',array('property1'=>'value1',...));
* </pre>
* or
* <pre>
* $this->beginWidget('path.to.widgetClass',array('property1'=>'value1',...));
* // ... display other contents here
* $this->endWidget();
* </pre>
*
* To create a clip, use the following:
* <pre>
* $this->beginClip('clipID');
* // ... display the clip contents
* $this->endClip();
* </pre>
* Then, in a different view or place, the captured clip can be inserted as:
* <pre>
* echo $this->clips['clipID'];
* </pre>
*
* Note that $this in the code above refers to current controller so, for example,
* if you need to access clip from a widget where $this refers to widget itself
* you need to do it the following way:
*
* <pre>
* echo $this->getController()->clips['clipID'];
* </pre>
*
* To use fragment cache, do as follows,
* <pre>
* if($this->beginCache('cacheID',array('property1'=>'value1',...))
* {
* // ... display the content to be cached here
* $this->endCache();
* }
* </pre>
* @property array $actionParams the request parameters (name-value pairs) to be used for action parameter binding
* @property string $route the route (module ID, controller ID and action ID) of the current request.
* @property string $uniqueId the controller ID that is prefixed with the module ID (if any).
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
@ -94,7 +58,7 @@ abstract class Controller extends Component implements Initable
/**
* Initializes the controller.
* This method is called by the application before the controller starts to execute.
* This method is called by the application before the controller starts to execute an action.
* You may override this method to perform the needed initialization for the controller.
*/
public function init()
@ -256,11 +220,9 @@ abstract class Controller extends Component implements Initable
/**
* Processes the request using another controller action.
* This is like {@link redirect}, but the user browser's URL remains unchanged.
* In most cases, you should call {@link redirect} instead of this method.
* @param string $route the route of the new controller action. This can be an action ID, or a complete route
* with module ID (optional in the current module), controller ID and action ID. If the former, the action is assumed
* to be located within the current controller.
* with module ID (optional in the current module), controller ID and action ID. If the former,
* the action is assumed to be located within the current controller.
* @param boolean $exit whether to end the application after this call. Defaults to true.
*/
public function forward($route, $exit = true)

58
framework/base/ErrorHandler.php

@ -15,47 +15,6 @@ namespace yii\base;
* ErrorHandler displays these errors using appropriate views based on the
* nature of the errors and the mode the application runs at.
*
* ErrorHandler does the following when the application encounters an error or exception:
*
* - If it is a PHP error, warning or notice, an ErrorException will be thrown which
* if not caught, will be handled in the next few steps
* - If it is an uncaught exception, it will invoke the action defined by [[errorAction]]
* to handle the exception;
* - If [[errorAction]] is not defined, it will
*
* ErrorHandler uses two sets of views:
* <ul>
* <li>development views, named as <code>exception.php</code>;
* <li>production views, named as <code>error&lt;StatusCode&gt;.php</code>;
* </ul>
* where &lt;StatusCode&gt; stands for the HTTP error code (e.g. error500.php).
* Localized views are named similarly but located under a subdirectory
* whose name is the language code (e.g. zh_cn/error500.php).
*
* Development views are displayed when the application is in debug mode
* (i.e. YII_DEBUG is defined as true). Detailed error information with source code
* are displayed in these views. Production views are meant to be shown
* to end-users and are used when the application is in production mode.
* For security reasons, they only display the error message without any
* sensitive information.
*
* ErrorHandler looks for the view templates from the following locations in order:
* <ol>
* <li><code>themes/ThemeName/views/system</code>: when a theme is active.</li>
* <li><code>protected/views/system</code></li>
* <li><code>framework/views</code></li>
* </ol>
* If the view is not found in a directory, it will be looked for in the next directory.
*
* The property {@link maxSourceLines} can be changed to specify the number
* of source code lines to be displayed in development views.
*
* ErrorHandler is a core application component that can be accessed via
* {@link CApplication::getErrorHandler()}.
*
* @property array $error The error details. Null if there is no error.
* @property string $versionInfo
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
@ -79,8 +38,13 @@ class ErrorHandler extends ApplicationComponent
* This property defaults to null, meaning ErrorHandler will handle the error display.
*/
public $errorAction;
/**
* @var string the path of the view file for rendering exceptions
*/
public $exceptionView = '@yii/views/exception.php';
/**
* @var string the path of the view file for rendering errors
*/
public $errorView = '@yii/views/error.php';
/**
* @var \Exception the exception that is being handled currently
@ -96,19 +60,13 @@ class ErrorHandler extends ApplicationComponent
/**
* Handles PHP execution errors such as warnings, notices.
*
* This method is used as a PHP error handler. It requires
* that constant YII_ENABLE_ERROR_HANDLER be defined true.
*
* This method will first raise an `error` event.
* If the error is not handled by any event handler, it will call
* {@link getErrorHandler errorHandler} to process the error.
*
* The application will be terminated by this method.
* This method is used as a PHP error handler. It will simply raise an `ErrorException`.
*
* @param integer $code the level of the error raised
* @param string $message the error message
* @param string $file the filename that the error was raised in
* @param integer $line the line number the error was raised at
* @throws \ErrorException the error exception
*/
public function handleError($code, $message, $file, $line)
{

Loading…
Cancel
Save