PHP5 - Zend Controller

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpman99
Forum Newbie
Posts: 6
Joined: Fri Feb 01, 2008 4:10 am

PHP5 - Zend Controller

Post by phpman99 »

Hey!
I have question about Zend Framework, and specifically Zend Controller. I'm reading "Practical Web 2.0 Applications with PHP" book, and I have the books code and I seem to have all the setting right. But for some reason when I try to access say http://localhost/account/register or any other location for that matter (only http://localhost works fine) then I always get a 404 File Not Found Error. I think there is something wrong with the Controller since it's the controller that uses this method of class and action names for URLs. Can anyone help or suggest a solution?
Thanks in advance!
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: PHP5 - Zend Controller

Post by Zoxive »

Are you using mod_rewrite? (Assuming your using apache)

Try http://localhost/index.php/account/register
phpman99
Forum Newbie
Posts: 6
Joined: Fri Feb 01, 2008 4:10 am

Re: PHP5 - Zend Controller

Post by phpman99 »

Yeah, I'm using rewrite and apache.
Thanks a lot for the advice, localhost/index.php/account/register works! How can I make it work without the index.php in between?
Thanks!
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: PHP5 - Zend Controller

Post by Zoxive »

What does your .htaccess look like?
Zend Framework Docs wrote:7.1.2.3. Create your rewrite rules

Edit the html/.htaccess file above to read as follows:
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
The above rules will route any non-resource (images, stylesheets) requests to the front controller. If there are other extensions you wish to exclude from the front controller (PDFs, text files, etc), add their extensions to the switch, or create your own rewrite rules. p
phpman99
Forum Newbie
Posts: 6
Joined: Fri Feb 01, 2008 4:10 am

Re: PHP5 - Zend Controller

Post by phpman99 »

This is how my .htaccess file looks like:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

And if I don't use it (AllowOverride None) then stuff works only through index.php (http://localhost/index.php/account/register), but if I use Allow Override All, then I always get a 500 Internal Server Error, which is part of the Zend Framework. Any ideas what to do?
Thanks!!
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: PHP5 - Zend Controller

Post by Zoxive »

The 500 Error leads me to think that most likely mod_rewrite isn't installed/enabled right.

Look in your apache log files.
phpman99
Forum Newbie
Posts: 6
Joined: Fri Feb 01, 2008 4:10 am

Re: PHP5 - Zend Controller

Post by phpman99 »

Thanks so much! Yeah, it wasn't included in the httpd.conf file. It took me 5 secs to fix that!
Help greatly appreciated!
Post Reply