Yii Framework Forum: Can I Specify Common Controller For Advance Structure? - Yii Framework Forum

Jump to content

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

Can I Specify Common Controller For Advance Structure?

#1 User is offline   relaxpor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 08-February 14

Posted 20 February 2014 - 11:41 AM

As someone has ask in stackoverflow question here
http://stackoverflow...-a-yii2-project

i wonder if we could specify common controller and view for frontend and backend part?

Because it must have some function it has business-logic quite the same, (but may be different in view).

Please advise,
0

#2 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 601
  • Joined: 29-August 12

Posted 21 February 2014 - 04:20 AM

View Postrelaxpor, on 20 February 2014 - 11:41 AM, said:

As someone has ask in stackoverflow question here
http://stackoverflow...-a-yii2-project

i wonder if we could specify common controller and view for frontend and backend part?

Because it must have some function it has business-logic quite the same, (but may be different in view).

Please advise,

The idea of using advanced application template in the first place is to separate frontend and backend logic (like 2 different sub-applications).

If you want a common controller (like in basic app)... you can consider implementing a module as an extension which you can access from both frontend & backend.
0

#3 User is offline   mmx 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 20-June 11
  • Location:Virginia Beach, VA USA

Posted 21 February 2014 - 02:25 PM

View Postrelaxpor, on 20 February 2014 - 11:41 AM, said:

As someone has ask in stackoverflow question here
http://stackoverflow...-a-yii2-project

i wonder if we could specify common controller and view for frontend and backend part?

Because it must have some function it has business-logic quite the same, (but may be different in view).

Please advise,


You still need one controller for both the frontend and backend, but you could move SiteController to common/controllers and adjust the paths in the controller file to reflect the move. Then create new controllers for frontend and backend that are extended from SiteController (e.g., FrontendController and BackendController). The two new controllers could have no properties or methods or they could contain frontend or backend specific code. Those controllers will inherit the properties and methods in SiteController.

Within the two new controller files, you have the option of overloading specific methods from the SiteController class or the framework's Controller class.
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