Hello Matthew,
Yes, I forgot to say that I resolved this issue and fully understand now the modules. After doing some reading and practicing along with API Docs I learned quite a lot of things. Although there is still a lot more to learn but I'll leave it to read/practice/test.
Right now, since I didn't want my module to be named "default" *which is what ZF names its module as default* I ended up doing this
$frontier = new Zend_Controller_Front::getInstance();
$frontier->setControllerDirectory(array(
'MyModule' => 'path',
'MySecondModule' => 'path'));
If you use only a path (without array) it will automatically become "default", but if you put multiple modules and one of them isn't named "default" it will throw you the message.
So to set the default module you will simply use:
$frontier->setDefaultModule('MyModule');
As for routes working together with modules:
$prettyme = new Zend_Controller_Router_Route(
'my/pretty/urls',
array(
'controller' => 'clean',
'action' => 'urls',
'module' => 'MyModule'
)
);
$router->addRoute('pretty-route',$prettyme);
Well, this is more of an example and basic explanation, there is probably more to it, or maybe not but I'll leave it at that for the moment. I hope this helps anyone that is having trouble with modules or routing with modules.
Thanks again Matthew!
Regards,
David
Yes, I forgot to say that I resolved this issue and fully understand now the modules. After doing some reading and practicing along with API Docs I learned quite a lot of things. Although there is still a lot more to learn but I'll leave it to read/practice/test.
Right now, since I didn't want my module to be named "default" *which is what ZF names its module as default* I ended up doing this
$frontier = new Zend_Controller_Front::getInstance();
$frontier->setControllerDirectory(array(
'MyModule' => 'path',
'MySecondModule' => 'path'));
If you use only a path (without array) it will automatically become "default", but if you put multiple modules and one of them isn't named "default" it will throw you the message.
So to set the default module you will simply use:
$frontier->setDefaultModule('MyModule');
As for routes working together with modules:
$prettyme = new Zend_Controller_Router_Route(
'my/pretty/urls',
array(
'controller' => 'clean',
'action' => 'urls',
'module' => 'MyModule'
)
);
$router->addRoute('pretty-route',$prettyme);
Well, this is more of an example and basic explanation, there is probably more to it, or maybe not but I'll leave it at that for the moment. I hope this helps anyone that is having trouble with modules or routing with modules.
Thanks again Matthew!
Regards,
David
On Tue, Jul 22, 2008 at 8:53 AM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
-- David G. <allenskd@gmail.com> wrote(on Friday, 18 July 2008, 04:48 PM -0700):
>No, models != modules. Modules are standalone functionality that include
> I didn't quite understand that (well, actually I did but, models = modules?)
their own controllers and view scripts (and, potentially, models).
Models are your business processes and data access layers. You define a
module when you add a controller directory to the front controller. If
you have only one controller directory, which is typical, that is the
"default" module.
No.
> anyway, after reading the manual I ran
> Zend_Controller_Front::run('application/CMS/controllers') and it started
> working again. Yet I will try setting the module to that one and see what
> happens.
>
> I read the manual that it goes like this:
> 1) getInstance
> 2) setController
> 3) Use ::run to run default controller
Standard workflow is:
* get front controller instance
* configure front controller instance
* including setting any controller directories (modules)
* dispatch() the front controller instance
run() is used when you have only a single module, and can be used as a
shortcut to set the controller directory and dispatch() in a single
line.
So, it's the difference between:
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory('application/controllers/');
$front->dispatch();
and:
Zend_Controller_Front::run('application/controllers/');
I believe the OP has figured out their issue, which involves having
multiple modules, but none of them defined as the default, fallback
module.
> Nguyen Kha wrote:
> >
> > I think you must special one of two module's name is 'default' or use
> > 'setDefaultModule' method to set ImageHost is default module :-)
> >
> >
> > David G. wrote:
> >>
> >> Well, I wanted to separate the administration controllers from the main
> >> site logical code. This is my first time doing it and thought I would
> >> give it a try for the sake of not overcomplicating my life.
> >>
> >> Here's the code
> >>
> >> <?php
> >> /**
> >> * CMS Skeleton
> >> *
> >> * #@author: David Gonzalez
> >> */
> >>
> >> error_reporting(E_ALL|E_STRICT);
> >>
> >> ini_set('display_startup_errors', 1);
> >> ini_set('display_errors',1);
> >>
> >> set_include_path('./library' . PATH_SEPARATOR . get_include_path());
> >>
> >> require_once 'Zend/Loader.php';
> >>
> >> Zend_Loader::registerAutoload();
> >>
> >>
> >> $frontier = Zend_Controller_Front::getInstance();
> >> $frontier->throwExceptions(1);
> >>
> >> $frontier->setControllerDirectory(
> >> array('ImageHost' => 'application/CMS/controllers',
> >> 'ImageHostAdmin' => 'application/CMSAdmin/controllers')
> >> );
> >>
> >> var_dump($frontier->getModuleControllerDirectoryName());
> >>
> >> $frontier->dispatch();
> >>
> >> ?>
> >>
> >>
> >> Can someone explain why ZF is throwing this message at me?
> >>
> >> Fatal error: Uncaught exception 'Zend_Controller_Exception' with message
> >> 'No default module defined for this application' in
> >> C:\WebServer\Apache2\htdocs\CMS\library\Zend\Controller\Dispatcher\Standard.php:392
> >> Stack trace: #0
> >> C:\WebServer\Apache2\htdocs\CMS\library\Zend\Controller\Dispatcher\Standard.php(211):
> >> Zend_Controller_Dispatcher_Standard->getControllerClass(Object(Zend_Controller_Request_Http))
> >> #1
> >> C:\WebServer\Apache2\htdocs\CMS\library\Zend\Controller\Dispatcher\Standard.php(245):
> >> Zend_Controller_Dispatcher_Standard->isDispatchable(Object(Zend_Controller_Request_Http))
> >> #2
> >> C:\WebServer\Apache2\htdocs\CMS\library\Zend\Controller\Front.php(914):
> >> Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
> >> Object(Zend_Controller_Response_Http)) #3
> >> C:\WebServer\Apache2\htdocs\CMS\index.php(29):
> >> Zend_Controller_Front->dispatch() #4 {main} thrown in
> >> C:\WebServer\Apache2\htdocs\CMS\library\Zend\Controller\Dispatcher\Standard.php
> >> on line 392
> >>
> >> I checked the API Doc and the documentation but I didn't quite find a
> >> real answer to this, hope someone could explain this to me, I'd really
> >> appreciate it. I want to continue learning ZF.
> >>
> >> Thanks,
> >> David
> >>
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Question-about-setControllerDirectory-tp18538214p18539546.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论