Hello everyone,
i am still a Yii-Beginner and i was trying to write an small search-portlet as an extension to the blog-demo.
At first, i added a SiteSearchPortlet.php to protected/components :
protected/components/SiteSearchPortlet.php:
<?php class SiteSearchPortlet extends Portlet { public function renderContent() { $form = new SiteSearchForm(); $this->render('siteSearch',array('form'=>$form)); } } ?>
Then i added a small view for this Portlet:
protected/components/views/siteSearch.php :
<?php echo CHtml::beginForm(); ?> <div class="row"> <?php echo CHtml::activeTextField($form,'search_string') ?> <?php echo CHtml::error($form,'search_string'); ?> <?php echo CHtml::submitButton('Start Search'); ?> </div> <?php echo CHtml::endForm(); ?>
At last, i wanted to set up the Model Logic:
protected/models/SiteSearchForm.php :
<?php class SiteSearchForm extends CFormModel { public $search_string; public function rules() { return array( array('searchstring', 'required'),); } public function actionSearch() { $condition = new CdbCriteria; $params = array(); $posts=Post::model()->findAll($condition,$params); print_r($posts); // Stuck here } }
Now i have some trouble to understand, how Yii determines, which function is called, after the Submit-Button is pushed. After that, i just want to display these posts, that have ‘content like “%search_string%”’ as a CdbCriteria. Could some of you Yii-Experts give me an hint