Search code examples
cakephp

Cakephp 2.5 Postlink hiding the model attribute name at the URL


I am using a cakephp 2.5 postlink method inside a view file :

$tableRow['Model.modelatribute'] = $this->Form->postLink(
                    $data['Vehicle']['plate'],
                    array('controller'=>'somecontroller',
                      'action' => 'somemethod',
                      'Model.modelatribute' => base64_encode($data['Vehicle']['plate'])
                    ),
                    array('confirm' => 'Look at  vehicle '.$data['Vehicle']['plate'])
                );

I would like not to show the model atribute name on the url bar. After clicking on the link and being redirected, the url shows :

somemethod/Model.modelatribute:vSpEeTIweQ%3D%3D

Can i hide the model atribute name, using postlink method o cakephp 2.5 ?

Thank´s in advance


Solution

  • If you simply want to pass the value of Model.modelatribute as a parameter, just leave off Model.modelatribute in your routing array. If you want to pass the value without occouring in the url you can use the data option of postLink.

    echo $this->Form->postLink(
        $data['Vehicle']['plate'],
        array(
            'controller'=>'somecontroller',
            'action' => 'somemethod',
            base64_encode($data['Vehicle']['plate']) // Routing array without modelname
        ),
        array(
            'confirm' => 'Look at  vehicle '.$data['Vehicle']['plate'],
            'data' => array(
                // Data option of postLink method
                'Model.modelatribute' => base64_encode($data['Vehicle']['plate'])
            )
        )
    );