Excuse me guys,
I need help do anyone know there is my mistake?
i already seeing it again and again but don’t know where is the problem
7002
Here is my ProductController.php
<?php
class ProductController extends Controller {
public $layout = "admin_page";
const URLUPLOAD = '/../images/products/';
public function actionReview($id) {
$this -> render('review',
array('model' => $this -> loadModel($id),
)
);
}
public function actionCreate() {
$model = new Product;
if (isset($_POST['Product'])) {
$cekfile = $model -> image =
CUploadedFile::getInstance($model, 'image');
$model -> attributes = $_POST['Product'];
$model -> image = CUploadedFile::getInstance($model,'image');
if ($model -> save()) {
if (!empty($cekfile)) {
$model -> image -> saveAs(Yii::app() -> basePath .
self::URLUPLOAD . $model -> image . '');
copy(Yii::app() -> basePath . self::URLUPLOAD .
$model -> image, Yii::app() -> basePath .
self::URLUPLOAD . 'thumbs/' . $model -> image);
$name = getcwd() . '/images/products/thumbs/' .
$model -> image;
$image = Yii::app() -> image -> load($name);
$image -> resize (93, 0);
$image -> save();
}
$this->redirect(array('review','id'=>$model->id));
}
}
$this -> render ('create',
array('model' => $model,
)
);
}
public function actionUpdate($id) {
$model = $this -> loadModel($id);
$image = $model -> image;
if (isset($_POST['Product'])) {
$cekfile = $model -> image =
CUploadedFile::getInstance($model, 'image');
if (empty($cekfile)) {
$model -> attributes = $_POST['Product'];
$model -> image = $image;
if ($model -> save()) {
$this -> redirect(array('review', 'id' => $model -> id));
}
} else {
$model -> attribute = $_POST['Product'];
$model -> image = CUploadedFile::getInstance($model, 'image');
if ($model -> save()) {
$model -> image -> saveAs(Yii::app() -> basePath .
'/../images/products/' . $model -> image .'');
copy(Yii::app() -> basePath . self::URLUPLOAD .
self::URLUPLOAD . 'thumbs/' . $model -> image);
$nama = getcwd() . '/images/products/thumbs/' . $model->image;
$image = Yii::app() -> image -> load($name);
$image -> resize(93, 0);
$image -> save();
}
}
}
$this -> render('update',
array('model' => $model,
)
);
}
public function actionDelete($id) {
if (Yii::app() -> request -> isPostRequest) {
// delete produk
$this -> loadModel($id) -> delete();
if (!isset($_GET['ajax']))
$this -> redirect(isset($_POST['returnUrl']) ?
$_POST['returnUrl'] : array('admin'));
} else
throw new CHttpException(400,
'Invalid request. Please do not repeat this request again.');
}
public function actionAdmin() {
$model = new product ('search');
$model -> unsetAttributes();
if (isset($_GET['Product'])) {
$model -> attributes = $_GET['Product'];
}
$this -> render('admin', array('model' => $model, ));
}
public function loadModel($id) {
$model = Product::model() -> findByPk($id);
if ($model === null)
throw new CHttpException(404,
'The requested page does not exist.');
return $model;
}
protected function performAjaxValidation($mode) {
if (isset($_POST['ajax']) &&
$_POST['ajax'] === 'product-form') {
echo CActiveForm::validate($model);
Yii::app() -> end();
}
}
public function actionIndex() {
$this -> layout= 'store';
$criteria = new CDbCriteria( array('order' => 'id DESC', ));
$count = Product::model() -> count($criteria);
$pages = new CPagination($count);
$pages -> pageSize = 8;
$pages -> applyLimit($criteria);
$models = Product::model() -> cache(1000) ->
findAll($criteria);
$this -> render(
'index',
array(
'models' => $models,
'pages' => $pages,
)
);
}
}
?>
this is my create.php
<h3>Create Product</h3>
<?php echo $this->renderPartial('_form',
array('model'=>$model)); ?>
this is my _form.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'product-form',
'htmlOptions'=>array('enctype' => 'multipart/form-data'),
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with
<span class="required">*</span> are require</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'product_name'); ?>
<?php echo $form->textField($model,'product_name',
array('size'=>60,'maxlength'=>555)); ?>
<?php echo $form->error($model,'product_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'category_id'); ?>
<?php echo $form->dropDownList($model,'category_id',
CHtml::listData(Category::model()->findAll(), 'id',
'category_name'), array('empty'=>'--please select--'));
?>
<?php echo $form->error($model,'category_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'price'); ?>
<?php echo $form->textField($model, 'price'); ?>
<?php echo $form->error($model, 'price'); ?>
</div>
<?php if(!empty($model->image)){?>
<div class="row">
<?php echo CHtml::image(Yii::app()->request->baseUrl.
'/images/products'.$model->image.'','image',
array("style"=>"width:93px;"));?>
</div>
<?php } ?>
<div class="row">
<?php echo $form->labelEx($model, 'image');?>
<?php echo $form->fileField($model,
'image',array('size'=>60,'maxlength'=>555));?>
<?php echo $form->error($model, 'image');?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'description');?>
<?php echo $form->textArea($model, 'description',
array('cols'=>50,'row'=>5,'maxlength'=>555));?>
<?php echo $form->error($model, 'description');?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ?
'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
and index.php
<?php
$this -> breadcrumbs = array('Products', );
?>
<?php
$i=1;
foreach($models as $data):
if($i%2==0) {$class="rightbox";}else{$class="leftbox";}
?>
<div style="height:170px; text-align:justify; padding-right:
3px ;margin-left:5px;margin-bottom:5px;border:1px solid #CCC;"
class="<?php echo $class; // tampilkan class css?>">
<div style="height: 130px;">
<h3 style="float:left; margin-right: 15px;
padding-right:12px; ">
<?php echo $data -> product_name; ?>
</h3>
<?php
echo CHtml::image(Yii::app() -> request -> baseUrl .
'/images/products/thumbs/' . $data -> image . '', '',
array("style" => "margin-left:0px;padding:10px;clear:left;",
"class" => "left",
));
?>
<br><br>
<b>Price:</b>
<b>IDR <?php echo $data -> price_product; ?></b>
<p style="margin-left: 15px;">
<?php echo substr($data -> description, 0, 100); ?>
</p>
<div class="clear"></div>
<div style="position:; margin-top: 50px;">
</div>
<br>
</div>
<p class="readmore" style="float: right; position:; margin-
right:11px; margin-bottom: 5px; margin-top: 0px;">
<?php
if (!Yii::app() -> user - isGuest) {
echo CHtml::link(CHtml::encoder("Update"),
array('update', 'id' =>$data -> id));
}
?>
<?php echo CHtml::link(CHtml::encode("Beli"),
array('addtocart',
'id' => $data -> id,
'p' => $data ->product_name
)); ?>
<?php echo CHtml::link(CHtml::encode("Detail"), array('view',
'id'
=> $data -> id,
'p'=>$data->product_name
)); ?>
</p>
</div>
<?php $i++; endforeach;?>
<div style="float: right; margin-top: 5px; margin-bottom: 7px;
margin-right: 18px;clear: both;">
<?php $this->widget('CLinkPager', array(
'pages' => $pages;
'header' => '',
'firstPageLabel' => '| <',
'lastPageLabel' => '> |',
'nextPageLabel' => '>',
'prevPageLabel' => '<',
'maxButtonCount' => 5,
))
?>
</div>