As discussed in the following two posts, I just completed the design and implementation of View class:
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.
What about CHtml ? Is it done ? If so, how is its design ?
Looks great, I’m also wondering about how CHtml will work, will it be e.g. echo $this->html->activeTextField() ?
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.
will the view have public methods like $this->theme=‘classic’ ?
if i have multiple actions that use the same view object, i can do this ?
$view = new View();
Yes, there will be some public properties. You’ll be able to use View manually as Qiang already mentioned.