Zend Framework, MVC - Unknown Controllers give 404

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
AcidRain
Forum Newbie
Posts: 3
Joined: Sun Jan 21, 2007 5:09 pm

Zend Framework, MVC - Unknown Controllers give 404

Post by AcidRain »

Hi,

I googled alot but I did not find any answers. I wanted to test the
MVC system, but I'm always getting http error 404 when I try to access
http://local-mysite/unknownctrl

Backgrounds:

PHP 5.1.6
Zend Framework 0.6.0
Apache 2.2.* (mod_rewrite enabled/loaded)

local-mysite is (in /etc/httpd/conf/httpd.conf)
<VirtualHost *:80>
ServerName local-mysite
DocumentRoot /var/www/html/mysite
</VirtualHost>

local-mysite is defined in /etc/hosts so that my local DNS knows it.
127.0.0.1 local-mysite localhost

the virtualhost directive is working, no problem with that. I put a
phpinfo file at the documentroot, and the $_SERVER vars are OK.

at the documentroot i have the following dirs & files
app/
app/controllers (contains "IndexController.php")
app/models
app/viewers
index.php
.htaccess

the content of .htaccess is

Code: Select all

RewriteEngine On
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
index.php (the boostrap file) content is

Code: Select all

<?php
$_include_path=get_include_path();
$_include_path.=PATH_SEPARATOR.'/usr/share/ZendFramework/library';
$_include_path.=PATH_SEPARATOR.'/usr/share/Smarty';

if(set_include_path($_include_path)==FALSE){
       echo "Error: unable to set include path\n";
       exit(1);
}

require_once 'Zend.php';

Zend::loadClass('Zend_Controller_Front');
Zend::loadClass('Zend_Controller_RewriteRouter');
Zend::loadClass('Zend_Controller_Action');
Zend::loadClass('Zend_Controller_Request_Http');

$request=new Zend_Controller_Request_Http();
$base_url = dirname($_SERVER['PHP_SELF']);//substr($_SERVER['PHP_SELF'], 0, -9);
$request->setBaseUrl($base_url);
$router=new Zend_Controller_RewriteRouter();


//Zend_Controller_Front::run('./app/controllers');

try{
$front=Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
$front->returnResponse(true);
$front->setControllerDirectory('./app/controllers');
$front->setRouter($router);
$response=$front->dispatch($request);
echo $response;
}catch(Zend_Controller_Exception $e){
       echo $e->getMessage();
}
?>
if i go to http://local-mysite/

i've got a message from IndexController::indexAction (it's the same
content than the manual's, a basic echo "hello i'm indexcontroller")

but when i go to http://local-mysite/unknownctrler

i just have a 404 error telling me the file is not found ??? i
expected that the .htaccess would have redirected me to index.php.

thanks for reading this far ;-)

best regards,
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Have you tried

Code: Select all

RewriteEngine on
RewriteBase /mysitename
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
in your top level .htaccess file ?
AcidRain
Forum Newbie
Posts: 3
Joined: Sun Jan 21, 2007 5:09 pm

Post by AcidRain »

Hi,

Thanks for the quick reply but my error was somewhere else. I never noticed that I had a "AllowOverride None" directive set inside the DocumentRoot's <Directory> ! The .htaccess (and it's mod_rewrite directives) was never read. I added some lines in my httpd.conf and now it's ok. (at least the demo scripts).

I will certainly return here ;-)
Post Reply