Resipi Panas : Menggunakan $form->inputs()
19 replies [Last post]
CakePHP Trainer
User offline. Last seen 2 years 34 weeks ago. Offline
Joined: 01/27/2003
Points: 408

Seringkali kita akan dilanda kemalasan melampau, tapi taklaaa sampai tahap nak guna $scaffold sepanjang masa

Bayangkan anda ada 100 fields, dan malas nak taip one by one

Solutionnya guna : echo $form->inputs();

/ice all #kampung

programmer yang tak pandai programming
User offline. Last seen 2 years 9 weeks ago. Offline
Joined: 08/16/2009
Points: 80

aku kurang jelas la..boleh tak detailkan sikit penerangan ni?

CakePHP Trainer
User offline. Last seen 2 years 34 weeks ago. Offline
Joined: 01/27/2003
Points: 408

bro, ini untuk yg dah tau CakePHP bukan PHP biasa.

http://www.cakephp.org

$form->inputs() tuh adalah satu fungsi bagaimana CakePHP generate HTML code untuk jenis-jenis HTML form yang bersesuaian dengan jenis Database Table yang digunakan dalam Model data yang digunakan.

http://twitter.com/phpnetmy
sameon's picture
User offline. Last seen 1 week 19 hours ago. Offline
Pro
Joined: 08/22/2002
Points: 168

aku yang part tak boleh bayang tu ada 100 fields. hehe.

have to start running again...
tukangkod's picture
User offline. Last seen 3 years 3 weeks ago. Offline
Pro
Joined: 08/17/2009
Points: 53

letih gak tu 100 fields.

CakePHP newbie
avenger108's picture
User offline. Last seen 1 year 40 weeks ago. Offline
Joined: 08/16/2009
Points: 26

salam...nak tanye pasal input ni la... dah seharian try n error pasal input ni...

macam mana nak letak nama input tu TAK SAMA dengan nama field?

contohnya macam dalam table post, ada field content,

pastu biasanya kat fail .ctp akan letak $form->input('content'); kan...

kalau aku nak letak nama input tu sebagai kandungan ( $form->input('kandungan')... ), apa yang perlu aku tambah supaya coding dapat detect yang 'kandungan' tu sebenarnya untuk field 'content' ?

thanks...

keje :)
zam3858's picture
User offline. Last seen 40 weeks 23 hours ago. Offline
Moderator
Joined: 04/26/2003
Points: 382

camni...

<?php
 
echo $form->input('nama_field', array('name' => 'kandungan'));
?>

CakePHP Trainer
User offline. Last seen 2 years 34 weeks ago. Offline
Joined: 01/27/2003
Points: 408

<?php
$form
->input('Content.kandungan');
?>
I'm noob
hymns's picture
User offline. Last seen 2 years 22 weeks ago. Offline
Pro
Joined: 08/16/2009
Points: 975

bazet wrote:

Seringkali kita akan dilanda kemalasan melampau, tapi taklaaa sampai tahap nak guna $scaffold sepanjang masa

Bayangkan anda ada 100 fields, dan malas nak taip one by one

Solutionnya guna : echo $form->inputs();

/ice all #kampung

isk isk agak2 ko la form ape sampai 100 field tu? aku aku amik paid survey pun lebih 30 field aku x amik dah lagikan 100 Stare

*tapi aku rasa ko la yg slalu guna scaffold*

I'm noob
hymns's picture
User offline. Last seen 2 years 22 weeks ago. Offline
Pro
Joined: 08/16/2009
Points: 975

bazet wrote:

Seringkali kita akan dilanda kemalasan melampau, tapi taklaaa sampai tahap nak guna $scaffold sepanjang masa

Bayangkan anda ada 100 fields, dan malas nak taip one by one

Solutionnya guna : echo $form->inputs();

/ice all #kampung

isk isk agak2 ko la form ape sampai 100 field tu? aku aku amik paid survey pun lebih 30 field aku x amik dah lagikan 100 Stare

*tapi aku rasa ko la yg slalu guna scaffold*

keje :)
zam3858's picture
User offline. Last seen 40 weeks 23 hours ago. Offline
Moderator
Joined: 04/26/2003
Points: 382

aku pernah jumpa sorang buat masters project dalam bidang AI. dia punya jadi 100 fields sebab dia denormalize database dia untuk speed.

time tu dia berdiri pun boleh tido.

so jgn denormalize table ko sampai 100++ field.

CakePHP Trainer
User offline. Last seen 2 years 34 weeks ago. Offline
Joined: 01/27/2003
Points: 408

