Hi all,
I’m new with Yii framework, and I’m starting my first project.
I’m completely stuck with a very simple thing. Need some demo-code.
What I want to do is the following:
I have one form in my main page, including two dropDownLists. One shows cities and the other one shows activities.
I want to show, in a different page, in a CGridView, "companies" offering selected "activity" in selected "city".
In my database, I have these three tables:
Activities
ActivityId
ActivityName
Companies
CompanyId
CompanyName
City
Schedule
ScheduleId
CompanyId
ActivityId
Hour
Day
This is my form, I think everything is ok round here:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'search-form',
'action'=>Yii::app()->baseUrl.'/activities/search',
'method'=>'post',
'enableAjaxValidation'=>true,
'enableClientValidation'=>false));
?>
<div id="search">
<label for="Activities_Activity" class="required">Choose Activity</label>
<?php echo $form->dropDownList(Activities::model(), 'ActivityId', CHtml::listData(Activities::model()->findAll(), 'ActivityId', 'Activity'), array('options'=>array('42'=>array('selected'=>true)),'name'=>'activity')); ?>
<label for="Cities_City" class="required">Choose City</label>
<?php echo $form->dropDownList(Cities::model(), 'CityId', CHtml::listData(Cities::model()->findAll(), 'CityId', 'City'), array('options'=>array('24'=>array('selected'=>true)),'name'=>'City')); ?>
<?php
$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit','type'=>'info','label'=>'Find','loadingText'=>'Searching...','htmlOptions'=>array('id'=>'buttonStateful','style'=>'margin-left:132px')));?>
</div>
<?php
$this->endWidget();
?>
I have no idea about what to put in my ActivitiesController:
public function actionSearch()
// :-(
{
I also don’t know how to define my table relations in Activities model
And this is what I want to get filled in the results page:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'results-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'name'=>'CompanyName',
'header'=>'CompanyName',
'type'=>'raw',
'value'=>$data->CompanyName
),
array(
'name'=>'Day',
'header'=>'Day',
'type'=>'raw',
'value'=>$data->Day
),
array(
'name'=>'Hour',
'header'=>'Hour',
'type'=>'raw',
'value'=>$data->Hour
),
),
));
?>
Can anybody help me? I’m really stuck with that, and I know it must be easy.
Thanks in advance!