See http://framework.zend.com/manual/en/zend.controller.rewriterouter.usage.html for using a Router to tell the ZF how to map a request to a controller and action.

For example. I would use in my index.php (ignoring includes for the moment):

//setup controller - step 1 add a Router!
$route = new Zend_Controller_RewriteRouter();

// this route array is actually in a separate file for my apps
// makes it easier to manage them and reduces index.php length
$routes = array();
$routes[] =    array(
        'name'        => 'generic',
        'route'        => ':controller/:action',
        'defaults'    => array(
            'controller' => 'index',
            'action' => 'index'
        )
);

// See how the index default is set above?
// To add params you need to define additional routes

// rest of index.php
foreach($routes as $rt)
{
    $route->addRoute($rt['name'], $rt['route'], $rt['defaults']);
}
$controller = Zend_Controller_Front::getInstance();
$controller->setRouter($route);

// run
$controller->run('./controllers');


You should read the documentation fully if possible - there are also a few ZF tutorials which cover most getting started steps. ;)

Kind regards,
Pádraic
 


Pádraic Brady
http://blog.quantum-star.com
http://www.patternsforphp.com


----- Original Message ----
From: Meraj Rasool Khattak <[EMAIL PROTECTED]>
To: [email protected]
Sent: Monday, October 9, 2006 5:43:15 AM
Subject: [fw-general] Controllers Errors

Hi,

I recently started working on Zend Framework but I am
having some problems with the controllers.  

My index.php is as the following:
<?php
set_include_path('.' . PATH_SEPARATOR . './library/'.
PATH_SEPARATOR . './application/models');

include 'Zend.php';
Zend::loadClass('Zend_Controller_Front');
Zend::loadClass('Zend_Controller_Action');
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('application/controllers');
$controller->dispatch();
?>

application/controllers/IndexController.php is as the
following:
<?php
class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        echo "This is the indexAction().";
    }
    public function loginAction()
    {
        echo "This is the loginAction().";
    }
}
?>

Now when I try to access this at
http://localhost/fwApp/index/ I am getting the
following error in my logs:
<ERROR>
[Mon Oct 09 09:38:16 2006] [error] [client
192.168.0.4] PHP Fatal error:  Uncaught exception
'Zend_Controller_Action_Exception' with message
'IndexController::norouteAction() does not exist and
was not trapped in __call().' in
/home/www/fwApp/library/Zend/Controller/Action.php:92\nStack
trace:\n#0
/home/www/fwApp/library/Zend/Controller/Action.php(114):
Zend_Controller_Action->__call('norouteAction',
Array)\n#1
/home/www/fwApp/library/Zend/Controller/Dispatcher.php(185):
Zend_Controller_Action->run(Object(Zend_Controller_Dispatcher),
Object(Zend_Controller_Dispatcher_Token))\n#2
/home/www/fwApp/library/Zend/Controller/Dispatcher.php(136):
Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token),
true)\n#3
/home/www/fwApp/library/Zend/Controller/Front.php(254):
Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Dispatcher_Token))\n#4
/home/www/fwApp/index.php(9):
Zend_Controller_Front->dispatch()\n#5 {main}\n  thrown
in /home/www/fwApp/library/Zend/Controller/Action.php
on line 92
</ERROR>

Can anyone help me resolve this issue?

I am using Zend Framework 0.1.5 with php5.1.6 on
Linux.

Thank you,

-Meraj

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


Reply via email to