Yii Framework Forum: Tanya tentang ambil data - Yii Framework Forum

Jump to content

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

Tanya tentang ambil data Rate Topic: -----

#1 User is offline   bob 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-April 10

Posted 02 May 2010 - 09:39 AM

Kk semua, mao nanya nih...gmn caranya ngambil isi dari database, trus di masukan ke dalam value textField??


thx
0

#2 User is offline   __agus 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 166
  • Joined: 22-April 10
  • Location:Yogyakarta, Indonesia

Posted 13 June 2010 - 12:44 AM

View Postbob, on 02 May 2010 - 09:39 AM, said:

Kk semua, mao nanya nih...gmn caranya ngambil isi dari database, trus di masukan ke dalam value textField??


thx


kamu bisa menggunakan find, findAll, findByPk dll. contoh:
misalnya halaman index(SiteController) web ingin menampilkan news/berita. sertakan data pada param render,
catatan: news mempunyai model dengan nama News.php.

#controller/SiteController.php
public function actionIndex() {
    $posts = new Post;
    $this->render('index', 
        array(
        // pada view data disimpan pd variabel ini($news).
        'news' => News::model()->findAll(),
	)
    );
}  


# views/site/index.php
Kemudian pada view index kamu bisa mengambil datanya via variabel $news. contoh:
<?php foreach($news as $berita): ?>
    <?php echo $berita->id; ?><br />
    <?php echo $berita->judul; ?><br />
<?php endforeach; ?>


semoga membantu..
0

#3 User is offline   mbaksri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 15-July 11

Posted 12 March 2012 - 09:27 AM

Mau nanya niy Agan Bob..
masalah yg ini udah bisa ya? mau liat solusinya dong.. saya jg butuh penyelesaian yg kasus kayak gini.. Thanks :D
0

#4 User is offline   mhdrasad 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 198
  • Joined: 20-April 11
  • Location:Bumi Indonesia

Posted 12 March 2012 - 08:57 PM

View Postbob, on 02 May 2010 - 09:39 AM, said:

Kk semua, mao nanya nih...gmn caranya ngambil isi dari database, trus di masukan ke dalam value textField??


thx


Ane setuju sama master _agus

Klo boleh nambahin , sekalian ikut eksis di forum :D

di controller (asumsi dimodel sama)

$model=$this->loadmodel(); // model nya sama
$model=NamaModel::model()->findbyAttributes(array('namaAttribute'=>'valueAttribute')) // asumsi panggil model sesuai keinginan;
$Attribute1 = $model->Attribute1;
$Attribute2 = $model->Attribute2;
$Attribute3 = $model->Attribute3;

$this->render('view',
array('Attribute1'=>$Attribute1,'Attribute2'=>$Attribute2,'Attribute3'=>$Attribute3)
);


di view

echo CHtml::textField('namaField1', $Attribute1);
echo CHtml::textField('namaField2', $Attribute2);
echo CHtml::textField('namaField3', $Attribute3);


CMIIW ^_^ (ma'af klo salah , numpang eksis aja :D)
Wait For True Concept or Finish it With Coding Concept .
#chadnox
0

#5 User is offline   xtremagix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 06-May 11

Posted 13 March 2012 - 11:46 AM

ikutan ah...
kenapa tidak menggunakan CACtiveForm ajah?
lebih enak kan? bisa sekalian validasi input nya juga... :D

lebih lengkap disini:
yii CActiveForm

lihat contoh nya di demo bawaan yii.
There's no such thing of Individualism, Sharing with others is how you respect the knowledge itself...
0

#6 User is offline   MasMo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 30-July 13

Posted 30 July 2013 - 03:05 AM

Kalo tabelnya punya relasi ke tabel lain,kok data nya g bisa diambil ya mas ,.,.
mohon Penjelasannya,,,

newbie
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