Location: PHPKode > projects > lowbatCMS > lowbatcms/class/multi.php

  //  An example for defining your own data types using the lowbatCMS framework
  //  Here we define a data type ("Entry") with a primitive data member, a
  //  "TextField", and two complex data members, a "multimultifield" (defined
  //  here), and an "ImageField" (comes with lowbatCMS).
  //  The "multimultifield" itself contains a complex data member, 
  //  "multitestfield".
  //  The difference between Entry and Field is that an Entry is an object 
  //  which corresponds to a SQL table. An Entry is a single row in a table.
  //  A Field is a data member of an Entry. 
  //  A "primitive" Field is simply a column in the table, a complex Field can
  //  correspond to multiple columns and can contain logic to process the
  //  columns somehow. 
  //  Complex Fields are derived from the MultiField class.
  //  The displaying of data is defined in Smarty templates. Templates can be
  //  defined for Fields and Entries, and for displaying the data as well as
  //  editing.
  //  we'll walk you through this file, from simple to complex.
  //  First, of course, include the lowbatCMS definitions.
  require_once ('lowbatcms/lowbatcms.inc.php');
  //  define a custom field type
  class multitestfield extends MultiField {
  //  The actual definition of the Fields which constitute this complex Field 
  //  is done in the constructor.
    function multitestfield ($name = 'multitestfield') {
  //  define the name this Field should have
  //  define the constituting data members and their types
          'textfield' =>  'TextField',
          'intfield' => 'IntField'
  //  we have defined custom templates for this type. Please see those templates
  //  for information on how to build them correctly.
  //  a slightly more complex Field type, containing two primitive and one
  //  complex data member
  class multimultifield extends MultiField {
    function multimultifield ($name = 'multimultifield') {
  //  Here we present a slightly different way to define data members.
  //  Instead of just giving the type of the Field, pass an array containing
  //  'type' => 'Your type name'. This allows to pass more parameters to
  //  initialize the Field.
          'textfield'  => array ( 'type' => 'TextField' ),
          'intfield'   => array ( 'type' => 'IntField'  ),
  //  Here we use the multitestfield defined above.
          'multifield' => array ( 'type' => 'multitestfield' )
  //  We didn't define custom templates for this type. That means that for each
  //  Field, its default template is used and the resulting output concatenated.
  //  We can change the templates for the Fields separately, though:
  //  Of course, we could do that for every field, and with input templates as 
  //  well.
  //  an Entry building on the Fields defined above, and the ImageField coming
  //  with lowbatCMS
  class multientry extends Entry {
  //  The constructor usually takes two arguments: the ID of the dat record in
  //  the database, and a flag indicating whether you want to construct an
  //  Entry from POST, if there are any POSTDATA present.
  //  If you always want to construct from POST, you can drop this parameter
  //  and pass "true" to the parent c'tor. Similarly, if you never want to.
    function multientry ($id = 0, $usePostData=false) {
  //  Tell lowbatCMS in which SQL table you want to store your objects.
  //  The field definition is analogous to the definition of MultiFields.
      parent::Entry(array (
          'field1' => array (
            'type'   => 'TextField',
  //  an example of a parameter to pass
            'length' => 100),
          'field2' => 'multimultifield',
          'field3' => 'ImageField'), 
  //  pass on ID and use-POST-flag
        $id, $usePostData);
  //  Again, we could define templates for display and input mode here.
  //  ... but we don't.

  //  automatically resize images if they are too small or too big
  //  if you don't set this, images too large or small are rejected
  //  set size constraints for the image field
      $this->fields['field3']->setMaxImageSize(640, 480);
      $this->fields['field3']->setMinImageSize(320, 240);
Return current item: lowbatCMS