views:

96

answers:

4

I have my directory structure set up as follows:

Application Root
|-application
|  |--configs
|  |--controllers
|  |  |--helpers
|  |
|  |--layouts
|  |  |--scripts
|  |
|  |--models
|  |--views
|     |--scripts
|        |--index
|        |--test
|
|--data
|  |--session
|
|--public
|--index.php
|--.htaccess

In my controllers directory, I have 2 controllers: IndexController and TestController which have identical internal definitions, with 2 methods, indexAction and testingAction. When I point my browser to localhost/application I get the result of my IndexController.indexAction() but when I go to localhost/test or localhost/testing or localhost/test or really, any other variation, I get a 404 Not Found error.

I'm using the Zend Framework (1.9.6 I believe), and I've confirmed that there is no issue with the various source PHP files in terms of syntax errors.

Why might I be seeing this behavior and what can I do to fix it?

EDIT:

I had another developer send me a full Zend-based application to compare my setup with. There were no apparent differences in terms of the location of files, or the contents of the various configuration files. However, on his site too, I can only access the index page of the site, but none of the internal controllers. He does not have that problem. Is this possibly an issue with my Apache setup?

A: 

You should be pointing your browser to localhost/public, which should contain a .htacess file and index.php. If you are using the started application as a basis, the .htaccess configuration should be setup so that all requests that would have resulted in a 404 end up being passed to index.php which then in turn starts the application, loading the appropriate controllers.

EDIT
You also have the functions slightly wrong (I think). If you go to localhost/test it should call the index action in the test controller (unless you have defined another default action in the configuration).

So if you have a action named test in the test controller, you want to access:

localhost/public/test/test/

It helps if you set up an error controller, as it makes everything far easier to debug. For example, when I try and access a action that doesn't exist I get this (when in development mode):

Message: Action "index" does not exist and was not trapped in __call()

Stack trace:
...

Request Parameters:

array 'controller' => string 'mod' (length=3)
'action' => string 'index' (length=5)
'module' => string 'default' (length=7)

Yacoby
But I can get my IndexController.indexAction() to run properly, but nothing else...
Elie
+1  A: 
  1. You should point to localhost/public, not localhost/application.
  2. ZF used "index" as default controller and action name. So when you try localhost/public, it will find localhost/public/index/index, result to indexController.indexAction. When you pointed to localhost/test it will find localhost/test/index and localhost/testing will result in localhost/testing/index.

So, you should try localhost/test/testing.

Thang Nguyen
A: 

u must have indexAction in TestController to work with url like localhost/test

SM
I do - both Controllers have indexAction and testAction defined
Elie
+2  A: 

check you Apache configs. seems like .htaccess mod_rewrite does not working properly

UPDATE 1:

also check:

 <Directory "/Applications/MAMP/htdocs"> # OR WHAT IS IN YOU CONF FILE

   ... SKIP ...
    #
 # 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

   ... SKIP ...
 </Directory>

for AllowOverride All option. without it .htaccess files does not work

SM
Would this be located anywhere other than in the httpd.conf file?
Elie
noup. httpd.conf must contain something like LoadModule rewrite_module modules/mod_rewrite.so
SM