We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Defalut controller

server {

listen   80;
server_name localhost.dev;

index index.php index.html index.htm;
set $root_path '/www/test.xxx.com/public';
root $root_path;

location / {
    try_files $uri $uri/ /index.php;
}

location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
}

location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
    root $root_path;
}

location ~ /\.ht {
    deny all;
}

}

index.php

<?php error_reporting(E_ALL); use Phalcon\Loader; use Phalcon\Mvc\View; use Phalcon\Mvc\Url as UrlProvider; use Phalcon\Mvc\Application; use Phalcon\DI\FactoryDefault; use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; try {

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

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

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

$di->set('db', function(){
    return new DbAdapter(array(
        "host"     => "localhost",
        "username" => "mysql",
        "password" => "1234",
        "dbname"   => "****",
        "charset"  => "utf8"
    ));
});

// Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
    $url = new UrlProvider();
    $url->setBaseUri('/');
    return $url;
});
// Handle the request
$application = new Application($di);

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

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

I encountered a problem, when I visited test.xxx.com cannot jump to the index controller, the page is blank, but I visit test.xxx.com/Index/inde is there is no problem, what reason is this excuse me?

Hi,

I had the same problem few days ago !

I'm using multiple modules, but I think it's the same answer for you :

  1. Check your database settings
  2. Check your paths
  3. Check your folders/files camelcase <--- the errors comes from here (for me)

Explanations : my file(s) was(were) named controller/indexController.php, but the filename must be the same as the classname (IndexController).

So all filename must begin with a uppercase letter (as your classnames).

If it's not the solution, check your nginx/php logs.

PS : In multiple modules, the paths to the folders (views, controllers, helpers, etc.) must be in camelcase too.



20.5k

Hi,

I had the same problem few days ago !

I'm using multiple modules, but I think it's the same answer for you :

  1. Check your database settings
  2. Check your paths
  3. Check your folders/files camelcase <--- the errors comes from here (for me)

Explanations : my file(s) was(were) named controller/indexController.php, but the filename must be the same as the classname (IndexController).

So all filename must begin with a uppercase letter (as your classnames).

If it's not the solution, check your nginx/php logs.

PS : In multiple modules, the paths to the folders (views, controllers, helpers, etc.) must be in camelcase too.

In fact, the controller has been implemented, but the program will not be the default rendering view, you need to add code $this->view->pick () to manually rendering, thank you for your enthusiastic answer