Hi Adam, I think you'll appreciate ZF once you get a grip on "the magic" with
the way it handles URL routing.
http://framework.zend.com/manual/en/zend.controller.router.html
The default route, which you *shouldn't* have to stray from is url
/:module/:controller/:action. ZF gets its params for the controller action from
those first three paths. Additional params follow along after the action.
Typically, you would have your module, let's say 'shop' and then the default
controller and inherent action, so yourdomain.com/shop/index/index (where index
doesn't need to be stated)
What you'd be proposing to do with the default route is a module for each site
section. But obviously that doesn't make any sense from a resource or workload
standpoint and will lead to redundancy.
So here's what to do in your case; you should create a default front
controller. All applications can have a config applied to them, which is loaded
into the index in root. I typically create a application.ini file that I stick
in a config folder. Something like this goes in index.php:
$application = new Zend_Application(
'production',
APPLICATION_PATH.'/configs/application.ini'
);
And then in your application.ini you should have (along with any other app
settings):
[production]
; Front Controller
resources.frontController.prefixDefaultModule = true
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.moduleControllerDirectoryName = "controllers"
resources.frontController.params.useDefaultControllerAlways = false
resources.frontController.params.displayExceptions = 0
resources.frontController.defaultController = "index"
resources.frontController.defaultAction = "index"
resources.frontController.defaultModule = "core"
This would allow you to put your AboutController into
modules/core/controllers/AboutController.php and call it from
yourdomain.com/about and it will fire the indexAction in that controller as it
is set to the defaultAction.
That's the crux of it, although I might be missing something - sorry, haven't
started a ZF app from scratch in a long while. So I welcome hearing from anyone
on what I may have missed here or if you find another method.
But this should get you toward your goal.
Best,
Wilson C. Revehl, CTO/VP
Web Developer
GO MEDIA
...........................................
Tel: 216.965.2437
Fax: 216.803.8100
Office Hours: 10-6 EST mon-fri
...........................................
gomedia.us
-----Original Message-----
From: Adam Dear [mailto:[email protected]]
Sent: Wednesday, January 25, 2012 10:20 AM
To: [email protected]
Subject: [fw-general] Best way to setup a Default controller that will be
called if controller not found
Hello, I am just starting to learn Zend Framework.
As an exercise to learn the framework, I am creating a new site for my wife to
showcase her handmade merchandise. On this site, as with most all sites, there
will be quite a few purely informational pages (About, Contact info, etc.).
My question, and what I need help with, is what is the best/proper way to
define a controller that will be called if no controller is found.
For example, I'd like to be able to go to the URL mysite.com/About and have the
framework call 'MyDefaultController' because the 'About'
controller will not exist.
I'm trying to avoid having to create a controller for every page that won't do
anything but show the same static html over and over. I also want my wife to be
able to create these pages on her own. The content for the pages will be in a
database and she will have an interface to edit the content.
Is the proper way to create a custom route that routes every request to my
default controller, and then define routes that send requests to few actual
controllers that will exist or is there a mechanism that I could use in a front
controller plugin that would be more appropriate?
Just for the record, I've been programming in PHP for about 10 years, I'm just
new to Zend Framework.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]