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.

forward-slash in get parameter returns null

Hello,

I use the the folliwing code:


    /**
     * @Get(
     *     '/{sample}'
     * )
     * @param $sample
     * @return \Phalcon\Http\Response
     */
    public function singleAction($sample)
    {
        return ResponseUtil::createJSONResponse (
            HTTPStatusCodeEnumeration::OK,
            true,
            'yes, found',
            $sample
        );
    }
$sample looks like this:

$sample = ABC123456789/12 -> returns: ROUTE NOT FOUND

$sample = ABC123456789 -> returns: ABC123456789

What do I have to do to make the router ignore the forward-slash in the sample-parameter?

Url-Encoding the forward-slash with "%2F" is not working. It destroys the routing functionality.

Thank you for your help!



168
Accepted
answer

Sometimes you miss the forest for the trees...

The solutions is to just pass the number after the slash as a second argument.

    /**
     * @Get(
     *     '/{orderNumber}/{sampleNumber}'
     * )
     * @param $orderNumber
     * @param $sampleNumber
     * @return \Phalcon\Http\Response
     */
    public function singleAction($orderNumber, $sampleNumber)
    {
        return ResponseUtil::createJSONResponse(
            HTTPStatusCodeEnumeration::OK,
            true,
            'yes, found',
            $orderNumber . "/" . $sampleNumber
        );
    }