New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module Best Practices In Split Front/Backend App #1520

Closed
angelcoding opened this Issue Dec 14, 2013 · 13 comments

Comments

Projects
None yet
5 participants
@angelcoding

angelcoding commented Dec 14, 2013

What is/will be the best approach to developing and using a single module in a separated frontend/backend app such as in the advanced app template?

I'm talking about modules that might require frontend/backend separation themselves such as a blog module where you would want to manage posts, comments etc. in the backend section and display them publicly in the frontend section, all using a single module installed via composer.

Is it best to use an admin submodule or simply 'Admin' named controllers? How best to deal with config? Am I over analyzing a non-existent issue!?

Apologies if there's an obvious answer - I'm fairly new to Yii2 but, having said that, I had similar issues with modules in Yii1 and it might be good to have a more standardized approach to this that developers can follow when creating extensions.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Dec 14, 2013

Member

In general use common to host the module, connect it via config for both apps. As for frontend/backend, it seems you're confusing module with extension. Extension may contain more than one module i.e. blogBackend, blogFrontend.

Member

samdark commented Dec 14, 2013

In general use common to host the module, connect it via config for both apps. As for frontend/backend, it seems you're confusing module with extension. Extension may contain more than one module i.e. blogBackend, blogFrontend.

@samdark samdark closed this Dec 14, 2013

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 14, 2013

Member

I had exactly the same question in one of my projects and we are not finished with a solution right now. I'd like to keep this open to discuss the topic.

Member

cebe commented Dec 14, 2013

I had exactly the same question in one of my projects and we are not finished with a solution right now. I'd like to keep this open to discuss the topic.

@cebe cebe reopened this Dec 14, 2013

@ghost ghost assigned cebe Dec 14, 2013

@angelcoding

This comment has been minimized.

Show comment
Hide comment
@angelcoding

angelcoding Dec 15, 2013

Some thoughts I have on the issue (just thinking aloud really) ...

For users sharing modules on Github/Yii extensions directory, should they design them for the basic app structure, advanced app structure, or is there an easy way to incorporate both that everyone can use out of the box? I know it's called the 'advanced' app for a reason but if there's a good solution to handling this for everyone then it's worth doing, right?

If you do indeed use a backend module alongside a separate frontend module to cater for the advanced app as @samdark suggested, where would common module code go best? You could choose one or the other I guess, or even a third 'common' module for the extension, but something just 'feels' wrong, untidy or overcomplicated by doing it that way. Just my personal view.

I quite like how Yupe CMS - https://github.com/yupe/yupe - uses modules for Yii 1.1, whereby they allow modules to be 'installed' and 'activated' by copying the config from each module into a config/modules directory and auto merging everything. I will do some tests to see if it's easy and practical to employ a similar approach when using Yii2, perhaps by using a single module (e.g. for a blog again), separate front/back controllers and two 'installable' config files (one for front, one for back) that can be used separately for an advanced app or auto-merged somehow for a basic app.

I know Yii is a framework rather than a CMS but, with the way the new app templates are going, it's very close to a CMS now - just without actual content management built in as standard. Is it worth considering a core Yii extension manager similar to what Wordpress, Drupal, Joomla and other CMS's use? I mean for simpler, non-module based components/widgets as well as full blown modules. I think it would make everyone's lives a lot easier and add yet another massive plus point for using Yii2.

Like I said, just thinking aloud so make of all that what you will.

angelcoding commented Dec 15, 2013

Some thoughts I have on the issue (just thinking aloud really) ...

For users sharing modules on Github/Yii extensions directory, should they design them for the basic app structure, advanced app structure, or is there an easy way to incorporate both that everyone can use out of the box? I know it's called the 'advanced' app for a reason but if there's a good solution to handling this for everyone then it's worth doing, right?

If you do indeed use a backend module alongside a separate frontend module to cater for the advanced app as @samdark suggested, where would common module code go best? You could choose one or the other I guess, or even a third 'common' module for the extension, but something just 'feels' wrong, untidy or overcomplicated by doing it that way. Just my personal view.

