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

i dont want to use --Action as suffix?

  • we use indexAction as its has a index view ,
  • but my ajax , i dont want to add a suffix -Action in ,
  • how it will effectivity
  • my english is poor , if misunderstand or wrong grammar, hope reply a true word for me


7.7k
edited May '15

Refer to @ https://github.com/phalcon/cphalcon/issues/10121

Workaround is to set this two options in your Dispatcher;

$dispatcher->setControllerSuffix("");
$dispatcher->setActionSuffix("");

If you remove suffix from controllers too, remember to also name your controllers properly.

/project/app/controllers/Index.php

Here is full example;

$di->set('dispatcher', function() {
    $dp = new \Phalcon\Mvc\Dispatcher();
    $dp->setControllerSuffix('');
    $dp->setActionSuffix('');
    $dp->setDefaultNamespace('App\Controllers');
    return $dp;
});

I prefer this method my self, but note there is some function names that you wont be able to use like for example list() funnction in php. But this true for any other php function name that already exists.



27.0k
edited May '15
  • you head portrait was so cool ,
  • i want to use -Action and no -Action


7.7k

i want to use -Action and no -Action

Not sure what you mean by that.



27.0k
edited May '15
  • 我的意思是說我想用action做為後綴和不用action在統一個controller裏面的,
  • by the way your portrait is so cute
  • how to change my portrait


5.4k
edited May '15

已经告诉你了,无法实现! 头像修改,请修改自己的github账号关联头像。

  • 我的意思是說我想用action做為後綴和不用action在統一個controller裏面的,
  • by the way your portrait is so cute
  • how to change my portrait


16.0k
Accepted
answer
edited May '15

if you don't want to use the Action suffix only on ajax request, you have to check if the request is ajax and apply on Tux's answer.

// Getting a request instance
$request = new Request();

$di->set('dispatcher', function() use ($request) {  
    // Check whether the request was made with Ajax
    if ($request->isAjax() == true) {
        $dp = new \Phalcon\Mvc\Dispatcher();
        $dp->setControllerSuffix('');
        $dp->setActionSuffix('');
        $dp->setDefaultNamespace('App\Controllers');
        return $dp;
    }
});

Read the docs. Are your best friend

https://docs.phalcon.io/en/latest/reference/request.html