Status update: View as object


(Qiang Xue) #1

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.

(Ricobregon) #2

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


(Gustavo) #3

great news!

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


(Yiqing 95) #4

:lol:

looks great!


(Charlespick) #5

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


(Alexander Makarov) #6

CHtml is still there.


(Jacob Moen) #7

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. :)


(Ak) #8

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.


(Roman Solomatin) #9

I think this is a great idea.


(Binkabir) #10

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)); 




(Alexander Makarov) #11

binkabir

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