I quite like how Yupe CMS - https://github.com/yupe/yupe - uses modules for Yii 1.1, whereby they allow modules to be 'installed' and 'activated' by copying the config from each module into a config/modules directory and auto merging everything. I will do some tests to see if it's easy and practical to employ a similar approach when using Yii2, perhaps by using a single module (e.g. for a blog again), separate front/back controllers and two 'installable' config files (one for front, one for back) that can be used separately for an advanced app or auto-merged somehow for a basic app.

I know Yii is a framework rather than a CMS but, with the way the new app templates are going, it's very close to a CMS now - just without actual content management built in as standard. Is it worth considering a core Yii extension manager similar to what Wordpress, Drupal, Joomla and other CMS's use? I mean for simpler, non-module based components/widgets as well as full blown modules. I think it would make everyone's lives a lot easier and add yet another massive plus point for using Yii2.

Like I said, just thinking aloud so make of all that what you will.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Dec 17, 2013

Contributor

@angelcoding all your thoughts can be marked as quetions do we need yii2 CMF?. As for me i see no problem in implementing this features for your own usage. Also you can submit PR to discuss it, because of reading so much text is painful. Can you submit PR?
Also i vote for this feature, want to see easy integration for Yii2 modules bundled with composer, this will make Yii2 more friendly and modules reusable.

Contributor

Ragazzo commented Dec 17, 2013

@angelcoding all your thoughts can be marked as quetions do we need yii2 CMF?. As for me i see no problem in implementing this features for your own usage. Also you can submit PR to discuss it, because of reading so much text is painful. Can you submit PR?
Also i vote for this feature, want to see easy integration for Yii2 modules bundled with composer, this will make Yii2 more friendly and modules reusable.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Feb 3, 2014

Member

Yii2 has everything for implementing such an extension in a good way.

Directory structure

common
  components
  models
backend
  controlles
  views
  Module
frontend
  controlles
  views
  Module

Namespaces

Root namespace is the same as in any extension i.e. samdark\blog (PSR-4 record required in composer.json). Common stuff is under samdark\blog\common. Backend module is samdark\blog\backend\Module, frontend module is samdark\blog\frontend\Module.

Using it

  • Install via Composer.
  • In your application config use modules:
'modules' => [
  'blogFrontend' => [
    'class' => 'samdark\blog\frontend\Module',
    'anonymousComments' => false,
  ],
  'blogBackend' => [
    'class' => 'samdark\blog\backend\Module',
  ],
]
  • Access via browser:
http://example.com/blog-frontend/post/view?id=10
http://example.com/blog-backend/user/index
Member

samdark commented Feb 3, 2014

Yii2 has everything for implementing such an extension in a good way.

Directory structure

common
  components
  models
backend
  controlles
  views
  Module
frontend
  controlles
  views
  Module

Namespaces

Root namespace is the same as in any extension i.e. samdark\blog (PSR-4 record required in composer.json). Common stuff is under samdark\blog\common. Backend module is samdark\blog\backend\Module, frontend module is samdark\blog\frontend\Module.

Using it

  • Install via Composer.
  • In your application config use modules:
'modules' => [
  'blogFrontend' => [
    'class' => 'samdark\blog\frontend\Module',
    'anonymousComments' => false,
  ],
  'blogBackend' => [
    'class' => 'samdark\blog\backend\Module',
  ],
]
  • Access via browser:
http://example.com/blog-frontend/post/view?id=10
http://example.com/blog-backend/user/index

@samdark samdark closed this Feb 3, 2014

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Feb 3, 2014

Contributor

@samdark can you correct or improve this example, i would like to see how to get simple http://example.com/blog/user/index, so some directory changes needed (i know that not, but example should be very simple without any questions)? this example wil be more usual rather then http://example.com/blog-backend/user/index.
And i think that we should document that for modules with camelCase same rule as for controller and controller actions are applied: ...blog-backend/user/index.

Contributor

Ragazzo commented Feb 3, 2014

@samdark can you correct or improve this example, i would like to see how to get simple http://example.com/blog/user/index, so some directory changes needed (i know that not, but example should be very simple without any questions)? this example wil be more usual rather then http://example.com/blog-backend/user/index.
And i think that we should document that for modules with camelCase same rule as for controller and controller actions are applied: ...blog-backend/user/index.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Feb 3, 2014

Member

@Ragazzo URLs are, as always, adjusted with URL rules in your application config. No directory changes needed.

