0

データベースに情報を保存するフォームを作成しようとしています...かなり簡単に聞こえますが、ドキュメントが面倒です(または私はそれほど賢くありません)。送信時にいくつかのパラメーターを送信したいだけで、反対側のキャッチでそれらをデータベースに保存します....

だから、私はこれをしました:

私の中でcomponent/views/myview/tmpl/default.php私はこれを書きました:

<form action="index.php">
<input type="submit" value="test" />
</form>

次に、ファイルview.html.phpに移動して/mycomponent/view/component/view.html、これを行います。

$this->get('SaveClient');

私のモデルでは、これを行いました(試してみるためだけに):

public function getSaveClient(){

  $query ="
      Insert into client ( `id_client` ,`test`)
      VALUES 
      (NULL , '1')
  ";
  $db = & JFactory::getDBO();
  $db->Execute($query);
}

しかし、それでも..機能しません。機能させる方法はありますか??

ありがとう!

4

2 に答える 2

2

テーブル名が正しく定義されていません。である必要があります#__tablename。これを試してもうまくいかない場合は、代わりに次のコードを使用してみてください。

public function getSaveClient($test){ 
    $db = JFactory::getDBO();
    $data = new stdClass();
    $data->id_client = null;
    $data->test = $test;
    $db->insertObject( '#__tablename', $data, 'id_client' );  
}
于 2012-11-06T21:16:54.613 に答える
1

次のようなレイアウトdefault.phpフォーム

<form action="<?php echo JRoute::_('index.php?option=com_example&view=example&layout=default'); ?>" method="post" name="adminForm">
<input size="60" type="text" name="settings[key]" id="settings[key]" value="<?php echo (isset ($this->settings ['key']) ? htmlspecialchars ($this->settings ['key']) : ''); ?>" />
// More html entites.
<input type="hidden" name="task" value="" />
</form>

あなたのview.html.php//あなたのクラス

public function display ($tpl = null)
    {
        $document = &JFactory::getDocument ();
        $document->addStyleSheet ('components/com_example/assets/css/example.css');

        $model = &$this->getModel ();
        $this->settings = $model->getSettings ();
        $this->form = $this->get ('Form');
        $this->addToolbar ();
        parent::display ($tpl);
    }

あなたのモデルあなたのモデルクラス

public function saveSettings ()
    {
        //Get database handle
        $db = $this->getDbo ();
        $api_settings = array();
        $mainframe = JFactory::getApplication();
        //Read Settings
        $settings = JRequest::getVar ('settings');
                //Insert new settings
          foreach ($settings as $k => $v)
          {

             $sql = "INSERT INTO #__yourtable ( setting, value )" . " VALUES ( " . $db->Quote ($k) . ", " . $db->Quote ($v) . " )";
            $db->setQuery ($sql);
            $db->query ();
          }
              }
于 2012-11-07T04:22:45.087 に答える