Quick search:

addDerivedProp

lucb
2005-02-04 12:52:19
 
Hello,

I just found the phppeanuts framework and it looks great! It has a large simularity to Omnis which I used for making some programs.

I installed the examples and the main programs and everything works fine.
I made a new application. I have 2 tables which are working fine but the third table in my database has references to the first two tables and thats more difficult. I tried to loan as much as possible from the examples and it works but i don't understand how you choose which column from the table is being shown, until now i only get the first (id) column.

I'll include 2 files:

-----------classLeden.php-------------------
<?php
// Copyright (c) MetaClass, 2003, 2004
// Licensed under the Academic Free License version 2.0

includeClass('PntDbObject', 'pnt/db');

class Leden extends PntDbObject {


        function Leden($id=null)
        {
                $this->PntDbObject($id);
        }

        /** @static
        * @return String the name of the database table the instances are stored in
        * @abstract - override for each subclass
        */
        function getTableName()
        {
                return 'leden';
        }

        /** Returns the classFolder
        * @static
        * @return String
        */
        function getClassDir()
        {
                return 'zcnop';
        }

        function initPropertyDescriptors() {
                parent::initPropertyDescriptors(); //allways first in this method !!!

                $this->addFieldProp('voornaam', 'string',false,null,null,0,20);
                $this->addFieldProp('achternaam', 'string',false,null,null,0,80);
                $this->addFieldProp('afkorting', 'string',false,null,null,0,40);
                $this->addFieldProp('lid', 'string',false,null,null,0,5);
        }

        /** Information for the user that is editing the object
        * Should be overridden
        * @return String Html
        */
        function getEditInfo()
        {
                return "geen idee wat hier moet staan";
        }

        /** getter method for inherited derived property 'label'.
        * the label will show up if the peanut is an a SELECT list
        */
/*      function getLabel()
        {
                return $this->get('lastName'). ', '. $this->get('firstName');
        }
*/
        /** getter method for derived property 'name' */
/*      function getName()
        {
                return $this->get('firstName'). ' '. $this->get('lastName');
        }
*/
        /** @static
        * @param string $itemType itemType for the sort (may be this method will be inherited and the sort will be for a subclass)
        * @return PntSqlSort that specifies the sql for sorting the instance records by label
        */

        function &getLabelSort($subclass)
        {
                includeClass('PntSqlSort', 'pnt/db/query');
                $sort =& new PntSqlSort('label', $subclass);
                $sort->addSortSpec('lid');
                $sort->addSortSpec('achternaam');
                $sort->addSortSpec('voornaam');
                return $sort;
        }

}

?>
------------------------------------
and
------------classStarts.php---------
<?php
// Copyright (c) MetaClass, 2003, 2004
// Licensed under the Academic Free License version 2.0

includeClass('PntDbObject', 'pnt/db');

class Starts extends PntDbObject {


        function Starts($id=null)
        {
                $this->PntDbObject($id);
        }

        /** @static
        * @return String the name of the database table the instances are stored in
        * @abstract - override for each subclass
        */
        function getTableName()
        {
                return 'starts';
        }

        /** Returns the classFolder
        * @static
        * @return String
        */
        function getClassDir()
        {
                return 'zcnop';
        }

        function initPropertyDescriptors() {
                parent::initPropertyDescriptors(); //allways first in this method !!!

                $this->addFieldProp('datum','date',false,null,null,0,20);
                $this->addFieldProp('vliegtuigenId', 'number',false,1,null,1,'6,0');
                $this->addDerivedProp('vliegtuigen', 'Vliegtuigen',false);
/*              $this->addFieldProp('piloot2Id', 'number',false,null,null,0,5);
                $this->addDerivedProp('piloot2', 'Leden',false);
*/      }

        /** Information for the user that is editing the object
        * Should be overridden
        * @return String Html
        */
        function getEditInfo()
        {
                return "geen idee wat hier moet staan";
        }

        /** getter method for inherited derived property 'label'.
        * the label will show up if the peanut is an a SELECT list
        */
/*      function getLabel()
        {
                return $this->get('lastName'). ', '. $this->get('firstName');
        }
*/
        /** getter method for derived property 'name' */
/*      function getName()
        {
                return $this->get('firstName'). ' '. $this->get('lastName');
        }
*/
        /** @static
        * @param string $itemType itemType for the sort (may be this method will be inherited and the sort will be for a subclass)
        * @return PntSqlSort that specifies the sql for sorting the instance records by label
        */

/*      function &getLabelSort($subclass)
        {
                includeClass('PntSqlSort', 'pnt/db/query');
                $sort =& new PntSqlSort('label', $subclass);
                $sort->addSortSpec('lid');
                $sort->addSortSpec('achternaam');
                $sort->addSortSpec('voornaam');
                return $sort;
        }
*/
}

?>

I searched the website and the tutorial is fine but i didn't find a description of individual commands other then the codebrowser.

Can anybody give me a clue?

Groeten Luc
henk
2005-02-04 15:34:42
 
Hi luc,

In the code you have included all columns for which you have entered addFieldProp or addDerivedProp commands in initPropertyDescriptors should show up, except for the ones that end with 'Id'.

From your question i conclude that you have three tables:
leden, vliegtuigen, starts.
I suppose you have three corresponding classes, all in your
the classFolder zcnop.
If you have setup the zcnop application properly you should get a table with pages on all 'leden' when your request is like:
http://yourserver/yourPeanutsPath/zcnop/index.php?pntType=Leden

As far as i understand your code this should work.

Now if you want to display a list with all starts, your url should be like
http://yourserver/yourPeanutsPath/zcnop/index.php?pntType=Starts

In the first place your Starts::getLabelSort is wrong. I suggest you remove this method for now, you can always put it back in later.

I can see in your code of Starts::initPropertyDescriptors
that you placed a comment around commands for adding the piloot2.. properties. I guess this is becuase you got errors when you tried it without te comment. This may be caused by Leden::getLabel referring to properties that do not exist. I suggest you change 'firstName' to 'voornaam' and 'lastName' to 'achternaam'. Then remove the comment signs from around the piloot2.. properties commands. If it works all right you should get a list with all Starts, with one column 'datum', one column 'vliegtuigen' and one column 'piloot2'. I do not know what should be in the column 'vliegtuigen' as that will be the result of the Vliegtuigen::getLabel method and you did not include the Vliegtuigen class file. If your Vliegtuigen class file does not include a getLabel method you will see the id of the referred Vliegtuigen record in the column labeled vliegtuigen.

If you still only get one column 'id', the framework seems not to process your add..Prop comands. Add a print command in the Starts::initPropertyDescriptors  that outputs something, then refresh the zcnop/index.php?pntType=Starts page to see if the initPropertyDescriptors method is actually called. I will try to help you with the debugging if you tell me the result.

Greetings, Success,

Henk Verhoeven,
www.phpPeanuts.org.

lucb
2005-02-04 16:00:32
 
Hello Henk,

Thank you very much for your quick answer, I missed the need for a getLabel function and your answer pointed it out. It works now, I continue an my application.

Groeten Luc
Add a Reply
Loading form, please wait
The website will not send you an e-mail when a reply is added to this topic

Back to Topics List