Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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


3.4k
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.



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


3.4k

i want to use -Action and no -Action

Not sure what you mean by that.



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


3.1k
edited May '15

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

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


12.6k
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

http://docs.phalconphp.com/en/latest/reference/request.html