I'm new to Zend-Framework and i'm trying to call action method from indexController.php file using Jquery, that time i'm getting Error :
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/zf_demo/public/index/process
My Code is : IndexController.php
public function processAction() {
echo "Successfully Called processAction";
}
And I'm calling this action using following Code :
$.ajax({
type: "POST",
url: "http://localhost/zf_demo/public/index/process",
success: function() {
alert("AJAX call a success!");
},
error: function() {
alert("AJAX call an epic failure");
}
});
.htaccess File :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
For More Help :
1 ) application.ini
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
[config]
resources.db.adapter = PDO_MYSQL
resources.db.isDefaultAdapter = true
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password =
resources.db.params.dbname = pankaj_test
2) Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initController()
{
$this->_frontcontroller = Zend_Controller_Front::getInstance();
$this->_frontcontroller->setControllerDirectory(APPLICATION_PATH . 'controllers/');
}
protected function _initRoute()
{
$this->_route = $this->_frontcontroller->getRouter();
$this->_route->addRoute('default', new Zend_Controller_Router_Route(
':controller/:action/*', array(
'module' => 'default',
'controller' => 'index',
'action' => 'index'
)
));
}
public function run()
{
try {
$this->_frontcontroller->dispatch();
}
catch (Exception $e) {
print nl2br($e->__toString());
}
}
protected function _initDb()
{
$configData=array(
'database' => array(
'adapter' => 'Pdo_Mysql',
'params' => array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'pankaj_test')
)
);
$config=new Zend_Config($configData);
$db=Zend_Db::factory($config->database);
//$db = Zend_Db_Table_Abstract::getDefaultAdapter();
Zend_Db_Table::setDefaultAdapter($db);
}
}
My index.php(From public folder)
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/* Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
?>