Commit 0f6eda37 by Carsten Brandt

Merge branch 'master' of git.yiisoft.com:yii2

* 'master' of git.yiisoft.com:yii2: moved ConsoleColor. Finished ViewRenderer. ViewRenderer WIP
parents 4726cf32 dcca0bcf
...@@ -359,6 +359,15 @@ class Application extends Module ...@@ -359,6 +359,15 @@ class Application extends Module
} }
/** /**
* Returns the view renderer.
* @return ViewRenderer the view renderer used by this application.
*/
public function getViewRenderer()
{
return $this->getComponent('viewRenderer');
}
/**
* Sets default path aliases. * Sets default path aliases.
*/ */
public function registerDefaultAliases() public function registerDefaultAliases()
......
...@@ -137,13 +137,37 @@ class View extends Component ...@@ -137,13 +137,37 @@ class View extends Component
/** /**
* Renders a view file. * Renders a view file.
* This method will extract the given parameters and include the view file. *
* It captures the output of the included view file and returns it as a string. * If a [[ViewRenderer|view renderer]] is installed, this method will try to use the view renderer
* to render the view file. Otherwise, it will simply include the view file, capture its output
* and return it as a string.
*
* @param string $file the view file.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return string the rendering result
*/
public function renderFile($file, $params = array())
{
$renderer = Yii::$application->getViewRenderer();
if ($renderer !== null) {
return $renderer->render($this, $file, $params);
} else {
return $this->renderPhpFile($file, $params);
}
}
/**
* Renders a view file as a PHP script.
*
* This method treats the view file as a PHP script and includes the file.
* It extracts the given parameters and makes them available in the view file.
* The method captures the output of the included view file and returns it as a string.
*
* @param string $_file_ the view file. * @param string $_file_ the view file.
* @param array $_params_ the parameters (name-value pairs) that will be extracted and made available in the view file. * @param array $_params_ the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return string the rendering result * @return string the rendering result
*/ */
public function renderFile($_file_, $_params_ = array()) public function renderPhpFile($_file_, $_params_ = array())
{ {
ob_start(); ob_start();
ob_implicit_flush(false); ob_implicit_flush(false);
......
<?php
/**
* ViewRenderer class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
/**
* ViewRenderer is the base class for view renderer classes.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
abstract class ViewRenderer extends Component
{
/**
* Renders a view file.
*
* This method is invoked by [[View]] whenever it tries to render a view.
* Child classes must implement this method to render the given view file.
*
* @param View $view the view object used for rendering the file.
* @param string $file the view file.
* @param array $params the parameters to be passed to the view file.
* @return string the rendering result
*/
abstract public function render($view, $file, $params);
}
<?php <?php
/** /**
* View class file. * ConsoleColor class file.
* *
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC * @copyright Copyright &copy; 2008 Yii Software LLC
...@@ -28,7 +28,7 @@ namespace yii\console; ...@@ -28,7 +28,7 @@ namespace yii\console;
* @author Carsten Brandt <mail@cebe.cc> * @author Carsten Brandt <mail@cebe.cc>
* @since 2.0 * @since 2.0
*/ */
class View extends \yii\base\Component class ConsoleColor
{ {
const FG_BLACK = 30; const FG_BLACK = 30;
const FG_RED = 31; const FG_RED = 31;
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
* mongodb (put it under framework/db/mongodb) * mongodb (put it under framework/db/mongodb)
* key-value-based (should allow storage-specific methods additionally to generic ones) * key-value-based (should allow storage-specific methods additionally to generic ones)
* redis (put it under framework/db/redis or perhaps framework/caching?) * redis (put it under framework/db/redis or perhaps framework/caching?)
- base
* TwigViewRenderer
* SmartyViewRenderer
- logging - logging
* WebTarget (TBD after web is in place): should consider using javascript and make it into a toolbar * WebTarget (TBD after web is in place): should consider using javascript and make it into a toolbar
* ProfileTarget (TBD after web is in place): should consider using javascript and make it into a toolbar * ProfileTarget (TBD after web is in place): should consider using javascript and make it into a toolbar
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment