Yii Framework Forum: [ASK] ngambil 5 record terakhir, render ke main.php - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[ASK] ngambil 5 record terakhir, render ke main.php Rate Topic: -----

#1 User is offline   intomidnight 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 17-March 12

Posted 20 March 2012 - 11:56 PM

Agan-agan,
newbie bertanya lagi kalo berkenan mohon dibantu ya..

Ceritanya, aq ingin ngambil 5 record terakhir dari postingan, kemudian ditampilkan di view, di layouts/main.php

Model :

public function lastNew()
{
$sql='SELECT * FROM font order by id desc';
$dataProvider=new CSqlDataProvider($sql,array(
'keyField' => 'id',
'pagination'=>array(
'pageSize'=>5,
),
));
return $dataProvider;
}


Controller :
public function actionMain()
	{
		$dataProvider=Font::model()->lastNew();
		$this->render('main',array(
				'dataProvider'=>$dataProvider,
		));			
	}


Kemudian di view, di layouts/main.php :

<?php
foreach($dataProvider->getData() as $i=>$ii)
{
echo Chtml::link($ii['fname'],array('font/view','id'=>$ii['fid']));
}
?>



dan errornya : Undefined variable: dataProvider. Saya keliru gak sih gan? mohon bantuannya untuk koreksi....


Trims ya sebelumnya... ^^
0

#2 User is offline   intomidnight 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 17-March 12

Posted 21 March 2012 - 04:16 AM

maap, udh teratasi :D ketemu CPortlet :) trimsssss
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users