开发者

reference field on form

I think I'm not understanding the reference field.

I have a simple form

<?php

class page_prueba extends Page {
  function init(){
    parent::init();
    $p=$this;
    $f=$p->add('Form');
    $f->setSource('ticket');
    $f->addField('line','texto')->validateNotNull();
    $f->addField('text','detalle')->validateNotNull();
    $c=$p->add('Model_Usuario');
    $f->addField('reference','usuario')->setValueList($c)->validateNotNull();
  }
}

And I have a User Model

<?php
  class Model_Usuario extends Model_Table {
    public $entity_code='usuario';
    public $table_alias='u';
    function defineFields(){
      parent::defineFields();           
      $this->addField('nombre');
      $this->addField('password');
      $this->addField('email');
      $this->addField('telefono');
      $this->addField('descripcion');
      $this->addField('interno');
      $this->addField('esadmin');
    }
  }
?>

When I run the example page I get on the dropdown (option values) displayed the id values (primary key) but what I want to see on that dropdowns is the name (nombre) field.

Maybe I'm missing something.

Any开发者_JS百科 help would be appreciate.

thanks Alejandro


By default model displays "name" field. There are few ways to customize that

  1. define name field as calculated
  2. redefine Model_Usuario::toStringSQL()
  3. since 4.1 you can also define field name through a property.

you should probably go after 2, here is example:

public function toStringSQL($source_field, $dest_fieldname, $expr = 'name') {
    // return parent::tostringSQL($source_field,$dest_fieldname, 'date')

    return 'concat(name," ",surname) as ' . $dest_fieldname;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