私のURLがCakePHPのURLナメクジ質問
example.com/deals/by_city/glasgowよう
ある私は、URLの「グラスゴー」の部分をつかむために必要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.ctpに
<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.ctpにするためにリンクされないデータベースが存在しないように:)
質問を明確にすることができます:コントローラ 'deals'にアクションby_cityがあり、そのアクションがどのようにパラメータを使用できるか知りたいですか?または、そのURLを文字列として持っていて、最後の部分を抽出する必要がありますか?または、他の何か? – JJJ
編集された質問:) – Dave
['SluggableBehavior'](https://github.com/CakeDC/utils/blob/master/models/behaviors/sluggable.php)は、それらのURLパーツの作成に役立ちます。あなたのモデルに添付して、あなたのテーブルに 'slug'フィールドを追加するだけです。 – deizel