Wie bekomme ich Daten aus der DB ins JForm?

Fragen zum Entwickeln eigener Addons?

Moderator: General Support Moderators

Forum rules
Forumregeln
Locked
tria1312
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Thu Oct 05, 2006 9:32 pm

Wie bekomme ich Daten aus der DB ins JForm?

Post by tria1312 » Sat Mar 01, 2014 10:46 pm

Hallo,

ich habe mir ein Formualr zusammengestellt.
Dazu habe ich eine XML-Datei (models/forms/test.xml) angelegt:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<form>
    <fields name="main">
        <fieldset name="primaryfieldset">
            <field
                    type="text"
                    name="my_text_field"
                    id="myTextField"
                    label="MY TEXT FIELD LABEL"
                    description="MY TEXT FIELD DESCRIPTION"
                    size="80"
                    maxLength="255" />
            <field
                    type="text"
                    name="my_other_text_field"
                    id="myOtherTextField"
                    label="MY OTHER TEXT FIELD LABEL"
                    description="MY OTHER TEXT FIELD DESCRIPTION"
                    size="80"
                    maxLength="255" />
            <field
                    type="editor"
                    name="my_editor_field"
                    id="myEditorField"
                    label="MY EDITOR FIELD LABEL"
                    description="MY EDITOR FIELD DESCRIPTION"
                    rows="5"
                    cols="200"/>
        </fieldset>
        <fieldset name="secondaryfieldset">
            <field
                    type="radio"
                    name="my_radio_field"
                    id="myRadioField"
                    label="MY RADIO FIELD LABEL"
                    description="MY RADIO FIELD DESCRIPTION">
                <option value="0">YES</option>
                <option value="1">NO</option>
            </field>
        </fieldset>
    </fields>
    <fields name="immutable">
        <!-- Fieldsets go here -->
    </fields>
    <fields name="extra">
        <fieldset name="publishing">
            <field
                    name="created"
                    type="calendar"
                    label="CREATED"
                    description="MY CREATED DESCRIPTION"
                    class="inputbox" size="20"
                    format="%Y-%m-%d %H:%M:%S"
                    filter="user_utc" />
            <field
                    name="created_by"
                    type="user"
                    label="CREATED BY"
                    description="CREATED BY DESCRIPTION" />
            <field
                    name="created_by_alias"
                    type="text"
                    label="CREATED BY ALIAS"
                    description="CREATED BY ALIAS DESCRIPTION"
                    class="inputbox"
                    size="20" />
        </fieldset>
        <fieldset name="metadata">
            <field
                    name="metakey"
                    type="textarea"
                    label="KEYWORDS"
                    description="KEYWORDS DESCRIPTION"
                    class="inputbox"
                    rows="3"
                    cols="30" />
            <field
                    name="metadesc"
                    type="textarea"
                    label="DESCRIPTION"
                    description="DESCRIPTION DESCRIPTION"
                    class="inputbox"
                    rows="3"
                    cols="30" />
        </fieldset>
    </fields>
</form>
Im Anschluss daran habe ich diese in die Datei views/test/tmpl/default.php eingebunden:

Code: Select all

<?php
defined('_JEXEC') or die('Restricted access'); 

// get the JForm object
$pathToXmlFile = JPATH_COMPONENT_ADMINISTRATOR.DS.'models/forms/test.xml';
$form = &JForm::getInstance('myform', $pathToXmlFile);

// get the JPane object
jimport( 'joomla.html.pane' );
$pane = JPane::getInstance('sliders', $pathToXmlFile);

$form->bind( $this->items);
?> 

<div id="editcell"> 

DIES IST EINE TESTSEITE

</div> 


<!-- normal fieldsets -->
<div class="width-60 fltlft">
    <?php
    // Iterate through the normal form fieldsets and display each one.
    foreach ($form->getFieldsets('main') as $fieldsets => $fieldset):
    ?>
    <fieldset class="adminform">
        <legend>
            <?php echo JText::_($fieldset->name.'_jform_fieldset_label'); ?>
        </legend>
		<dl>
		<?php
		// Iterate through the fields and display them.
		foreach($form->getFieldset($fieldset->name) as $field):
		    // If the field is hidden, only use the input.
		    if ($field->hidden):
		        echo $field->input;
		    else:
		    ?>
		    <dt>
		        <?php echo $field->label; ?>
		    </dt>
		    <dd<?php echo ($field->type == 'Editor' || $field->type == 'Textarea') ? ' style="clear: both; margin: 0;"' : ''?>>
		        <?php echo $field->input ?>
		    </dd>
		    <?php
		    endif;
		endforeach;
		?>
		</dl>
        </fieldset>
    <?php
    endforeach;
    ?>
</div>

<!-- extra fieldsets -->
<div class="width-40 fltrt">
    <?php echo $pane->startPane("extra"); ?>
        <?php
        // Iterate through the extra form fieldsets and display each one.
        foreach ($form->getFieldsets("extra") as $fieldsets => $fieldset):
        ?>
        <?php echo $pane->startPanel(JText::_($fieldset->name.'_jform_fieldset_label'), $fieldsets); ?>
        <fieldset class="panelform">
            <dl>
            <?php
            // Iterate through the fields and display them.
            foreach($form->getFieldset($fieldset->name) as $field):
                // If the field is hidden, just display the input.
                if ($field->hidden):
                    echo $field->input;
                else:
                ?>
                <dt>
                    <?php echo $field->label; ?>
                </dt>
                <dd>
                    <?php echo $field->input; ?>
                </dd>
                <?php
                endif;
            endforeach;
            ?>
            </dl>
        </fieldset>
        <?php echo $pane->endPanel(); ?>
        <?php
        endforeach;
        ?>
    <?php echo $pane->endPanel(); ?>
</div>
Und dann habe ich schliesslich diese Datei (views/test/view.html.php):

Code: Select all

<?php 
defined('_JEXEC') or die( 'Restricted Access' ); 
jimport( 'joomla.application.component.view' ); 
jimport( 'joomla.filesystem.file' );

class MYCOMPViewTest extends JView 
{ 
    /* Daten */
    var $_modelStandard = NULL;
    var $_modelConfig = NULL;
    var $_modelLaunchpad = NULL;
    var $_modelLaunchpads = NULL;
    var $_modelPerson = NULL;
    var $_modelEvent = NULL;
    
    function display($tpl = null) 
    { 
         $this->_modelStandard = $this->getModel('standard');
         $this->_modelConfig = $this->getModel('config');
         $configData = $this->_modelConfig->getData();
         $this->_modelEvent = $this->getModel('event');
         $eventData = $this->_modelEvent->getData(11);
          
        JToolBarHelper::title(JText::_('COM_MYCOMP').' - '.JText::_('COM_MYCOMP_TEST_SECTION_NAME').'<br>'.$actEventText.'', 
                              'generic.png' ); 
                
        $this->assignRef('items', $eventData); 
        
      	parent::display($tpl); 
    } 
} 
?>
??? ??? ???
Nun habe ich in der default.php die Daten aus der DB mit dem Formular verbunden. Nur leider wird mir nichts angezeigt. Habe ich das was falsch gemacht?


Gruß
tria1312

Locked

Return to “Entwicklerforum”