Hello
I am new in Yii.
Actually I try to retrieve data from database to print on htmlpage.
But one column of table is printing in actionIndex but i want to print whole table data.
I use for loop in action index but it printing whole index page multiple times.
This is the code:-
I siteContoller.php
public function actionIndex()
{
for ($i=1;$i<5;$i++)
{
$name= Yiitest::model()->findByPk($i);
$id= Yiitest::model()->findByPk($i);
$this->render('index', array('name'=>$name,'id'=>$id));
}
}
In index.php
<p>Your Name is :<?php echo $name->name?><br>
Your ID is:<?php echo $id->id?></p>
Model is:-
<?php
class Yiitest extends CActiveRecord
{
public function tableName()
{
return 'yiitest';
}
public function rules()
{
return array(
array('id, name', 'required'),
array('id', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>50),
array('id, name', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
);
}
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'Name',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}