基於ThinkPHP的開發筆記5-顯示活動詳情

一、後臺組織數據
<?php
	//活動控制器
	class ActivityAction extends Action{
		public function view(){
			$id=I('get.id');
			//$this->activity=M('activity')->where('id='.$id)->find();
			$sql='select a.*,ua.signName,ua.signNum,ua.userName from activity a '
					.' left join user_activity ua on a.id=ua.activityId '
					.' where a.id="'.$id.'" order by ua.signTime';
			$Model = new Model();// 實例化一個model對象 沒有對應任何數據表
			$data=$Model->query($sql);	
			$signUsers='';
			$totalNum=0;
			foreach ($data as $v) {
				//p($v[signName]);
				$signUsers.=$v[signName].', ';
				$totalNum+=$v[signNum];
			}
			$signUsers=substr($signUsers, 0,strlen($signUsers)-2);
			// echo $signUsers;
			// echo $totalNum;
			$activity = array(
				'typeName' => $data[0][typeName], 
				'title' => $data[0][title], 
				'startTime' => $data[0][startTime],
				'endTime' => $data[0][endTime],
				'address' => $data[0][address],
				'detail' => $data[0][detail],
				'maxNum' => $data[0][maxNum],
				'signUsers' => $signUsers,
				'totalNum' => $totalNum
				);
			$this->activity=$activity;
			$this->display();
		}

	}
?>
二、前臺顯示數據
<div class="row">
	<label class="field">活動分類
	</label>
	<label class="field_content">
		{$activity.typeName}
	</label>
</div>
<div class="row">
	<label class="field">活動標題
	</label>
	<label class="field_content">
		{$activity.title}
	</label>
</div>
      
<div class="row">
	<label class="field">活動地點
	</label>
	<label class="field_content">
		{$activity.address}
	</label>
</div>
<div class="row">
	<label class="field">開始時間
	</label>
	<label class="field_content">
		{$activity.startTime}
	</label>
</div>
<div class="row">
	<label class="field">結束時間
	</label>
	<label class="field_content">
		{$activity.endTime}
	</label>
</div>
<div class="row">
	<label class="field">限制人數
	</label>
	<label class="field_content">
		{$activity.maxNum}
	</label>
</div>
<div class="row">
	<label class="field">活動詳情
	</label>
	<label class="field_content">
		{$activity.detail}
	</label>
</div>
<hr class="hrline"/>
<div class="row">
	<label class="field">報名人員
	</label>
	<label class="field_content" id="signUsers">
		{$activity.signUsers}</br>
		共&nbsp;{$activity.totalNum}&nbsp;人
	</label>
</div>
相關文章
相關標籤/搜索