Yii Framework Forum: Questions related to module development - Yii Framework Forum

Jump to content

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

Questions related to module development Module developers share your thoughts Rate Topic: ***** 1 Votes

#1 User is offline   Chris83 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 27-February 10
  • Location:Helsinki, Finland

Posted 08 December 2011 - 02:27 AM

Hello All,

Please note that I'm posting here and not on the extension forum because this doesn't concern a specific extension and I want to reach as many Yii developers and possible with these questions.

I've been developing extensions for Yii for the past year and a half and during that time I've encountered a few questions. Here are some for starters:

1. Module dependencies
If I would be to develop a smaller extension that I want to use in all of my modules would it be better to just build in the functionality instead of providing the extension and an extension within the module. Providing the extension with the module could easily lead to duplicate of code and naming collisions (assuming that PHP 5.3 is not available). What would be the best practice in this case?

2. Module themes
When developing a module that could be used in any Yii project there are some limitations to the user interface and lately I have been creating alternative UIs for my newest modules using Twitter's amazing Bootstrap library. Now my question is how I should distribute the alternative views/css for my modules? Should I add a themes/bootstrap folder and place the files there or what is the best practice?

3. Modules with application components
Sometimes it's necessary to both have a module and an application component for accessing the module functionality also outside of the module. Is it appropriate to include an application component with my modules and if so, should the configuration be split up between the component and the module? Have anyone else encountered a similar situation?

If you have any thoughts regarding any of the above questions please leave a reply below.

Thanks for reading.
Best regards,
Chris

My contribution to the Yii community:
Account | Yiistrap | Auth | Bootstrap | NordCms | Rights | LESS | SEO | Img

Follow me:
Twitter | GitHub | Bitbucket
0

#2 User is offline   Chris83 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 27-February 10
  • Location:Helsinki, Finland

Posted 09 December 2011 - 08:26 AM

Haven't anyone stumbled on the same questions I posted above? It would be great to see other opinions on these matters.
Best regards,
Chris

My contribution to the Yii community:
Account | Yiistrap | Auth | Bootstrap | NordCms | Rights | LESS | SEO | Img

Follow me:
Twitter | GitHub | Bitbucket
0

#3 User is offline   ahmadroni 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 250
  • Joined: 14-June 09
  • Location:Yogyakarta-Indonesia

Posted 09 December 2011 - 11:01 AM

This is an excellent idea, broaden my topic, I can not add my comment because I just learned yii
Hospital Cost Management System and
Hospital Management Information System
0

#4 User is offline   Chris83 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 27-February 10
  • Location:Helsinki, Finland

Posted 12 December 2011 - 02:47 PM

Surely someone has encountered the same questions. If you have or have an idea how to tackle one or multiple of my issues please post below.
Best regards,
Chris

My contribution to the Yii community:
Account | Yiistrap | Auth | Bootstrap | NordCms | Rights | LESS | SEO | Img

Follow me:
Twitter | GitHub | Bitbucket
0

#5 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 274
  • Joined: 15-March 09

Posted 12 December 2011 - 10:22 PM

View PostChris83, on 08 December 2011 - 02:27 AM, said:

1. Module dependencies
If I would be to develop a smaller extension that I want to use in all of my modules would it be better to just build in the functionality instead of providing the extension and an extension within the module. Providing the extension with the module could easily lead to duplicate of code and naming collisions (assuming that PHP 5.3 is not available). What would be the best practice in this case?


If you really use it in several modules, extract it. Maybe don't provide every small extension as a separate package, but provide one base library that contains all of your smaller extensions. So each module can specify as dependency: "baseLib >= v1.0.0", "baseLib >= v1.1.0", ... Doesn't introduce too many dependencies.

View PostChris83, on 08 December 2011 - 02:27 AM, said:

2. Module themes
When developing a module that could be used in any Yii project there are some limitations to the user interface and lately I have been creating alternative UIs for my newest modules using Twitter's amazing Bootstrap library. Now my question is how I should distribute the alternative views/css for my modules? Should I add a themes/bootstrap folder and place the files there or what is the best practice?


Didn't ever work with alternative themes, but I think providing a module with one "default" style (css) that can be disabled if someone wants to do his own styling should be a good start. About alternative views... Really no experience. But I think it will only result in increased maintenance work. And whoever cares about alternative views will probably also care about a consistent look and behavior of all components across his application -> he will probably have to write his own views.

View PostChris83, on 08 December 2011 - 02:27 AM, said:

3. Modules with application components
Sometimes it's necessary to both have a module and an application component for accessing the module functionality also outside of the module. Is it appropriate to include an application component with my modules and if so, should the configuration be split up between the component and the module? Have anyone else encountered a similar situation?


I don't see the need of a wrapping component. I think a module should simply specify its API that can be used. Where's the benefit of "Yii::app()->getComponent('foo')->bar()" over "Yii::app()->getModule('foo')->bar()"?
Don't like ads in my sig...
0

#6 User is offline   Chris83 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 27-February 10
  • Location:Helsinki, Finland

Posted 13 December 2011 - 01:38 AM

