문제

Just upgraded from 1.3 to 2.0.3 and I'm trying to migrate all the changes. I'm noticing that the following line

echo $this->Html->link('Quote', array('controller'=>'crm_quotes', 'action'=>'index', $lead['id'].'/'.$crmContact['CrmContact']['id']), null);

builds the url "/crm_quotes/index/15/21". When I click the link I'm taken to url:

"/crm_quotes/index/15%2F212

so it's replacing the characters with the html # but it's ultimately breaking the link.

When I manually edit the URL to the correct one:

"/crm_quotes/index/15/21"

the page loads.

Can someone enlighten me? Should I be using the url function rather than link?

I have a lot of pages that need multiple parameters passed in the url. I was using named parameters but after reading some comments by Mark Story I decided to stop the named parameters as he hinted at their possible removal from future versions.

도움이 되었습니까?

해결책

Pass the extra parameters the correct (cake) way. Cake encodes any / in the URL that it didn't specifically set; I haven't found out how to prevent this yet.

echo $this->Html->link('Quote', array('controller'=>'crm_quotes', 
                              'action'=>'index', 
                               $lead['id'],
                               $crmContact['CrmContact']['id']), null);

다른 팁

As an answer for your problem: just take the concatenated '/' out and pass the IDs as separate values in that array. It should place forward slashes between them automatically.

echo $this->Html->link('Quote', array(
    'controller'=>'crm_quotes', 
    'action'=>'index', 
    $lead['id'],
    $crmContact['CrmContact']['id']
));

On the topic of encoding: I think the problem here is that it doesn't know that you intend for the / to be treated as a valid part of the URL instead of just some text. The default behavior is to encode reserve characters to avoid this problem, so it gets URL encoded.

Here's a similar question, and an answer about URL encoding in general.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top