Status update: View as object

As discussed in the following two posts, I just completed the design and implementation of View class:

http://www.yiiframework.com/forum/index.php/topic/30101-views-as-objects/

http://www.yiiframework.com/forum/index.php/topic/21693-view-and-helper/

Below are summary of the View class design. Your feedback are welcome:

  • We will still have the render() methods in controllers and widgets like we do in 1.1. However, the implementation is different. In 2.0, the render() methods in controllers/widgets will create new View objects and call their render() thereafter.
  • The View class also contains methods such as widget(), beginCache() which in 1.1 are within CBaseController.
  • The View class contains a property named $owner which refers to the owner of the view.
  • In a view file, $this refers to the View object, while $this->owner refers to the owner of the view.
  • View renderer is no longer needed in 2.0. To support a new template syntax, one needs to extend View now.
  • Besides controllers and widgets, the View class can also be used in other places, such as console commands.

+1 for new View class and all the new features.

great news!

What about CHtml ? Is it done ? If so, how is its design ?

:lol:

looks great!

Looks great, I’m also wondering about how CHtml will work, will it be e.g. echo $this->html->activeTextField() ?

CHtml is still there.

Really nice!

This means that we can tell Yii to render different media/content types?

For instance, based on what is requesting data, and what method is used, the controller could decide what view object to use - JSON or XML for rest requests and the default for regular requests?

I think I am going to like this. :)

Sounds like a good move to me - one thing I would like is the ability to have a view that simply renders supplied xml with an xslt.

This sounds like it should make this much easier to implement.

I think this is a great idea.

great idea.

will the view have public methods like $this->theme=‘classic’ ?

secondly

if i have multiple actions that use the same view object, i can do this ?


 

 $view = new View(); 

 $view::render(array('model'=>$model,'var1'=>$var1)); 



binkabir

Yes, there will be some public properties. You’ll be able to use View manually as Qiang already mentioned.