I just could not figure out how to in the best way approach of having a certain layout depending on accessed module? I'm using the simple approach to modules,
just a subdir in the controller folder since i need share most of the models between my two (soon three) modules.
That should do it. Adding this to the layout section, howto modify layout within a controller would be great to new users just like myself. I will try to compile my problems and solutions building my app and post them when im finished.
Thanks a lot! There's been so many days I want to ask this. But I though that was no way. Glad to see I was wrong.
EDIT:
adding the code posted by Qiang, I got this error:
"Missing argument 1 for CModule::getModule()"
This is caused by the line
if($this->module)
Some doubts:
Why do I have to use the condition above?
Is it better to create my layouts under modules or in the main project? In mean, under myproject/protected/modules/mymodule/views/layout or myproject/protected/views/layout?
Under my module, how to create URLs that will ever be prefixed by the module-id? I mean, if I have a module 'docs', my urls will ever be 'http://myproject/docs/…'? (I've already set urlFormat to 'path')
- Under my module, how to create URLs that will ever be prefixed by the module-id? I mean, if I have a module 'docs', my urls will ever be 'http://myproject/docs/...'? (I've already set urlFormat to 'path')
Make sure you configure your server to rewrite the url aswell.
You should be able to use the same rewrites as they use in the Zend framework.
urlManager => 'path' just like you said you have it configured.
I've honestly not looked through the docs for this info so it might already be there, otherwise it might be good to add the link or copy paste the different configs.
The code I suggested is meant to be placed inside the init() method of base controller class. Not all controllers belong to a module, and that’s why the check.
urlManager => 'path' just like you said you have it configured.
I've honestly not looked through the docs for this info so it might already be there, otherwise it might be good to add the link or copy paste the different configs.
/Martin
Not exactly i was looking for
There is a way to create a url (with createUrl) with something like Yii:app->getModule('mymodule')->createUrl('/post/admin')?
Quote
The code I suggested is meant to be placed inside the init() method of base controller class. Not all controllers belong to a module, and that's why the check.
Thx Qiang, I've misunderstood. But it wouldn't be better to put it in the module base class?
Yes, putting in the module is fine too, but then you just need to access $this instead of $this->module since the former already gives you the module instance.