Yii Framework Forum: How to extend View class - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to extend View class

#1 User is offline   phantomlord 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 15-October 17

Posted 13 February 2018 - 03:25 AM

Is there any way to create own view classes extended from standard yii\web\View? I wrote classes to emphasize that I need different classes for different views, but not one common "custom" view class. So that in view php files $this will represent either the respective "custom" class or standard yii\web\View if no custom class is present.
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,630
  • Joined: 16-February 11
  • Location:Japan

Posted 13 February 2018 - 05:51 AM

What aspects of the View object do you want to customize?

Well, you can see what View is expected to do by looking through the API reference of yii\web\View.
(http://www.yiiframew...i-web-view.html)
Do you really want to customize some methods of View?

I don't think the View object is designed to be customized for each and every page. IMO, what should be customized is not the View itself, but the view scripts, layouts, and/or themes that the View object uses to render the pages.
0

#3 User is offline   phantomlord 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 15-October 17

Posted 13 February 2018 - 11:46 PM

Thank you for reply. I mainly want to add some functions to avoid big piles of php codes mixed with html and js code. Of course I can do this in controller, but I think that view is a better place for it.
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,630
  • Joined: 16-February 11
  • Location:Japan

Posted 14 February 2018 - 05:59 AM

View Postphantomlord, on 13 February 2018 - 11:46 PM, said:

I mainly want to add some functions to avoid big piles of php codes mixed with html and js code.

I would like to know what kind of "big piles of php codes" you have in mind.

Quote

Of course I can do this in controller, but I think that view is a better place for it.

I'm not sure, but I would rather want to consider it in the model layer.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users