2013-03-01 1 views
1

je suis nouveau à joomla.i concevoir un composant de forme pour comprendre le modèle mvc comme formulaire de contact.i formez le spectacle facilement et il est visible en face avant maintenant je veux comprendre comment base de données est utilisée dans joomla.how j'envoie des valeurs de formulaire à la base de données quels fichiers nous devons utiliser le contrôleur de vue de modèle.

// no direct access 
defined('_JEXEC') or die; 
JHtml::_('behavior.keepalive'); 
JHtml::_('behavior.tooltip'); 
JHtml::_('behavior.formvalidation'); 

//Load admin language file 
$lang = JFactory::getLanguage(); 
$lang->load('com_new', JPATH_ADMINISTRATOR); 
$document = &JFactory::getDocument(); 
$document->addStyleSheet(JURI::base() . 'C:\wamp\www\j25\components\com_new\assets\demo.css'); 
?> 
<div class="item_fields"> 
<?php #if($this->item) : ?> 
<form id="form-feild" action="#" method="post" class="form-validate" enctype="multipart/form-data"> 

<table class="body"> 
     <tr><td><?php echo $this->form->getLabel('firstname'); ?></td><td></td><td><?php echo $this->form->getInput('firstname'); ?></td></tr> 
     <tr><td><?php echo $this->form->getLabel('middlename'); ?></td><td></td><td><?php echo $this->form->getInput('middlename'); ?></td></tr> 
     <tr><td><?php echo $this->form->getLabel('lastname'); ?></td><td></td><td><?php echo $this->form->getInput('lastname'); ?></td></tr> 
     <tr><td><?php echo $this->form->getLabel('gender'); ?></td><td></td><td><?php echo $this->form->getInput('gender'); ?></td></tr> 
     <tr><td><?php echo $this->form->getLabel('dateofbirth'); ?></td><td></td><td><?php echo $this->form->getInput('dateofbirth'); ?></td></tr> 
     <tr><td><?php echo $this->form->getLabel('address'); ?></td><td></td><td><?php echo $this->form->getInput('address'); ?></td></tr> 
     <tr><td><?php echo $this->form->getLabel('state'); ?></td><td></td><td><?php echo $this->form->getInput('state'); ?></td></tr> 
     <tr><td><?php echo $this->form->getLabel('postcode'); ?></td><td></td><td><?php echo $this->form->getInput('postcode'); ?></td></tr> 
     <tr><td><?php #echo 'index.php?option=com_details&task=feild.save'; ?></td></tr>  
    <table> 
<div> 
    <button type="submit" class="validate"><span><?php echo JText::_('JSUBMIT'); ?></span></button> 
    <?php echo JText::_('or'); ?> 
<a href="<?php echo JRoute::_('index.php?option=com_new&task=new.cancel'); ?>" title="<?php echo JText::_('JCANCEL'); ?>"><?php echo JText::_('JCANCEL'); ?></a> 

    <input type="hidden" name="option" value="com_new" /> 
    <input type="hidden" name="task" value="new.save" /> 
    <?php echo JHtml::_('form.token'); ?> 
    </div> 
    </form> 
note:->how action work on joomla.In few files i find like JRoute::_('index.php?option=com_new&task=new.save') 

aide me remercie à l'avance

Répondre

2

Salut Here il y a docs officiels pour construire une forme avec un motif mvc dans joomla. Le formulaire va dans votre tmp/default.php (site/views/updhelloworld/tmpl/default.php), puis définissez votre action et lorsque vous soumettez le formulaire, vous êtes "redirigé" vers le contrôleur (site/controllers/updhelloworld .php), ici, vous devez vérifier vos données de formulaire

$data = JRequest::getVar('jform', array(), 'post', 'array'); 

puis utilisez l'action dans votre modèle

$upditem  = $model->updItem($data); 

dans votre modèle vous utilisez votre base de données.

public function updItem($data) 
    { 
    // set the variables from the passed data 
    $id = $data['id']; 
    $greeting = $data['greeting']; 

    // set the data into a query to update the record 
      $db    = $this->getDbo(); 
      $query = $db->getQuery(true); 
    $query->clear(); 
      $query->update(' #__helloworld '); 
      $query->set(' greeting = '.$db->Quote($greeting)); 
      $query->where(' id = ' . (int) $id); 

      $db->setQuery((string)$query); 

    if (!$db->query()) { 
     JError::raiseError(500, $db->getErrorMsg()); 
      return false; 
    } else { 
      return true; 
      } 
    }