<h1>Danh bạ khách sạn</h1> </div><!--/.page-header--> <div class="row-fluid"> <div class="span12"> <a href="<?php echo PIUrl::createUrl('/admin/hotel/create/'); ?> " class="btn btn-primary"> <i class="icon-ok bigger-110"></i> <?php echo translate('Thêm'); ?> </a> <form method="post"> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'hotel-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'htmlOptions' => array(), 'itemsCssClass' => 'table table-striped table-bordered table-hover', 'emptyText' => 'Không có kết quả hiển thị', 'selectableRows' => 2, 'summaryText' => 'Hiển thị {start} - {end} của {count} kết quả ', 'columns' => array(array('id' => 'id', 'class' => 'CCheckBoxColumn'), array('header' => 'STT', 'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)'), 'image' => array('name' => 'image', 'type' => 'raw', 'filter' => false, 'value' => 'CHtml::image(getImage($data->image,"80", "60" ))', 'htmlOptions' => array("class" => "image")), 'name', 'type' => array('name' => 'type', 'type' => 'raw', 'filter' => CHtml::dropDownList('Hotel[type]', '', Hotel::model()->getTypeHotel()), 'value' => 'Hotel::model()->getType($data->type)'), 'pro.title' => array('name' => 'provinces', 'type' => 'raw', 'value' => 'isset($data->pro->title) ? $data->pro->title : ""', 'filter' => CHtml::dropDownList('Hotel[provinces]', '', Provinces::model()->getData())), 'ward.title' => array('name' => 'wards', 'type' => 'raw', 'value' => 'isset($data->ward->title) ? $data->ward->title : ""', 'filter' => CHtml::dropDownList('Hotel[wards]', '', Wards::model()->getData())), 'address' => array('name' => 'address', 'type' => 'raw', 'value' => '$data->address', 'filter' => false), array('header' => '<input type="button" name="deleteAll" class="deleteAll btn btn-mini btn-danger icon-trash bigger-120" value="Xóa" />', 'class' => 'CButtonColumn', 'template' => '{update}{delete}', 'buttons' => array('update' => array('options' => array('class' => 'btn btn-mini btn-info icon-edit bigger-120', 'title' => 'Sửa tin tức'), 'imageUrl' => false, 'label' => false), 'delete' => array('label' => false, 'options' => array('class' => 'btn btn-mini btn-danger icon-trash bigger-120', 'title' => 'Xóa tin tức'), 'imageUrl' => false)), 'deleteConfirmation' => 'Bạn có muốn xóa tin tức này không?')))); ?> </form> </div><!--/.span--> </div><!--/.row-fluid--> </div><!--/.page-content--> </div><!--/.main-content--> <style> .grid-view .filters input, .grid-view .filters select { width: 92%; } .image img{ width:80px; height:60px; } .btn-info{margin-right:3px;}
public function loadModel($id) { $model = Provinces::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function getData() { $data = Provinces::model()->findALl(); $result = array(); $result[''] = '-- chọn tỉnh/thành phố --'; foreach ($data as $dt) { $result[$dt->id] = $dt->title; } return $result; }
public function actionUpdate($id = null) { $model = Wards::model()->findByPk($id); if (!empty($_POST['Wards'])) { $model->attributes = $_POST['Wards']; $model->province_id = $_POST['Wards']['province_id']; if ($model->save()) { Yii::app()->user->setFlash('success', translate('Cập nhập thành công.')); $this->redirect(PIUrl::createUrl('/admin/Wards/')); } } $dataProvinces = Provinces::model()->getData(); $this->render('update', array('model' => $model, 'dataProvinces' => $dataProvinces)); }
public function actionUpdate($id = null) { $model = Hotel::model()->findByPk($id); $flag = 0; $image_old = $model->attributes['image']; if (!empty($_POST['Hotel'])) { if (!empty(CUploadedFile::getInstance($model, 'image')->name)) { $image_old = $model->attributes['image']; $path = realpath(Yii::app()->basePath . '/../upload/images/' . $image_old); if (file_exists($path) && !empty($image_old)) { unlink($path); } $model->attributes = $_POST['Hotel']; $model->image = CUploadedFile::getInstance($model, 'image'); $image = $model->image; $imageType = explode('.', $model->image->name); $imageType = $imageType[count($imageType) - 1]; $imageName = md5(uniqid()) . '.' . $imageType; $model->image = $imageName; $images_path = Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName; $flag = 1; } else { $model->attributes = $_POST['Hotel']; $model->image = $image_old; } $model->provinces = $_POST['provinces']; $model->wards = $_POST['wards']; $model->created = time(); $model->alias = alias($_POST['Hotel']['name']); if ($model->save()) { Yii::app()->user->setFlash('success', translate('Cập nhập khách sạn thành công.')); if ($flag == 1) { $image->saveAs($images_path); } $this->redirect(PIUrl::createUrl('/admin/hotel/')); } } $criteria = new CDBCriteria(); $criteria->select = "id, title"; $provinces = Provinces::model()->findAll($criteria); $ward = new Wards(); $wards = $ward->getWards($model->provinces); $typeHotel = Hotel::model()->getTypeHotel(); $this->render('update', array('model' => $model, 'provinces' => $provinces, 'wards' => $wards, 'typeHotel' => $typeHotel)); }