2

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 help would be appreciate.

thanks Alejandro

Mchl
  • 61,444
  • 9
  • 118
  • 120
AJM.MARTINEZ
  • 477
  • 2
  • 10

1 Answers1

1

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;
}
romaninsh
  • 10,606
  • 4
  • 50
  • 70
  • Roman, thanks very much. I just simple change the column name, adjust some code and have it working !!!!! I'm really impressed with the framework, I'm not a very experienced framework php programmer, just simple code. I've looking other alternatives, but now I'm a new Agile Toolkit fan !!! I've replaced an old developed system in a few hours with clean code, an cool look and feel... Thanks again !!! – AJM.MARTINEZ Aug 21 '11 at 17:51
  • Always a pleasure to hear such words. Please let me know if anything is wrong and keep using 4.1 version, it's stable and matches documentation. http://agiletoolkit.org/distfiles/lab/atk4-example-4.1.zip I Will announce it veeery soon. – romaninsh Aug 21 '11 at 19:44