View PostBen, on 12 December 2011 - 10:22 PM, said:

I don't see the need of a wrapping component. I think a module should simply specify its API that can be used. Where's the benefit of "Yii::app()->getComponent('foo')->bar()" over "Yii::app()->getModule('foo')->bar()"?


The module isn't loaded unless the route points to that module. Sure it's possible to always import the module but I don't think that's the right solution. So it feels like an application component is the correct solution for this...
Best regards,
Chris

My contribution to the Yii community:
Account | Yiistrap | Auth | Bootstrap | NordCms | Rights | LESS | SEO | Img

Follow me:
Twitter | GitHub | Bitbucket
0

#7 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 274
  • Joined: 15-March 09

Posted 13 December 2011 - 05:49 PM

A module will be lazy-loaded the same way as a component. The first time you call:

Yii::app()->getComponent('foo');  // lazy-loads component named foo
Yii::app()->getModule('foo');     // lazy-loads module named foo


It's only that you can access components like properties:

Yii::app()->foo;


Which you can't do with modules.
Don't like ads in my sig...
0

#8 User is offline   Chris83 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 27-February 10
  • Location:Helsinki, Finland

Posted 14 December 2011 - 02:10 PM

View PostBen, on 13 December 2011 - 05:49 PM, said:

A module will be lazy-loaded the same way as a component. The first time you call:

Yii::app()->getComponent('foo');  // lazy-loads component named foo
Yii::app()->getModule('foo');     // lazy-loads module named foo


It's only that you can access components like properties:

Yii::app()->foo;


Which you can't do with modules.


Yeah that's what I meant by "importing" but I don't still think it's appropriate to load a module unless you're routing to it. Also if you nest the module then the following won't work:

Yii::app()->getModule('foo');

Best regards,
Chris

My contribution to the Yii community:
Account | Yiistrap | Auth | Bootstrap | NordCms | Rights | LESS | SEO | Img

Follow me:
Twitter | GitHub | Bitbucket
0

#9 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 274
  • Joined: 15-March 09

Posted 16 December 2011 - 03:52 AM

I think it's perfectly clean to access the module using getModule(). After all, if you want to use functionality provided by a module, it needs to be initialized/ imported even if not using one of its controller routes.

For example, a userManagement module could provide an API to create/ delete/ activate users, to expose the same functionality as provided by a controller to other programmers.

If using a component, how would you access the module functionality from that?
Don't like ads in my sig...
0

#10 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 569
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 17 January 2012 - 06:03 PM

Hi chris,

View PostChris83, on 08 December 2011 - 02:27 AM, said:

1. Module dependencies
If I would be to develop a smaller extension that I want to use in all of my modules would it be better to just build in the functionality instead of providing the extension and an extension within the module. Providing the extension with the module could easily lead to duplicate of code and naming collisions (assuming that PHP 5.3 is not available). What would be the best practice in this case?

Before PHP 5.3 you'd have to prefix your classes, but I would like to abandon that.
Regarding dependencies, please take a look at this posting. I think we need a tool like composer for that.
Because I have extensions shared across core modules I created my own extension package p3extensions, like yiiext. This one is required by my Phundament 3 modules. I found this the better solution over providing extensions with the modules, for the reasons you said above.

View PostChris83, on 08 December 2011 - 02:27 AM, said:

2. Module themes
When developing a module that could be used in any Yii project there are some limitations to the user interface and lately I have been creating alternative UIs for my newest modules using Twitter's amazing Bootstrap library. Now my question is how I should distribute the alternative views/css for my modules? Should I add a themes/bootstrap folder and place the files there or what is the best practice?

I think providing a themes folder is one of the best options, some modules let you specify a layout or css classes, but this is limited. On the other hand you have to move the files manually into the themes folder.
Usually one is developing his application without a theme, maybe you stick to blueprint or bootstrap, but themes are mainly used to overwrite the default application files.
For improving this situation it would be better if Yii comes with a default theme enabled by default and with an improved directory structure for themeing.
IMHO your theme files are 'buried' within the theme directory, which is not user friendly and complicates their management.

Maybe (backend-)modules simply should come with their layout and views and you customize them with a theme if you need to.
But That's more a discussion about module conventions. As there are no conventions regarding the points you mentioned. It's up to us to define them :)

View PostChris83, on 08 December 2011 - 02:27 AM, said:

3. Modules with application components
Sometimes it's necessary to both have a module and an application component for accessing the module functionality also outside of the module. Is it appropriate to include an application component with my modules and if so, should the configuration be split up between the component and the module? Have anyone else encountered a similar situation?

So you mean an image resizing app-component which is accessed by a media manager module for example?
If yes ... I think that is OK, regarding the config I would say, that this is also a weak point of Yii, so there should be another convention for it.


Best regards,
schmunk
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
0

#11 User is offline   schmunk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 569
  • Joined: 02-November 08
  • Location:Stuttgart, Germany

Posted 27 January 2012 - 10:26 AM

Related thread: UI components standardization
Phundament - Yii Application Boilerplate with composer support
Fork on github

Follow phundament on Twitter

DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
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