Browse Source

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

* 'master' of git.yiisoft.com:yii2:
  moved ConsoleColor.
  Finished ViewRenderer.
  ViewRenderer WIP
tags/2.0.0-beta
Carsten Brandt 12 years ago
parent
commit
0f6eda3718
  1. 9
      framework/base/Application.php
  2. 30
      framework/base/View.php
  3. 32
      framework/base/ViewRenderer.php
  4. 4
      framework/util/ConsoleColor.php
  5. 3
      todo.md

9
framework/base/Application.php

@ -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.
*/
public function registerDefaultAliases()

30
framework/base/View.php

@ -137,13 +137,37 @@ class View extends Component
/**
* 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 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())
public function renderPhpFile($_file_, $_params_ = array())
{
ob_start();
ob_implicit_flush(false);

32
framework/base/ViewRenderer.php

@ -0,0 +1,32 @@
<?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);
}

4
framework/console/View.php → framework/util/ConsoleColor.php

@ -1,6 +1,6 @@
<?php
/**
* View class file.
* ConsoleColor class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
@ -28,7 +28,7 @@ namespace yii\console;
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class View extends \yii\base\Component
class ConsoleColor
{
const FG_BLACK = 30;
const FG_RED = 31;

3
todo.md

@ -5,6 +5,9 @@
* mongodb (put it under framework/db/mongodb)
* key-value-based (should allow storage-specific methods additionally to generic ones)
* redis (put it under framework/db/redis or perhaps framework/caching?)
- base
* TwigViewRenderer
* SmartyViewRenderer
- logging
* 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

Loading…
Cancel
Save