tag:blogger.com,1999:blog-5257555736106762701.post6608536721721868293..comments2024-02-15T05:46:49.798-08:00Comments on Learn Yii: How to implement simple and easy search functionality on an index pageNeil McGuiganhttp://www.blogger.com/profile/14122981831780837323noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-5257555736106762701.post-13446419778776334632015-06-25T23:08:21.900-07:002015-06-25T23:08:21.900-07:00attribute1 and attribute2 refers to fields in your...attribute1 and attribute2 refers to fields in your table of your database. Suppose you are to compare 'title' and 'detail' of your table with the passed parameter 'q' then you write. <br />$criteria= new CDbCriteria();<br />$criteria->compare('title', $q, true, 'OR');<br />$criteria->compare('detail', $q, true, 'OR');<br /><br />this compares your variable $q 's value to 'title' and 'detail' fields in your table.<br /><br />Anonymoushttps://www.blogger.com/profile/09179433321824601749noreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-7121416456862272922013-07-30T04:48:29.439-07:002013-07-30T04:48:29.439-07:00Thanks a lot...nice work..Thanks a lot...nice work..Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-78770384615889653652013-04-26T12:54:15.041-07:002013-04-26T12:54:15.041-07:00Thanks so much :) youre the bestThanks so much :) youre the bestAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-38962526422241973492012-12-07T02:19:08.809-08:002012-12-07T02:19:08.809-08:00helpp helpp Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-79450733986015809892012-11-19T12:05:22.529-08:002012-11-19T12:05:22.529-08:00Thanks! very helpful!Thanks! very helpful!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-15137622104763746732012-10-23T10:02:36.004-07:002012-10-23T10:02:36.004-07:00how does the redirect work, after clicking search ...how does the redirect work, after clicking search button?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-7695750494771234132012-08-02T16:23:57.137-07:002012-08-02T16:23:57.137-07:00can you please explain the code as where is which ...can you please explain the code as where is which code supposed to be .. please i am really new and i need to implement this .. just dont know where to put what ... thanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-48316039718934353322012-05-28T03:02:04.022-07:002012-05-28T03:02:04.022-07:00great Nishogreat NishoAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-24008088208429004072012-02-02T14:52:15.503-08:002012-02-02T14:52:15.503-08:00this is a bad solution.. Yii model have a search()...this is a bad solution.. Yii model have a search() function that return criteria for searching. We can use this in most component like ListView or GridView.<br /><br />Controller action<br /><br /> /**<br /> * Lists all models.<br /> */<br /> public function actionIndex() {<br /> $model = new MyModel('search');<br /> $model->unsetAttributes(); // clear any default values<br /> if (isset($_GET['MyModel']))<br /> $model->attributes = $_GET['MyModel'];<br /> <br /> $this->render('index', array(<br /> 'model' => $model,<br /> ));<br /> }<br /><br /><br />View page<br /><br /> <!-- render search form --><br /> <?php echo CHtml::link(Yii::t('app','Advanced search'),<br /> '#',array('class'=>'search-button')); ?><br /> <div class="search-form" style="display:none"><br /> <?php $this->renderPartial('_search',array(<br /> 'model'=>$model,<br /> )); ?><br /> </div><!-- search-form --><br /><br /> <!-- render list of MyModel --><br /> <?php $this->widget('zii.widgets.CListView', array(<br /> 'id'=>'my-list',<br /> 'dataProvider'=>$model->search(),<br /> 'sortableAttributes'=>array(<br /> 'name',<br /> 'description'<br /> ), <br /> 'itemView'=>'_view',<br /> )); ?><br /><br /> <!-- easy script for update list with search parameter !--><br /> Yii::app()->clientScript->registerScript('my-list-search', "<br /> $('.search-button').click(function(){<br /> $('.search-form').toggle();<br /> return false;<br /> });<br /> $('.search-form form').submit(function(){<br /> $.fn.yiiListView.update('my-list', {<br /> data: $(this).serialize()<br /> });<br /> return false;<br /> });<br /> ");Nishonoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-25809373213891873142011-11-26T00:18:24.177-08:002011-11-26T00:18:24.177-08:00if i have more pages on results... when i click an...if i have more pages on results... when i click another page the results are reseted and it show all the items from that table...<br />how can i fix that?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-11760663154259865582011-11-22T19:19:23.121-08:002011-11-22T19:19:23.121-08:00I second this: How can I do this in a many-to-many...I second this: How can I do this in a many-to-many table am passing a variable cat_id via get and I have three tables on post, category and post_category(which has ids post_id and cat_id) but I want to select the post corresponding to a certain category.wtfbrbhttps://www.blogger.com/profile/04962988467033965381noreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-42369100946116194892011-09-10T07:14:49.385-07:002011-09-10T07:14:49.385-07:00Thanks for the simple, yet powerful, implementatio...Thanks for the simple, yet powerful, implementation. Would serve the purpose of majority of the websitesMukeshhttp://twitter.com/mukeshsoninoreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-80465888136236491062011-08-21T08:46:30.424-07:002011-08-21T08:46:30.424-07:00Hi,
what does it means $criteria->compar...Hi,<br /><br />what does it means $criteria->compare('attribute1', $q, true, 'OR');<br />$criteria->compare('attribute2', $q, true, 'OR');<br /><br />what is attribute1, 2?<br />how it search in database?<br /><br />It shouldn't be something like LIKELaborator Informatica Aplicatahttps://www.blogger.com/profile/11729763859218044340noreply@blogger.comtag:blogger.com,1999:blog-5257555736106762701.post-37324794152584434712011-07-29T14:06:51.525-07:002011-07-29T14:06:51.525-07:00How can I do this in a many-to-many table am passi...How can I do this in a many-to-many table am passing a variable cat_id via get and I have three tables on post, category and post_category(which has ids post_id and cat_id) but I want to select the post corresponding to a certain category.Anonymousnoreply@blogger.com