Search code examples
phpsearchcakephp-1.3slash

Named parameters being passed as part of the url because of slashes


I am using cakephp 1.3 and i want to search a record which contain / in string. i have passed parameter as below. Search params are as below.

Array
(
    [controller] => indents
    [action] => admin_index
    [named] => Array
        (
            [pr_no_data] => pr
        )

    [pass] => Array
        (
            [0] => no
            [1] => dip
            [2] => 002
        )

    [prefix] => admin
    [admin] => 1
    [plugin] => 
    [form] => Array
        (
        )

    [url] => Array
        (
            [url] => admin/indents/index/pr_no_data:pr/no/dip/002
        )

    [isAjax] => 
)

as you all can see my url params contain admin/indents/index/pr_no_data:pr/no/dip/002 and now i want to search pr_no as defined in url. How can i do this.? because search for / record passing values as passed parameter. Please help me.

Thanks a lot.


Solution

  • As you can see in your array, CakePHP sees part of the data as passed parameters. In the pr_no_data named variable, you see it references pr as it's value.

    [named] => Array
       (
           [pr_no_data] => pr
       )
    

    However, the remaining character string in the data is recognized as passed parameters because of the slashes. So it is reading them as part of the URL, not the pr_no_data variable.

     [pass] => Array
        (
            [0] => no
            [1] => dip
            [2] => 002
        )
    

    What you need to look at is how you generate that variable before it is added to the URL. Perhaps you can change it to a pipe | separated list or a comma , separated list so it does not interfere with the URL and confuse cakephp.

    pr|no|dip|002
    pr,no,dip,002
    

    Once cakephp receives the data, you can then convert them back to slashes if needed:

    $passed = preg_replace('/,/', '/', $this->params['named']['pr_no_data']);