aku buat project gis, ada 174 fields auto generated dari collector machine Laughing out loud

I'm noob
hymns's picture
User offline. Last seen 2 years 22 weeks ago. Offline
Pro
Joined: 08/16/2009
Points: 975

bazet wrote:
aku buat project gis, ada 174 fields auto generated dari collector machine Laughing out loud

hmm... siapakah yg design table tu. isk isk Puzzled

CakePHP newbie
avenger108's picture
User offline. Last seen 1 year 40 weeks ago. Offline
Joined: 08/16/2009
Points: 26

zam3858 wrote:

camni...

<?php
 
echo $form->input('nama_field', array('name' => 'kandungan'));
?>

thanks bro... tapi tak jadi la...
aku dah jumpa skrip lain... kawan ajar...
ni nak share untuk semua...

skrip kat view file (.ctp)

<?php echo $form->create('Post');?>
<fieldset>
    <legend><?php __('Add Post');?></legend>
    <?php echo $form->input('kandungan'); ?>
</fieldset>
<?php     echo $form->end('Submit');?>

skrip kat controller, :

<?php
 
function add() {
    if(
$this->data){
     
$this->data = array('Post' => array('content'=> $this->data['Post']['kandungan']));
    }
  }
?>

harap skrip ni dapat membantu korang (yg beginner mcm aku...heheh)...

no way to hide
User offline. Last seen 4 years 9 weeks ago. Offline
Joined: 06/17/2010
Points: 2

bazet wrote:
<?php
$form
->input('Content.kandungan');
?>

Saya pun ada masalah yg sama.. dah ikut cara diatas untuk fungsi add memang ok.. kalau untuk fungsi edit je yang bermasalah..

function edit($id = null) {
    $this->Butiran->id = $id;
    if (empty($this->data)) {
        $this->data = $this->Butiran->read();
    } else {
        if ($this->Butiran->save($this->data)){
            $this->Session->setFlash('Aduan Berjaya Dikemaskini');
            $this->redirect(array('action'=>'index'));
            }
        }
    }


tengah gasak Zend Framework nih...
User offline. Last seen 3 years 1 week ago. Offline
Joined: 08/16/2009
Points: 1

bazet wrote:
aku buat project gis, ada 174 fields auto generated dari collector machine Laughing out loud

bro , aku baru je siap kan form over 311 fields, 5 hari siapkan Laughing out loud without framework Sad

keje :)
zam3858's picture
User offline. Last seen 40 weeks 23 hours ago. Offline
Moderator
Joined: 04/26/2003
Points: 382

congrats ailichigo, sure family ko rindu kat ko dalam 5 hari tu.

I'm noob
hymns's picture
User offline. Last seen 2 years 22 weeks ago. Offline
Pro
Joined: 08/16/2009
Points: 975

zam3858 wrote:
congrats ailichigo, sure family ko rindu kat ko dalam 5 hari tu.

mendalam maksud yg ayat hujung tu Big smile

CakePHP newbie
avenger108's picture
User offline. Last seen 1 year 40 weeks ago. Offline
Joined: 08/16/2009
Points: 26

orangbaru wrote:

Saya pun ada masalah yg sama.. dah ikut cara diatas untuk fungsi add memang ok.. kalau untuk fungsi edit je yang bermasalah..

function edit($id = null) {
    $this->Butiran->id = $id;
    if (empty($this->data)) {
        $this->data = $this->Butiran->read();
    } else {
        if ($this->Butiran->save($this->data)){
            $this->Session->setFlash('Aduan Berjaya Dikemaskini');
            $this->redirect(array('action'=>'index'));
            }
        }
    }

bro... untuk edit, ko kena unset dulu... kalau ikut skrip aku kat atas tu, untuk edit tak jadi...sebab tak unset... so, kena guna skrip macam ni...

<?php                
if (!empty($this->data)) {
 
$this->data['Post']['content'] = $this->data['Post']['kandungan']; unset($this->data['Post']['kandungan']);
 
  if (
$this->Post->save($this->data)) {
   
$this->Session->setFlash(__('The Post has been updated', true));
   
$this->redirect(array('action'=>'index'));
  } else {
   
$this->Session->setFlash(__('The Post could not be saved. Please, try again.', true));
  }
}
?>


Sedang mencari pembangun PHP yang berpengalaman.
User offline. Last seen 1 year 38 weeks ago. Offline
Pro
Joined: 06/28/2010
Points: 123

Ada sesiapa yang pernah membuka kaedah Form::inputs() untuk mengkaji kandungannya?