PDA

View Full Version : delete در gridview



desatir7316
سه شنبه 26 فروردین 1393, 21:40 عصر
سلام دوستان
وقتی می خوام توی gridview حدف کنم میره به آدرس item/delete/1 و دیگه از post استفاده نمی کنه
چطور می تونم درستش کنم
ممنون

MMSHFE
سه شنبه 26 فروردین 1393, 23:24 عصر
کد ویو و کنترلر رو بگذارین. متد performAjaxValidation رو که حذف نکردین؟

desatir7316
چهارشنبه 27 فروردین 1393, 00:02 صبح
نه حذف نکردم

کنترلر:


<?php
class CategoryController extends Controller{ public $pageTitle = 'فروشگاه هنرهای دستی'; /** * @var string the default layout for the views. Defaults to '//layouts/column2', meaning * using two-column layout. See 'protected/views/layouts/column2.php'. */ public $layout='//layouts/column2';
/** * @return array action filters */ public function filters() { return array( 'accessControl', // perform access control for CRUD operations 'postOnly + delete', // we only allow deletion via POST request ); }


/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $categoryList = Category::model()->getCategoryList(); $this->pageTitle ='بخش '. $categoryList[$id]['name']; foreach ($categoryList as $key => $value) { $categoryList[$key]['itemCount'] = Category::model()->findByPk($categoryList[$key]['category_id'])->itemCount; } $items = Item::model()->getItemList($id); $this->render('view',array( 'model'=>$this->loadModel($id), 'items'=>$items, 'categoryList'=>$categoryList, )); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new Category;
// Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model);
if(isset($_POST['Category'])) { $model->attributes=$_POST['Category']; if($model->save()){ $this->addCategoryDir(); $this->redirect(array('view','id'=>$model->category_id)); } } $this->render('create',array( 'model'=>$model, )); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model);
if(isset($_POST['Category'])) { $model->attributes=$_POST['Category']; if($model->save()) $this->redirect(array('view','id'=>$model->category_id)); }
$this->render('update',array( 'model'=>$model, )); }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $this->loadModel($id)->delete(); $this->removeCategoryDir(Yii::app()->basePath . '/../images/categories/' . $id); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if(!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); }
/** * Lists all models. */ public function actionIndex() { $mostViewed = Item::model()->getMostViewed(); $mostBuyed = Item::model()->getMostBuyed(); $newest = Item::model()->getNewest(); $categoryList = Category::model()->getCategoryList(); foreach ($categoryList as $key => $value) { $categoryList[$key]['itemCount'] = Category::model()->findByPk($categoryList[$key]['category_id'])->itemCount; } $this->render('index',array( 'categoryList'=> $categoryList, 'mostViewed' => $mostViewed, 'mostBuyed' => $mostBuyed, 'newest' => $newest, )); }
/** * Manages all models. */ public function actionAdmin() { $this->pageTitle = 'مدیریت گروه ها'; $category= new Category; if(isset($_POST['Category'])){ $category->attributes = $_POST['Category']; if($category->save()) $this->addCategoryDir(); } $model=new Category('search'); $model->unsetAttributes(); // clear any default values if(isset($_GET['Category'])) $model->attributes=$_GET['Category'];
$this->render('admin',array( 'model'=>$model, 'category'=>$category, )); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Category the loaded model * @throws CHttpException */ public function loadModel($id) { $model=Category::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
/** * Performs the AJAX validation. * @param Category $model the model to be validated */ protected function performAjaxValidation($model) { if(isset($_POST['ajax']) && $_POST['ajax']==='category-form') { echo CActiveForm::validate($model); Yii::app()->end(); } } protected function addCategoryDir() { $model = new Category; $model->image=CUploadedFile::getInstance($model,'image'); $lastId = Yii::app()->db->getLastInsertID (); $imageDir = Yii::app()->basePath . '/../images/categories/' ; mkdir($imageDir . $lastId); $model->image->saveAs($imageDir . $lastId . '.jpg'); } protected function removeCategoryDir($dir) { foreach(scandir($dir) as $file) { if ('.' === $file || '..' === $file) continue; if (is_dir("$dir/$file")) $this->removeCategoryDir("$dir/$file"); else unlink("$dir/$file"); } rmdir($dir); unlink($dir. '.jpg'); }}


ویو:

<?php/* @var $this CategoryController *//* @var $model Category */
$this->breadcrumbs=array( 'مدیرت دسته بندی ها',);
$this->menu=array( array('label'=>'مشاهده سایت', 'url'=>array('/category/index')),);
Yii::app()->clientScript->registerScript('search', "$('.search-button').click(function(){ $('.search-form').toggle(); return false;});$('.search-form form').submit(function(){ $('#category-grid').yiiGridView('update', { data: $(this).serialize() }); return false;});");?><h4>ایجاد گروه جدید</h4>
<?php $this->renderPartial('/category/_form', array( 'model'=>$category,));?><br /><hr /><br /><h4>مدیریت گروه ها</h4>
<!--<p>You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.</p>-->
<?php echo CHtml::link('جستجوی پیشرفته','#',array('class'=>'search-button')); ?><div class="search-form" style="display:none"><?php $this->renderPartial('_search',array( 'model'=>$model,)); ?></div><!-- search-form -->
<div style="direction:rtl" class="well"><?php $this->widget('bootstrap.widgets.TbGridView', array( 'summaryText' => 'نمایش {start}-{end} از {count}', 'type'=>'striped bordered condensed', 'id'=>'category-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'htmlOptions'=>array('style'=>'text-align:center',), 'columns'=>array( array( 'header'=>'ردیف', 'name'=>'category_id', 'filter'=>CHtml::textField('Category[category_id]', '', array('style'=>'padding-left:0;padding-right:0')), 'htmlOptions'=>array('width'=>'20px','style'=>'text-align:right'), 'headerHtmlOptions'=>array('style'=>'text-align:center'), ), array( 'header'=>'گروه', 'name'=>'name', 'filter'=>CHtml::textField('Category[name]', '', array('style'=>'padding-left:0;padding-right:0')), 'type'=>'raw', 'value'=>'CHtml::link("$data->name",Yii::app()->createUrl("/item/admin",array("category_id"=>$data->category_id)))',// 'value'=>'CHtml::link("$data->name",Yii::app()->createUrl("/item/admin"),array("submit"=>Yii::app()->createUrl("/item/admin"),"params"=>array("category_id"=>$data->category_id)))', 'htmlOptions'=>array('width'=>'200px','style'=>'text-align:right'), 'headerHtmlOptions'=>array('style'=>'text-align:center'), ), array( 'class'=>'bootstrap.widgets.TbButtonColumn', 'template'=>'{view}{update}{delete}', 'header'=>'مدیریت گروه ها', 'htmlOptions'=>array('width'=>'100px','style'=>'text-align:center;'), 'buttons'=>array( 'value'=>'test', 'type'=>'raw', 'delete'=>array( 'label'=>'حذف(به همراه زیرگروه ها)', ), 'update'=>array( 'label'=>'ویرایش', ), 'view'=>array( 'label'=>'مشاهده', ), ), ), ),)); ?></div>


نمی دونم چرا بعد از آپ دیت سایت برنامه نویس، همش متن هام اینجوری بهم میریزن
راه حلی هم داره
باید وایسم خط به خط همیشه درستش کنم

MMSHFE
چهارشنبه 27 فروردین 1393, 10:23 صبح
باید صبر کنید ادیتور کامل بارگذاری بشه، بعد متنتون رو بنویسید. لطفاً مجدداً ویرایش کنید تا کدها درست دیده بشه.

desatir7316
چهارشنبه 10 اردیبهشت 1393, 12:48 عصر
سلام
ببخشید که دیر پیگیری کردم، مرخصیم تموم شد و مجبور شدم برم
ولی توی این مدت متوجه یه چیزی شدم، بعد از کاری که با assetManager کردم (http://barnamenevis.org/showthread.php?448474-assetManager&p=2007748#post2007748) این مشکلات به وجود اومد، بعدا که درسترسی به اینترنت نداشتم، رفتم پروژه رو توی یه سیستم دیگه اجرا کردم دیدم بدون مشکل کار می کنه
الان هم مشکلی که پیش اومده اینه که توی view ها جای footer با slider عوض می شه ولی فقط روی سیستم خودم اینجوری
نمی دونم چرا اینجوری شده، یکارش باید کرد؟
ممنون

desatir7316
چهارشنبه 10 اردیبهشت 1393, 21:16 عصر
الان هم مشکلی که پیش اومده اینه که توی view ها جای footer با slider عوض می شه ولی فقط روی سیستم خودم اینجوری
نمی دونم چرا اینجوری شده، یکارش باید کرد؟

دوستان چی کار باید بکنم؟

MMSHFE
پنج شنبه 11 اردیبهشت 1393, 11:06 صبح
روی سیستم خودتون با تمام مرورگرها اینطوریه؟

desatir7316
پنج شنبه 11 اردیبهشت 1393, 12:33 عصر
آره
asset ها هم پاک می کنم و اجرا می کنم بازم فرقی نمی کنه

MMSHFE
پنج شنبه 11 اردیبهشت 1393, 13:11 عصر
جالبه. میتونید تیم ویور بدین؟

desatir7316
پنج شنبه 11 اردیبهشت 1393, 13:37 عصر
آخه asset ها رو پاک کردم، یه سیستم عامل به صورت virtual نصب کردم، یه بار اونجا اجراش کردم ، بعد با assetهای جدید اوردم اینور ، الان درسته
ولی یکی این مشکل، یکی هم اون که حذف نمی کرد روی سیستم خودم برام جالبته
اون موقع که اونجوری بود، یه بار هم پوشه فریم ورک رو از اول ریختم ، گفتم شاید موردی پیش اومده باشه ولی از اونم نبود
نمی دونم قضیه چیه...

MMSHFE
پنج شنبه 11 اردیبهشت 1393, 13:44 عصر
منم اینطوری متوجه نمیشم و چندباری هم هست که میبینم درمقابل تیم ویور دادن مقاومت عجیبی دارین. بهرصورت از راه دور بیشتر از این نمیتونم راهنمایی کنم چون برای حل مشکل اول باید مشکل رو کامل بشناسم و این مسئله بستگی به تنظیمات سیستمتون (PHP و...) هم میتونه داشته باشه و از کدها هم ممکنه باشه.

desatir7316
پنج شنبه 11 اردیبهشت 1393, 13:51 عصر
نه با تیم ویور که مشکلی نیست ولی وقتی فقط روی سیستم خودم اینجوریه پس از کد ها که نیست
فقط می تونه از تنظیمات php باشه که من اونارو دست کاری نکردم ولی برای احتیاط همه رو یه بار reset میکنم به پیشفرض

MMSHFE
پنج شنبه 11 اردیبهشت 1393, 14:01 عصر
شاید هم یکی از فایلهای هسته Yii رو تغییر داده باشین.

desatir7316
پنج شنبه 11 اردیبهشت 1393, 14:30 عصر
آخه من کل فریم ورک رو یه بار دیگه کپی کردم، ولی از اون نبود
جالب ترینش اون مشکل حذف کردن بود که با system restore درست شد !!!!