soopers Posted July 21, 2014 Share Posted July 21, 2014 hello dears.I am currently working on a project in which I want to use the Search() as just like we use with Gridview (admin view that gii generates by default.). But I want to display my search result on some other page.here is my code.Search code on index page. <?php $this->renderPartial('_search', array( 'model' => $model, )); ?> <?php Yii::app()->clientScript->registerScript('my-list-search', " $('.search-button').click(function(){ $('.search-form').toggle(); return false; }); $('.search-form form').submit(function(){ $.fn.yiiListView.update('itemslistview', { data: $(this).serialize() }); return false; }); "); ?> and I want to display its result on the some other page e.g. search_result.php <?php $this->widget('zii.widgets.CListView', array( 'id' => 'itemslistview', 'dataProvider' => $model->search(), 'summaryText' => '', 'itemView' => '_products', 'enablePagination' => false, )); ?> and here is search() public function search() { // @todo Please modify the following code to remove attributes that should not be searched. $criteria = new CDbCriteria; $criteria->compare('id', $this->id); $criteria->compare('language', $this->language, true); $criteria->compare('seller_id', $this->seller_id); $criteria->compare('category_id', $this->category_id); $criteria->compare('title', $this->title, true); $criteria->compare('detail', $this->detail, true); $criteria->compare('tags', $this->tags, true); $criteria->compare('url', $this->url, true); $criteria->compare('vehicle_type', $this->vehicle_type); $criteria->compare('brand_id', $this->brand_id); $criteria->compare('model_id', $this->model_id); $criteria->compare('year', $this->year); $criteria->compare('code', $this->code, true); $criteria->compare('image', $this->image, true); $criteria->compare('price', $this->price, true); $criteria->compare('is_new', $this->is_new, true); $criteria->compare('in_stock', $this->in_stock, true); $criteria->compare('is_featured', $this->is_featured, true); $criteria->compare('is_blocked', $this->is_blocked, true); $criteria->compare('status', $this->status); $criteria->compare('viewed', $this->viewed); $criteria->compare('last_modified', $this->last_modified, true); $criteria->compare('create_date', $this->create_date, true); return new CActiveDataProvider($this, array( 'criteria' => $criteria, )); } but it is not working.How can I solve my problem ? Thanks in advance. Link to comment Share on other sites More sharing options...
Larry Posted July 29, 2014 Share Posted July 29, 2014 The principle is that you'd use the search() method to return a data provider that can be used in your view file. In the grid is one way to use it, but you can use it directly in a view file or use a different type of widget. Link to comment Share on other sites More sharing options...
Recommended Posts