2
votes

I am new to Zend Framework.

I am running Apache 2.2 and have set the DocumentRoot in the httpd.conf file to the public directory created using Zend_Tool.

Within the public directory I have an .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]

...and an index.php file;

<?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') : 'production'));

// 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();

When I type "http://localhost/" into the browser the file index.phtml in the "application/views/scripts/index/" directory is rendered ok.

If I try to access other views using the controller and action names in a url I get a 404 error saying that the requested URL could not be found on the server.

For example I have the controller file TestController.php which is in the same directory as IndexController.php

/TestController.php/

<?php

class TestController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function testAction()
    {
        // action body
    }


}

I have created a test directory containing a file called index.phtml in "application/views/scripts/";

/views/scripts/test/index.phtml/

<br /><br />
<div id="view-content">
<p>View script for controller <b>Test</b> and script/action name <b>index</b></p>
</div>

When I try to render this file by typing "http://localhost/test/" I get a 404 error stating that the requested URL could not be found. All of the Zend Framework documentation I have read and countless other resources all state that this method should render correctly.

I must be missing something, but after an exhaustive search have been unable to find anyone else having this particular problem.

Regards Roan

4

4 Answers

1
votes

try creating an indexAction in the test controller... or test.phtml in the directory

1
votes

Can you check if the second url localhost/test is going through your index.php. You can put a die() or some debug statement for that.

0
votes

Hmm try to add this in your httpd.conf file:

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot Link to yourSiteFolder exp. C:/AppServ/www/yourSite/public
ServerName youServerName exp. http://mysite.com or you ip http://xxx.xxx.xxx.xxx
 </VirtualHost>

<Directory "Link to yourSiteFolder exp. C:/AppServ/www/yourSite/public">
Options FollowSymLinks
AllowOverride All
</Directory>

Find this:

#LoadModule rewrite_module modules/mod_rewrite.so

And delete '#'.

0
votes

Thanks for your replies.

Thought I would post my solution for others..

Here is the section I updated in the httpd.conf file within the directory tags;

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride All

and I had previously uncommented the module mentioned above

LoadModule rewrite_module modules/mod_rewrite.so

Cheers