2

I'm new to phalconphp and following their tutorials, as far as I understand it, I don't need to create a specific routing component and that it should pick up a route if it exists. I could obviously be massively wrong here which means it should be easy to correct me! But so far the only controller that will work is my indexController.

This is my bootstrap

<?php

try {

//Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
    '../app/controllers/',
    '../app/models/'
))->register();

//Create a DI
$di = new Phalcon\DI\FactoryDefault();

//Setting up the view component
$di->set('view', function(){
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../app/views/');
    return $view;
});

//Handle the request
$application = new \Phalcon\Mvc\Application($di);

echo $application->handle()->getContent();

} catch(\Phalcon\Exception $e) {
  echo "PhalconException: ", $e->getMessage();
}

And then if I create my own FooController

<?php

class FooController extends \Phalcon\Mvc\Controller
{

public function indexAction()
{

    echo "FOO";

}

public function fooAction(){
    echo "FOO";
}

}

Neither of these actions will ever get fired. Now I actually receive a 404 error document from the server. So I'm not sure if there's an issue with my .htaccess file, again though this is copied straight from the tutorial

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
   </IfModule>

Can anyone see anything obviously wrong here? The only difference is I've set up a view for the indexController. I think it's the 404 which is leading me to believe it's more an issue with the server set-up perhaps then my php code

kwelsan
  • 1,229
  • 1
  • 7
  • 18
TommyBs
  • 9,354
  • 4
  • 34
  • 65

2 Answers2

2

Your .htaccess file is fine and, no, you don't need any routes file if you just want to use the standard MVC /controller/action type pattern.

Your issue is that your http server is not re-writing the URLs properly. I'm not sure which http server you are using, so, I can't provide any specifics on fixing the http server itself.

brian
  • 2,745
  • 2
  • 17
  • 33
1

Turn MultiViews off or apache will try to find the file by adding some extensions (.txt, .html, .htm, .php ...) and then the redirect variable _url is wrong.

<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteEngine on
  RewriteRule  ^$ public/    [L]
  RewriteRule  (.*) public/$1 [L]
</IfModule>
DerFichtl
  • 97
  • 1
  • 3