Can't call indexController's actions other than indexAction in Phalcon php

你离开我真会死。 提交于 2019-12-05 09:34:58

I am not sure if I understand your question completely but I think your Action must match the folder/file in view with the same name for it to function.

Also, I see you have extends 'ControllerBase' there then do you have a file called 'ControllerBase' in the controllers file with:

class ControllerBase extends \Phalcon\Mvc\Controller 

Another thing you can check would be the index.php in your public folder. Most of the time these stuff happens because the DI is missing or with a wrong input.

I think, that you should check your .htaccess file for following rule:

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

This will enable all other controller actions, not only index. To check that the problem is in this rule you can by access your controller method via url /index.php?_url=/index/some - if it will be loaded, change your .htaccess like in example below

Not sure if that's expected behaviour, but in some scenarios actions from IndexController should be requested in Capital case like Index/some/ when index/some/ would return not found response.

Try using custom routing.

This can be done as follows if you are using the skeleton project but the concept is the same for any other application.

create the file app/config/routes.php

/**@var $router \Phalcon\Mvc\Router*/
$router = $di->get('router');

$router->add(
    "/index/some",
    [
       "controller" => "index",
       "action"     => "some",
    ]
 );

In the index.php after loading services.php

require __DIR__ . '/../app/config/routes.php';
please change your .htaccess settings to following one

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule  ^$ public/    [L]
RewriteRule  (.*) public/$1 [L]
</IfModule>
class SomeController...

is what you're looking for.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!