2013-03-01 114 views
1

我是joomla.i的新手設計一個窗體組件,用於理解像聯繫form.i的窗體組件,我很容易看到它,並且它在前端可以看到現在我想了解如何數據庫用於joomla.how我發送表單值到數據庫哪些文件我們必須使用模型視圖控制器。

// 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') 

幫我提前

回答

2

Here感謝有用於建立官方的文檔在的Joomla MVC模式的一種形式。

表單進入你的tmp/default.php(site/views/updhelloworld/tmpl/default.php),然後設置你的動作,當你提交表單時,你的「重定向」到控制器(site/controllers/updhelloworld .PHP),在這裏你必須檢查你的表單數據

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

,然後用行動在模型

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

在模型中使用你的數據庫。

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; 
      } 
    }