我有roomcatalogue.php
页面,此页面显示了所有可供选择的房间 -
<?php foreach ($data as $key=>$row): ?>
<!-- Item -->
<div class="col-sm-6 masonry-item">
<a href="<?php echo Url::to(['site/roompage']); ?>" class="product_item text-center">
<span class="product_photo bordered_wht_border">
<img src="images/rooms/double_room.jpg" alt="">
</span>
<span class="product_title"><?php echo $row['room_type']; ?></span>
<span class="product_price">Rs.<?php echo $row['rate']; ?></span>
</a>
</div>
<?php endforeach; ?>
我还有roompage.php
,其中包含有关房间的所有房间描述/信息。
当用户点击roompage.php
中的特定房间时,我需要roomcatalogue.php
根据房间进行更改。
问题可能听起来很基本我尝试了许多教程,说明使用$_GET[]
方法,但我无法正确使用它,请帮助解决这个问题。
更新
public function actionRoompage($id)
{
$searchModel = new RoomTypesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$data = RoomTypes::findOne($id);
return $this->render('roompage', [
'model' => $this->findModel($id),
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'data' => $data,
]);
}
protected function findModel($id)
{
if (($model = RoomTypes::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
并在roompage.php <?php echo Html::encode($data->room_type);?>
中显示与数据库中的id相关联的数据
roompage.php
<!-- Content -->
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="bordered_block col-md-12 grey_border">
<div class="container">
<div class="row">
<div class="col-md-6 col-xs-12">
<h3 class="title"><?php echo Html::encode($data->room_type);?></h3>
<div class="meta-box clearfix">
<div class="price-box">
<span class="special-price">$1420.20</span>
<del class="old-price">$1607.96</del>
</div>
</div>
<p>Single Rooms provide a space of 30-40m², offering a comfortable stay for one guest. </p>
<div class="add-to-box">
<div class="add-to-cart">
<input type="text" class="form-control qty" title="Qty" value="1" maxlength="12" id="qty" name="qty">
<span class="increase-qty"><i class="fa fa-sort-up"></i></span>
<span class="decrease-qty"><i class="fa fa-sort-down"></i></span>
</div>
<a href="<?php echo Url::to(['site/shopcart']); ?>">
<button class="button btn btn-default" title="Add to Cart" type="button">
<em class="fa-icon"><i class="fa fa-shopping-cart"></i></em>
<span>Add Cart</span>
</button></a>
<a class="link-wishlist btn btn-default"><i class="fa fa-star"></i></a>
</div>
</div>
<hr>
<ul id="myTab" class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#home" id="home-tab" role="tab" data-toggle="tab" aria-controls="home" aria-expanded="true">Description</a></li>
<li role="presentation"><a href="#profile" role="tab" id="profile-tab" data-toggle="tab" aria-controls="profile">Reviews</a></li>
</ul>
<div id="myTabContent" class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="home" aria-labelledBy="home-tab">
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
</div>
<div role="tabpanel" class="tab-pane fade" id="profile" aria-labelledBy="profile-tab">
</div>
</div>
<!--Sidebar End-->
</div>
<!--Row End-->
</div>
</div>
</div>
<!-- Row End -->
</div>
</div>
<!-- Content End -->
答案 0 :(得分:1)
假设roompage是站点控制器中用于显示由id标识的房间信息的操作
你的参考应该是
<div class="col-sm-6 masonry-item">
<a href="<?php echo Url::to(['site/view-roompage',
'id' =>$row['room_id']]); ?>" class="product_item text-center">
假设控制器是站点 在你的控制器中你需要一个新的动作
public function actionViewRoompage($room_id)
{
return $this->render('view-roompage', [
'model' => $this->findModel($room_id),
]);
}
protected function findModel($room_id)
{
if (($model = Room::findOne($romm_id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
然后您需要在views / site
中使用view-rooompage视图在view-roompage.php中你可以显示与你相关的数据房间..
如果您遇到findOne($room_id)
问题,请尝试
$data = RoomTypes::find()->where(['room_id' => $room_di])->one();
对于最后一个小问题,建议你这样做
$modelForRate = RoomTypes::find()->where(['room_type' => $model->room_type])->all();
foreach($modelForRate as $key =>$value){
$actRate = value->rate
}
答案 1 :(得分:0)
这不应该是困难的。如果您有房间控制器,则只需执行另一个名为roomDetails()
的操作。在a标签内创建一个指向该操作的URL,并作为参数发送房间ID。在操作中使用该参数通过用户模型从sql获取房间详细信息并将房间详细信息发送为json,或者如果要渲染另一个完整视图或部分视图,则可以通过$this->render('roomDetailsPartial', array('roomDetail' => $roomDetailsFromSql))
您没有指定您尝试的内容,因此我无法添加代码来帮助您。