wonder what is wrong with that?. it appears when i search something with my search widget
wonder what is wrong with that?. it appears when i search something with my search widget
It happens because you pass a non object to the view. Maybe your search returned nothing and so you are passing a null instead of an object.
What exactly are you doing in your code?
Also use error_reporting(E_ALL) when programming, this will give you more clear messages.
SiteSearch.php [widget]
<?php
class SiteSearch extends CWidget {
public $title='Site Search';
public function run() {
$form = new SiteSearchForm();
$this->render('siteSearch', array('form'=>$form));
}
}
siteSearch.php [widget view]
<?php $url = $this->getController()->createUrl('search'); ?>
<?php echo CHtml::beginForm($url); ?>
<div class="row">
<?php echo CHtml::activeTextField($form,'string') ?>
<?php echo CHtml::error($form,'string'); ?>
<?php echo CHtml::SubmitButton('Search'); ?>
</div>
<?php error_reporting(E_ALL); ?>
<?php echo CHtml::endForm(); ?>
SiteSearchForm.php [model]
<?php
class SiteSearchForm extends CFormModel
{
public $string;
public function rules() {
return array(array('string', 'required'));
}
public function safeAttributes() {
return array('string',);
}
}
primary model: [exerpt]
public function rules()
{
return array(
array('title','length','max'=>255),
array('subheader','length','max'=>255),
array('streamurl','length','max'=>255),
array('thumbnail','length','max'=>255),
array('promoimage','length','max'=>255),
array('title, description, streamurl, price, airdate', 'required'),
array('price', 'type', 'type'=>'float'),
array('publish', 'numerical', 'integerOnly'=>true),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => Yii::t('admin','Id'),
'title' => Yii::t('admin','Title'),
'subheader' => Yii::t('admin','Subheader'),
'description' => Yii::t('admin','Description'),
'streamurl' => Yii::t('admin','Streamurl'),
'price' => Yii::t('admin','Price'),
'thumbnail' => Yii::t('admin','Thumbnail'),
'promoimage' => Yii::t('admin','Promoimage'),
'airdate' => Yii::t('admin','Airdate'),
'publish' => Yii::t('admin','Publish'),
);
}
Controller.php [primary model controller] search function
/**
* Sitewide search.
*/
/**
* Shows a particular post searched.
*/
public function actionSearch()
{
$search=new SiteSearchForm;
if(isset($_POST['SiteSearchForm'])) {
$search->attributes=$_POST['SiteSearchForm'];
$criteria=new CDbCriteria;
$criteria->condition='publish=1';
$criteria->compare('title',$event->title, 'OR');
$criteria->compare('subheader',$event->subheader, 'OR');
$criteria->compare('description',$event->description, 'OR');
$criteria->compare('streamurl',$event->streamurl, 'OR');
$criteria->compare('price',$event->price, 'OR');
$criteria->compare('thumbnail',$event->thumbnail, 'OR');
$criteria->compare('airdate',$event->airdate, 'OR');
/* $find = Event::model()->findAll($criteria);
*/
$postCount=Event::model()->count($criteria);
$posts=Event::model()->findAll($criteria);
$this->render('search',array(
'posts'=>$posts,
'search'=>$search,
));
}
}
view
<?php if(!empty($_GET['tag'])): ?>
<h3>Posts Tagged with "<?php echo CHtml::encode($_GET['tag']); ?>"</h3>
<?php endif; ?>
<?php if(!empty($search->string)): ?>
<h3>Events Searched by "<?php echo CHtml::encode($search->string); ?>"</h3>
<?php endif; ?>
<?php foreach($posts as $post): ?>
<?php $this->renderPartial('_search',array(
'post'=>$post,
)); ?>
<?php endforeach; ?>
<br/>
<?php $this->widget('CLinkPager',array('pages'=>$pages)); ?>
_view
<div class="wide form">
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'post',
)); ?>
<div class="row">
<?php echo $form->label($model,'id'); ?>
<?php //echo $form->textField($model,'id'); ?>
</div>
<div class="row">
<?php echo $form->label($model,'title'); ?>
<?php //echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
</div>
<div class="row">
<?php echo $form->label($model,'sport_name'); ?>
<?php //echo $form->textField($model,'sport_name',array('size'=>40,'maxlength'=>40)); ?>
</div>
<div class="row">
<?php echo $form->label($model,'subheader'); ?>
<?php //echo $form->textField($model,'subheader',array('size'=>60,'maxlength'=>255)); ?>
</div>
<div class="row">
<?php echo $form->label($model,'description'); ?>
<?php //echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
</div>
<div class="row">
<?php echo $form->label($model,'streamurl'); ?>
<?php //echo $form->textField($model,'streamurl',array('size'=>60,'maxlength'=>255)); ?>
</div>
<div class="row">
<?php echo $form->label($model,'price'); ?>
<?php //echo $form->textField($model,'price'); ?>
</div>
<div class="row">
<?php echo $form->label($model,'thumbnail'); ?>
<?php //echo $form->textField($model,'thumbnail',array('size'=>60,'maxlength'=>255)); ?>
</div>
<div class="row">
<?php echo $form->label($model,'promoimage'); ?>
<?php //echo $form->textField($model,'promoimage',array('size'=>60,'maxlength'=>255)); ?>
</div>
<div class="row">
<?php echo $form->label($model,'airdate'); ?>
<?php //echo $form->textField($model,'airdate'); ?>
</div>
<div class="row">
<?php echo $form->label($model,'publish'); ?>
<?php //echo $form->textField($model,'publish'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
sorry if i needed to post all my code… i really have no idea… i’m new to this… and it’s kinda rush.
You are using activeTextField() in siteSearch.php for string… use instead textField()
activeTextField - http://www.yiiframew…extField-detail
textField - http://www.yiiframework.com/doc/api/CHtml#textField-detail
Object of class SiteSearchForm could not be converted to string… ?_?
ups…
I whould debug like that:
probably this error arrives from a <?php echo $form->label($model,‘description’); ?>
Try to comment the render of views, in order to find from wich view arrives the error.
when you analize the view, make sure that the model you are passing is a real model and not an empty variable.
put error_reporting(E_ALL); in index.php, before calling Yii::createWebApplication();
Good hunt!!
i commented out
/* $criteria->compare('title',$event->title, 'OR');
$criteria->compare('subheader',$event->subheader, 'OR');
$criteria->compare('description',$event->description, 'OR');
$criteria->compare('streamurl',$event->streamurl, 'OR');
$criteria->compare('price',$event->price, 'OR');
$criteria->compare('thumbnail',$event->thumbnail, 'OR');
$criteria->compare('airdate',$event->airdate, 'OR');*/
/* $find = Event::model()->findAll($criteria);
*/
and it says undefined variable: model
i tried commenting out the render section and it didn’t show anything… just white.
You call _search with
<?php $this->renderPartial('_search',array(
'post'=>$post,
));
but in the _search.php you are using $model instead of $post
or you can call it like
<?php $this->renderPartial('_search',array(
'model'=>$post,
));
In the controller.php - actionSearch you are using $event->… but where is $event assigned and does it have any value?