https://github.com/yiisoft/yii2/blob/master/docs/guide/controller.md#routes

Member

samdark commented Feb 3, 2014

@Ragazzo URLs are, as always, adjusted with URL rules in your application config. No directory changes needed.

https://github.com/yiisoft/yii2/blob/master/docs/guide/controller.md#routes

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Feb 3, 2014

Contributor

yes, i guess i will submit docs to url.md with some examples, since they are very useful there. Should we have additional guide section for this issue?

Contributor

Ragazzo commented Feb 3, 2014

yes, i guess i will submit docs to url.md with some examples, since they are very useful there. Should we have additional guide section for this issue?

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Feb 3, 2014

Member

No, I think it was more of a forum topic "how to design my extension" rather than issue of the framework.

Member

samdark commented Feb 3, 2014

No, I think it was more of a forum topic "how to design my extension" rather than issue of the framework.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Feb 3, 2014

Member

👍

Member

cebe commented Feb 3, 2014

👍

@dynasource

This comment has been minimized.

Show comment
Hide comment
@dynasource

dynasource May 30, 2014

Member

I have studied the transition of Yii1 to Yii2 for a while now and I must say that the role of Modules in Yii2 is too much neglected in the upgrading docs. Many of us out here are using modules in our Yii1 projects and their application in the advanced template is vague and doesnt seem to be documented.

Important questions to be answered:

  • how should modules be divided over frontend/common/backend in the advanced template
  • how should a module in the common app be accessed in frontend / backend
  • what is the difference between a module and a extension that is installable by composer

Finally, not quite unimportant is the ambiguity in the definition of a frontend & backend environment. To me the explanations in docs / comments are unclear about:

  • the real difference between frontend & backend
  • the real advantages ('the advanced app is meant for medium & large sized projects within a teamsetting' does not answer this question)
  • practical examples of the advantages (how do we benefit from a separation of frontend and backend)
  • the tradeoff between the basic app & advanced app (there is an substantial increase in complexity -> in files/ in references / in tests etc etc.)

3 scenario's that overlap:

  • Frontend could be about the application meant for non-logged in users.
  • Frontend could also be about the application behind the login (registered users), with perhabs admin tasks (create/update/admin)
  • Backend is also primarily meant for administrator tasks.

So should users with administrative rights login through the backend? It is still unclear to me.

Many questions that I would love to see answered in the official docs.

Member

dynasource commented May 30, 2014

I have studied the transition of Yii1 to Yii2 for a while now and I must say that the role of Modules in Yii2 is too much neglected in the upgrading docs. Many of us out here are using modules in our Yii1 projects and their application in the advanced template is vague and doesnt seem to be documented.

Important questions to be answered:

  • how should modules be divided over frontend/common/backend in the advanced template
  • how should a module in the common app be accessed in frontend / backend
  • what is the difference between a module and a extension that is installable by composer

Finally, not quite unimportant is the ambiguity in the definition of a frontend & backend environment. To me the explanations in docs / comments are unclear about:

  • the real difference between frontend & backend
  • the real advantages ('the advanced app is meant for medium & large sized projects within a teamsetting' does not answer this question)
  • practical examples of the advantages (how do we benefit from a separation of frontend and backend)
  • the tradeoff between the basic app & advanced app (there is an substantial increase in complexity -> in files/ in references / in tests etc etc.)

3 scenario's that overlap:

  • Frontend could be about the application meant for non-logged in users.
  • Frontend could also be about the application behind the login (registered users), with perhabs admin tasks (create/update/admin)
  • Backend is also primarily meant for administrator tasks.

So should users with administrative rights login through the backend? It is still unclear to me.

Many questions that I would love to see answered in the official docs.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe May 30, 2014

Member

can you please open a new issue for this? This is not related to this issue and also this issue is already closed.

Member

cebe commented May 30, 2014

can you please open a new issue for this? This is not related to this issue and also this issue is already closed.

@dynasource

This comment has been minimized.

Show comment
Hide comment
@dynasource

dynasource May 30, 2014

Member

Of course. It is related to this issue with respect to the role of a module in the advanced template. Opened a topic at:
#3647

Member

dynasource commented May 30, 2014

Of course. It is related to this issue with respect to the role of a module in the advanced template. Opened a topic at:
#3647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment