I have a simple controller named AjaxController,
<?php
class AjaxController extends Zend_Controller_Action {
public function init() {
$params = $this->_getAllParams();
Zend_Debug::dump($params);
}
public function cartAction() {
$params = $this->_getAllParams();
Zend_Debug::dump($params);
}
}
?>
And I am calling this URL – http://example.com/ajax/cart from jQuery like below:
$.post(base_path + "ajax/cart/", { },
function(data) {
alert("Data Loaded: " + data);
});
I get a 404 error (Action not found) when called via jQuery/When I visit the URL directly
I get the following output alone (for the init function):
array(4) {
["controller"] => string(4) "ajax"
["action"] => string(3) "get"
["id"] => string(4) "cart"
["module"] => string(7) "default"
}
Here action is “get” and “cart” goes into ID (Just like a Zend Rest Route). Instead, the action name should be “cart”. What is wrong here?
The route works expected, if I add the following route via a ini file:
routes.about.type = "Zend_Controller_Router_Route_Static"
routes.about.route = "ajax/cart"
routes.about.defaults.controller = "ajax"
routes.about.defaults.action = "cart"
But I cannot add routes like this for all my actions in each controller.
I created a test controller to test this.
<?php
Class TestController extends Zend_Controller_Action {
function indexAction() {
echo "Index"; exit();
}
function testAction() {
echo "Test"; exit();
}
}
?>
Only the index action works. Test action does not work (throws EXCEPTION_NO_ACTION exception)
Zend Framework version – 1.12.0
Answering my own question (Actual answer is in the comment by Bas van Dorst)
There was a Zend_Rest_Route code in the bootstrap, which I forgot to remove from an old code.
After the removing that code, default routes started working.