Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Error Object 2 not found in author Olá, tudo bem? Estou iniciando minhas pesquisas no Adianti Framework a pouco tempo, estou estudando o módulo Biblioteca (library) disponibilizado pelo Pablo, estou mudando o seu template para o tema 3 e estou com o seguinte Error Object 2 not found in author. Se alguma alma caridosa puder ajudar, serei grato! Mais notei que as pessoas que participam do fórum são bastante colaborativas! ...
JA
Error Object 2 not found in author  
Olá, tudo bem?

Estou iniciando minhas pesquisas no Adianti Framework a pouco tempo, estou estudando o módulo Biblioteca (library) disponibilizado pelo Pablo, estou mudando o seu template para o tema 3 e estou com o seguinte Error Object 2 not found in author.

Se alguma alma caridosa puder ajudar, serei grato! Mais notei que as pessoas que participam do fórum são bastante colaborativas!

Att,
Jonathas Alves

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (2)


LA

ola Jonathas, resolveu?
posta como fez no BookList e no Model da tabela.
JA

Olá, Luis Alberto!

Tudo bem?
Ainda não consegui resolver

Control

  1. <?php
  2. /**
  3.  * BookList Listing
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage library
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class BookList extends TPage
  13. {
  14.     private $form;     // registration form
  15.     private $datagrid// listing
  16.     private $pageNavigation;
  17.     private $loaded;
  18.     
  19.     /**
  20.      * Class constructor
  21.      * Creates the page, the form and the listing
  22.      */
  23.     public function __construct()
  24.     {
  25.         parent::__construct();
  26.         // security check
  27.         if (TSession::getValue('logged') !== TRUE)
  28.         {
  29.             throw new Exception(('Not logged'));
  30.         }
  31.         
  32.         // creates the form
  33.         $this->form = new TForm('form_search_Book');
  34.         $this->form->class 'tform';
  35.         // creates a table
  36.         $table = new TTable;
  37.         $table->width '100%';
  38.         
  39.         $table->addRowSet(new TLabel(('Books')), '')->class='tformtitle';
  40.         
  41.         // add the table inside the form
  42.         $this->form->add($table);
  43.         
  44.         // create the form fields
  45.         $title             = new TEntry('title');
  46.         $author_id         = new TSeekButton('author_id');
  47.         $author_name       = new TEntry('author_name');
  48.         $collection_id     = new TDBCombo('collection_id''library''Collection''id''description');
  49.         $classification_id = new TDBCombo('classification_id''library''Classification''id''description');
  50.         
  51.         $title->setValue(TSession::getValue('Book_title'));
  52.         $author_id->setValue(TSession::getValue('Book_author_id'));
  53.         $author_name->setValue(TSession::getValue('Book_author_name'));
  54.         $collection_id->setValue(TSession::getValue('Book_collection_id'));
  55.         $classification_id->setValue(TSession::getValue('Book_classification_id'));
  56.         $author_name->setEditable(FALSE);
  57.         
  58.         $title->setSize(320);
  59.         $author_id->setSize(100);
  60.         $obj = new TStandardSeek;
  61.         $action = new TAction(array($obj'onSetup'));
  62.         $action->setParameter('database',      'library');
  63.         $action->setParameter('parent',        'form_search_Book');
  64.         $action->setParameter('model',         'Author');
  65.         $action->setParameter('display_field''name');
  66.         $action->setParameter('receive_key',   'author_id');
  67.         $action->setParameter('receive_field''author_name');
  68.         $author_id->setAction($action);
  69.         
  70.         // add a row for the title field
  71.         $row=$table->addRow();
  72.         $row->addCell(new TLabel(('Title') . ': '));
  73.         $cell=$row->addCell($title);
  74.         
  75.         // add a row for the title field
  76.         $row=$table->addRow();
  77.         $row->addCell(new TLabel(('Author') . ': '));
  78.         $row->addMultiCell($author_id$author_name);
  79.         
  80.         // add a row for the title field
  81.         $row=$table->addRow();
  82.         $row->addCell(new TLabel(('Collection') . ': '));
  83.         $cell=$row->addCell($collection_id);
  84.         
  85.         // add a row for the title field
  86.         $row=$table->addRow();
  87.         $row->addCell(new TLabel(('Classification') . ': '));
  88.         $cell=$row->addCell($classification_id);
  89.         
  90.         // create two action buttons to the form
  91.         $find_button = new TButton('find');
  92.         $new_button  = new TButton('new');
  93.         // define the button actions
  94.         $find_button->setAction(new TAction(array($this'onSearch')), ('Find'));
  95.         $find_button->setImage('fa:search');
  96.         
  97.         $new_button->setAction(new TAction(array('BookForm''onEdit')), ('New'));
  98.         $new_button->setImage('fa:plus-square green');
  99.         
  100.         $table->addRowSet('', array($find_button$new_button))->class='tformaction';
  101.         
  102.         // define wich are the form fields
  103.         $this->form->setFields(array($title$author_id$author_name$collection_id$classification_id$find_button$new_button));
  104.         
  105.         // creates a DataGrid
  106.         $this->datagrid = new TDataGrid;
  107.         $this->datagrid->style 'width: 100%';
  108.         $this->datagrid->setHeight(280);
  109.         
  110.         // creates the datagrid columns
  111.         $id                = new TDataGridColumn('id', ('Code'), 'right'50);
  112.         $title             = new TDataGridColumn('title', ('Title'), 'left'200);
  113.         $main_author       = new TDataGridColumn('author_name', ('Author'), 'left'160);
  114.         $edition           = new TDataGridColumn('edition', ('Edition'), 'left'50);
  115.         $call              = new TDataGridColumn('call_number', ('Call'), 'left'80);
  116.         // creates the datagrid actions
  117.         $order1= new TAction(array($this'onReload'));
  118.         $order2= new TAction(array($this'onReload'));
  119.         // define the ordering parameters
  120.         $order1->setParameter('order''id');
  121.         $order2->setParameter('order''title');
  122.         // assign the ordering actions
  123.         $id->setAction($order1);
  124.         $title->setAction($order2);
  125.         
  126.         // add the columns to the DataGrid
  127.         $this->datagrid->addColumn($id);
  128.         $this->datagrid->addColumn($title);
  129.         $this->datagrid->addColumn($main_author);
  130.         $this->datagrid->addColumn($edition);
  131.         $this->datagrid->addColumn($call);
  132.         
  133.         // creates two datagrid actions
  134.         $action1 = new TDataGridAction(array('BookForm''onEdit'));
  135.         $action1->setLabel(('Edit'));
  136.         $action1->setImage('fa:pencil-square-o blue fa-lg');
  137.         $action1->setField('id');
  138.         
  139.         $action2 = new TDataGridAction(array($this'onDelete'));
  140.         $action2->setLabel(('Delete'));
  141.         $action2->setImage('fa:trash-o red fa-lg');
  142.         $action2->setField('id');
  143.         
  144.         // add the actions to the datagrid
  145.         $this->datagrid->addAction($action1);
  146.         $this->datagrid->addAction($action2);
  147.         
  148.         // create the datagrid model
  149.         $this->datagrid->createModel();
  150.         
  151.         // creates the page navigation
  152.         $this->pageNavigation = new TPageNavigation;
  153.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  154.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  155.         
  156.         // creates the page structure using a vbox
  157.         $container = new TVBox;
  158.         $container->style 'width: 100%';
  159.         $container->add($this->form);
  160.         $container->add($this->datagrid);
  161.         $container->add($this->pageNavigation);
  162.         // add the vbox inside the page
  163.         parent::add($container);
  164.     }
  165.     
  166.     /**
  167.      * method onSearch()
  168.      * Register the filter in the session when the user performs a search
  169.      */
  170.     function onSearch()
  171.     {
  172.         // get the search form data
  173.         $data $this->form->getData();
  174.         $filters = array();
  175.         TSession::setValue('Book_title''');
  176.         TSession::setValue('Book_author_id''');
  177.         TSession::setValue('Book_author_name''');
  178.         TSession::setValue('Book_collection_id''');
  179.         TSession::setValue('Book_classification_id''');
  180.         TSession::setValue('Book_filters',   array());
  181.         
  182.         // check if the user has filled the form
  183.         if ($data->title)
  184.         {
  185.             // creates a filter using what the user has typed
  186.             $filter = new TFilter('title''like'"%{$data->title}%");
  187.             
  188.             // stores the filter in the session
  189.             TSession::setValue('Book_title'$data->title);
  190.             $filters[] = $filter;
  191.         }
  192.         
  193.         if ($data->author_id)
  194.         {
  195.             // creates a filter using what the user has typed
  196.             $filter = new TFilter('author_id''='"{$data->author_id}");
  197.             
  198.             // stores the filter in the session
  199.             TSession::setValue('Book_author_id'$data->author_id);
  200.             TSession::setValue('Book_author_name'$data->author_name);
  201.             $filters[] = $filter;
  202.         }
  203.         
  204.         if ($data->collection_id)
  205.         {
  206.             // creates a filter using what the user has typed
  207.             $filter = new TFilter('collection_id''='"{$data->collection_id}");
  208.             
  209.             // stores the filter in the session
  210.             TSession::setValue('Book_collection_id'$data->collection_id);
  211.             $filters[] = $filter;
  212.         }
  213.         
  214.         if ($data->classification_id)
  215.         {
  216.             // creates a filter using what the user has typed
  217.             $filter = new TFilter('classification_id''='"{$data->classification_id}");
  218.             
  219.             // stores the filter in the session
  220.             TSession::setValue('Book_classification_id'$data->classification_id);
  221.             $filters[] = $filter;
  222.         }
  223.         
  224.         if ($filters)
  225.         {
  226.             TSession::setValue('Book_filters',   $filters);
  227.         }
  228.         
  229.         // fill the form with data again
  230.         $this->form->setData($data);
  231.         $param=array();
  232.         $param['offset']    =0;
  233.         $param['first_page']=1;
  234.         $this->onReload($param);
  235.     }
  236.     
  237.     /**
  238.      * method onReload()
  239.      * Load the datagrid with the database objects
  240.      */
  241.     function onReload($param NULL)
  242.     {
  243.         try
  244.         {
  245.             // open a transaction with database 'library'
  246.             TTransaction::open('library');
  247.             
  248.             // creates a repository for Book
  249.             $repository = new TRepository('Book');
  250.             $limit 10;
  251.             // creates a criteria
  252.             $criteria = new TCriteria;
  253.             $criteria->setProperties($param); // order, offset
  254.             $criteria->setProperty('limit'$limit);
  255.             
  256.             if (TSession::getValue('Book_filters'))
  257.             {
  258.                 foreach (TSession::getValue('Book_filters') as $filter)
  259.                 {
  260.                     if ($filter instanceof TFilter)
  261.                     {
  262.                         // add the filter stored in the session to the criteria
  263.                         $criteria->add($filter);
  264.                     }
  265.                 }
  266.             }
  267.             
  268.             // load the objects according to criteria
  269.             $objects $repository->load($criteria);
  270.             
  271.             $this->datagrid->clear();
  272.             if ($objects)
  273.             {
  274.                 // iterate the collection of active records
  275.                 foreach ($objects as $object)
  276.                 {
  277.                     // add the object inside the datagrid
  278.                     $this->datagrid->addItem($object);
  279.                 }
  280.             }
  281.             
  282.             // reset the criteria for record count
  283.             $criteria->resetProperties();
  284.             $count$repository->count($criteria);
  285.             
  286.             $this->pageNavigation->setCount($count); // count of records
  287.             $this->pageNavigation->setProperties($param); // order, page
  288.             $this->pageNavigation->setLimit($limit); // limit
  289.             
  290.             // close the transaction
  291.             TTransaction::close();
  292.             $this->loaded true;
  293.         }
  294.         catch (Exception $e// in case of exception
  295.         {
  296.             // shows the exception error message
  297.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  298.             
  299.             // undo all pending operations
  300.             TTransaction::rollback();
  301.         }
  302.     }
  303.     
  304.     /**
  305.      * method onDelete()
  306.      * executed whenever the user clicks at the delete button
  307.      * Ask if the user really wants to delete the record
  308.      */
  309.     function onDelete($param)
  310.     {
  311.         // get the parameter $key
  312.         $key=$param['key'];
  313.         
  314.         // define two actions
  315.         $action = new TAction(array($this'Delete'));
  316.         
  317.         // define the action parameters
  318.         $action->setParameter('key'$key);
  319.         
  320.         // shows a dialog to the user
  321.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  322.     }
  323.     
  324.     /**
  325.      * method Delete()
  326.      * Delete a record
  327.      */
  328.     function Delete($param)
  329.     {
  330.         try
  331.         {
  332.             // get the parameter $key
  333.             $key=$param['key'];
  334.             // open a transaction with database 'library'
  335.             TTransaction::open('library');
  336.             
  337.             // instantiates object Book
  338.             $object = new Book($key);
  339.             
  340.             // deletes the object from the database
  341.             $object->delete();
  342.             
  343.             // close the transaction
  344.             TTransaction::close();
  345.             
  346.             // reload the listing
  347.             $this->onReload();
  348.             // shows the success message
  349.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted'));
  350.         }
  351.         catch (Exception $e// in case of exception
  352.         {
  353.             // shows the exception error message
  354.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  355.             
  356.             // undo all pending operations
  357.             TTransaction::rollback();
  358.         }
  359.     }
  360.     
  361.     /**
  362.      * method show()
  363.      * Shows the page
  364.      */
  365.     function show()
  366.     {
  367.         // check if the datagrid is already loaded
  368.         if (!$this->loaded)
  369.         {
  370.             $this->onReload();
  371.         }
  372.         parent::show();
  373.     }
  374. }
  375. ?>



Model

  1. <?php
  2. /**
  3.  * Book Active Record
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage library
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class Book extends TRecord
  13. {
  14.     const TABLENAME 'book';
  15.     const PRIMARYKEY'id';
  16.     const IDPOLICY =  'max'// {max, serial}
  17.     use SystemChangeLogTrait
  18.     
  19.     private $authors;
  20.     private $subjects;
  21.     private $items;
  22.     private $author;
  23.     private $publisher;
  24.     private $collection;
  25.     
  26.     /**
  27.      * Returns the book author name
  28.      */
  29.     function get_author_name()
  30.     {
  31.         if (empty($this->author))
  32.             $this->author = new Author($this->author_id);
  33.         
  34.         return $this->author->name;
  35.     }
  36.     
  37.     /**
  38.      * Returns the book collection description
  39.      */
  40.     function get_collection_description()
  41.     {
  42.         if (empty($this->collection))
  43.             $this->collection = new Collection($this->collection_id);
  44.         
  45.         return $this->collection->description;
  46.     }
  47.     
  48.     /**
  49.      * Returns the book publisher name
  50.      */
  51.     function get_publisher_name()
  52.     {
  53.         if (empty($this->publisher))
  54.             $this->publisher = new Publisher($this->publisher_id);
  55.         
  56.         return $this->publisher->name;
  57.     }
  58.     
  59.     /**
  60.      * Reset aggregates
  61.      */
  62.     public function clearParts()
  63.     {
  64.         $this->authors  = array();
  65.         $this->subjects = array();
  66.         $this->items    = array();
  67.     }
  68.     
  69.     /**
  70.      * Aggregation with Author
  71.      */
  72.     public function addAuthor(Author $author)
  73.     {
  74.         $this->authors[] = $author;
  75.     }
  76.     
  77.     /**
  78.      * Aggregation with Subject
  79.      */
  80.     public function addSubject(Subject $subject)
  81.     {
  82.         $this->subjects[] = $subject;
  83.     }
  84.     
  85.     /**
  86.      * Composition with Item
  87.      */
  88.     public function addItem(Item $item)
  89.     {
  90.         $this->items[] = $item;
  91.     }
  92.     
  93.     /**
  94.      * Return Author aggregates
  95.      */
  96.     public function getAuthors()
  97.     {
  98.         return $this->authors;
  99.     }
  100.     
  101.     /**
  102.      * Return Subject aggregates
  103.      */
  104.     public function getSubjects()
  105.     {
  106.         return $this->subjects;
  107.     }
  108.     
  109.     /**
  110.      * Return Items composition
  111.      */
  112.     public function getItems()
  113.     {
  114.         return $this->items;
  115.     }
  116.     
  117.     /**
  118.      * Load the object and the aggregates
  119.      */
  120.     public function load($id)
  121.     {
  122.         $book_author_rep  = new TRepository('BookAuthor');
  123.         $book_subject_rep = new TRepository('BookSubject');
  124.         $item_rep         = new TRepository('Item');
  125.         
  126.         $criteria = new TCriteria;
  127.         $criteria->add(new TFilter('book_id''='$id));
  128.         
  129.         // load the Author aggregates
  130.         $book_authors $book_author_rep->load($criteria);
  131.         if ($book_authors)
  132.         {
  133.             foreach ($book_authors as $book_author)
  134.             {
  135.                 $author = new Author($book_author-> author_id);
  136.                 $this->addAuthor($author);
  137.             }
  138.         }
  139.         
  140.         // load the Subject aggregates
  141.         $book_subjects $book_subject_rep->load($criteria);
  142.         if ($book_subjects)
  143.         {
  144.             foreach ($book_subjects as $book_subject)
  145.             {
  146.                 $subject = new Subject($book_subject-> subject_id);
  147.                 $this->addSubject($subject);
  148.             }
  149.         }
  150.         
  151.         // load the Item composition
  152.         $items $item_rep->load($criteria);
  153.         if ($items)
  154.         {
  155.             foreach ($items as $item)
  156.             {
  157.                 $this->addItem($item);
  158.             }
  159.         }
  160.         
  161.         // load the object itself
  162.         return parent::load($id);
  163.     }
  164.     
  165.     /**
  166.      * Stores the book and the aggregates (authors, subjects, items)
  167.      */
  168.     public function store()
  169.     {
  170.         // stores the Book
  171.         parent::store();
  172.         
  173.         // delete the aggregates
  174.         $criteria = new TCriteria;
  175.         $criteria->add(new TFilter('book_id''='$this->id));
  176.         
  177.         $repository = new TRepository('BookAuthor');
  178.         $repository->delete($criteria);
  179.         $repository = new TRepository('BookSubject');
  180.         $repository->delete($criteria);
  181.         
  182.         // collect persistent item ids
  183.         if ($this->items)
  184.         {
  185.             foreach ($this->items as $item)
  186.             {
  187.                 if ($item->id)
  188.                 {
  189.                     $item_ids[] = $item->id;
  190.                 }
  191.             }
  192.         }
  193.         
  194.         
  195.         // delete all items, except for those that persist
  196.         $criteria->add(new TFilter('id''NOT IN'$item_ids));
  197.         $repository = new TRepository('Item');
  198.         $repository->delete($criteria);
  199.         
  200.         // store the authors
  201.         if ($this->authors)
  202.         {
  203.             foreach ($this->authors as $author)
  204.             {
  205.                 $book_author = new BookAuthor;
  206.                 $book_author-> book_id    $this-> id;
  207.                 $book_author-> author_id  $author-> id;
  208.                 $book_author->store();
  209.             }
  210.         }
  211.         
  212.         // store the subjects
  213.         if ($this->subjects)
  214.         {
  215.             foreach ($this->subjects as $subject)
  216.             {
  217.                 $book_subject = new BookSubject;
  218.                 $book_subject-> book_id     $this-> id;
  219.                 $book_subject-> subject_id  $subject-> id;
  220.                 $book_subject->store();
  221.             }
  222.         }
  223.         
  224.         // store the items
  225.         if ($this->items)
  226.         {
  227.             foreach ($this->items as $item)
  228.             {
  229.                 $item-> book_id $this-> id;
  230.                 $item->store();
  231.             }
  232.         }
  233.     }
  234.     
  235.     /**
  236.      * Delete the book and its aggregates
  237.      */
  238.     public function delete($id NULL)
  239.     {
  240.         $id = isset($id) ? $id $this->{'id'};
  241.         
  242.         $criteria = new TCriteria;
  243.         $criteria->add(new TFilter('book_id''='$id));
  244.         
  245.         $repository = new TRepository('BookAuthor');
  246.         $repository->delete($criteria);
  247.         $repository = new TRepository('BookSubject');
  248.         $repository->delete($criteria);
  249.         $repository = new TRepository('Item');
  250.         $repository->delete($criteria);
  251.         
  252.         // delete the object itself
  253.         parent::delete($id);
  254.     }
  255. }
  256. ?>