我的網址都是這樣CakePHP的URL蛞蝓問題
example.com/deals/by_city/glasgow
我在需要搶網址的「格拉斯哥」部分和cities_controller行動「by_city」做的東西我怎麼能用cakephp做這個?我只想知道如何獲取這部分url並將其存儲在變量中。
所有幫助表示讚賞:)
感謝 戴夫
城市控制器
function city_changer($CitySlug = null) {
$active = $this->City->find('first', array('conditions' => array('City.slug' => $CitySlug)));
$cities = $this->City->find('all', array('order' => array('City.name', 'City.name ASC')));
$this->set(compact('active', 'cities'));
}
市changer.ctp
<h2>Daily Deals from <?php echo $active['City']['name'];?></h2>
<form>
<select name="file" size="1" onchange="loadPage(this.form.elements[0])" target="_parent._top" onmouseclick="this.focus()">
<?php foreach($cities as $city) {?>
<option value="/new_avc/deals/by_city/<?php echo $city['City']['slug'];?>"><?php echo $city['City']['name'];?></option>
<?php }?>
</select>
</form>
default.thtml中
<div id="header_wrapper">
<div id="navigation">
<div id="logo">
<h1>Amazing Voucher Codes</h1>
</div>
<div id="city_nav">
<?php echo $this->requestAction('/cities/city_changer/'.$city['City']['slug'], array('return'));?>
</div>
由於沒有數據庫鏈接到default.thtml中具有問題得到蛞蝓傳遞給控制器:)
您能否澄清一下問題:您是否在控制器交易中使用了'by_city',並且您想知道該操作如何使用該參數?或者您是否將該URL作爲字符串,並且您需要提取它的最後部分?或者是其他東西? – JJJ
編輯問題:) – Dave
['SluggableBehavior'](https://github.com/CakeDC/utils/blob/master/models/behaviors/sluggable.php)可以幫助您創建這些URL部分。只需將其附加到您的模型,並添加一個'slug'字段到您的表。 – deizel