我正在開發使用CakePHP 2.6的應用程序,並用使含有URL的字符作爲一個參數的字符串通過到一個控制器的方法具有的問題。阻止CakePHP從作爲參數傳遞的url中提取字符?
我認爲我的代碼塊,其相呼應了一系列包含數據表中的行,並穿過頁面ID,單元ID和有時可以包含一個URL的鏈接的ID。
<?php foreach($linklist as $l) { ?>
<tr id="Link_<?php echo $l['ID']; ?>">
<td><?php echo $l['Title']; ?></td>
<td class="buttontd"><?php echo $this->Form->postlink('Delete', array('action' => 'deletelink', $this->request->params['pass'][0], $results[0]['PageUnitTypeID'], $l['ID']), array('class' => 'button delete')); ?></td>
</tr>
<?php } ?>
當postlink
按鈕在傳遞信息的「deletelink」動作控制器的URL看起來是這樣的:
http://mydomainname.com/webpages/deletelink/239/7/urlhttp%3A%2F%2Fwww.google.co.uk%2F
這表明URL已通過爲字符串,但隨後在行動時,我嘗試只是var_dump()
它返回的www.google.co.uk
一個字符串,僅此而已,其阻止我這樣做對參數substr()
調用來檢查前3個字符等於url
是第三參數。
我試圖包裹內serialize()
和urlencode()
在postlink調用的參數,但它們都沒有過完整的字符串返回爲
urlhttp%3A%2F%2Fwww.google.co.uk%2F
的預期效果沒有人知道一個成功的方式穿過這樣的參數不會丟失重要的字符?
更新1:Deletelink行動
public function deletelink($pid = null, $uid = null, $lid = null) {
$this->autoRender = false;
if (!is_null($pid) && is_numeric($pid) && !is_null($uid) && is_numeric($uid)) {
if (!is_null($lid)) {
if (substr($lid, 0, 3) == 'url') {
echo substr($lid, 0, 3);
} else {
echo substr($lid, 0, 3);
}
} else {
$this->Session->setFlash('It is unknown which link you wish to delete from the webpage', 'flash_message_bar', array('class' => 'error'));
return $this->redirect(array('action' => 'edit', $pid));
}
} else {
$this->Session->setFlash('It is unknown which on which webpage you wish to delete a link', 'flash_message_bar', array('class' => 'error'));
return $this->redirect(array('action' => 'index'));
}
}
是否要傳遞3個參數ters到'deletelink'行動?你的刪除動作是怎樣的? – skywalker
@skywalker是的,我想所有的3個參數傳遞給'deletelink'行動。這個概念是用第三個參數來做東西,然後使用前兩個參數重定向到另一個動作。我已更新我的原始文章,以包含'deletelink'控制器代碼。 – Daniel
你嘗試[這](http://stackoverflow.com/questions/4750989/passing-an-urlencoded-url-as-parameter-to-a-controller-action-at-cakephp)? – skywalker