2

I need help in Agile Toolkit CRUD Grid/Form.

I made a CRUD Grid/Form in Agile Toolkit for Employee, Position and Department. It was very easy. But i am now having difficulty trying to set the Position and Department columns. Instead of showing 'id' value, i'd like to show the referenced text in 'pos_desc' and 'dept_desc' respectively.

Also in CRUD's Add/Edit Form, it only shows 'id' and not the corresponding text. Is there a way to set this using the description text but save the 'id' instead on commit?

Thanks!

Here is the project's directory structure and some code snippets:

    + atk4
    + atk4-addons
    + empmaster
      + admin
        + lib
        + page
      + doc
      + lib
        + Model
      + page
      + templates

admin/lib/Admin.php

    class Admin extends ApiFrontend {
    :
    :   
       function init(){
    :
    :
          $this->addLocation('..',array(
                      'php'=>array(
                            'lib',
                            )
                      ));
          $this->addLocation('../..',array(
                      'php'=>array(
                            'atk4-addons/mvc',
                            'atk4-addons/misc/lib',
                            )
                      ))
                ->setParent($this->pathfinder->base_location);
    :
    :

lib/Model/Employee.php

    class Model_Employee extends Model_Table {
       public $entity_code = 'emp';

       function init() {
          parent::init();

          $this->addField('eeid')->caption('Emp ID');
          $this->addField('fnm')->caption('First Name');
          $this->addField('mnm')->caption('Middle Name');
          $this->addField('lnm')->caption('Last Name');

          $pos=$this->addField('pos_id')->caption('Position');
          $pos->refModel('Model_Postition');

          $dep=$this->addField('dept_id')->caption('Department');
          $dep->refModel('Model_Department');

          // #1 refModel gives error if declared w/out 'Model_' prefix
          // #2 Position & Department caption not on grid, but only on form
       }
    }

lib/Model/Position.php

    class Model_Position extends Model_Table {
       public $entity_code = 'pos';

       function init() {
          parent::init();

          $this->addField('pos_desc');
       }
    }

lib/Model/Department.php

    class Model_Department extends Model_Table {
       public $entity_code = 'dept';

       function init() {
          parent::init();

          $this->addField('dept_desc');
       }
    }

admin/page/index.php

    $crud = $tabs->addTab('Employee Master')->add('CRUD')->setModel('Employee');

1 Answers1

0

By default it looks for the field named "name" on the model. If you don't have this field, you will need to override toStringSQL function in the Model_Position.

See this answer for more information:

reference field on form

Community
  • 1
  • 1
romaninsh
  • 10,606
  • 4
  • 50
  • 70
  • yes! the link you referred worked like a charm. thank you very much! i knew about the 'name' field which was especially mentioned in the Models introduction on the Agile Toolkit Learning section, i must've overlooked it because it said: _by default the field called "name" (if defined) is considered a "display field". you will see the "name" of that related table when you are building a grid with the book model._ – Open Technologist Dec 06 '11 at 00:56
  • i thought it meant, getting the name of the table. i changed the two Models to this respectively: `$this->addField('name')->caption('Position');` `$this->addField('name')->caption('Department');` and renamed the field 'pos_desc' and 'dept_desc' to 'name' instead. again, thank you for this wonderful framework! i'll give feedback whenever i can. :) – Open Technologist Dec 06 '11 at 00:56