2011-01-03 9 views
0

私の仕事のためのカスタムコンポーネントを書いています。私はそれを構築するためにhelloコンポーネントを使用しています。私は、フォームを編集して保存すると、私はこのエラーを取得:joomla function bind問題

Call to a member function bind() on a non-object

マイコード:

function save() 
{ 
    global $option; 

    JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_abc'.DS.'tables'); 
    $row =& JTable::getInstance('abc', 'Table'); 
    if(!$row->bind(JRequest::get('post'))) 
    { 
     JError::raiseError(500, $row->getError()); 
    } 
    $row->message = JRequest::getVar('message', '','post', 'string', JREQUEST_ALLOWRAW); 

    if(!$row->store()){ 
     JError::raiseError(500, $row->getError()); 
    } 

    switch($this->_task) 
    { 
     case 'apply': 
      $msg = 'Change Saved'; 
      $link = 'index.php?option='.$option.'&task=edit&cid[]='.$row->id; 
      break; 
     case 'save': 
      $msg = 'Saved'; 
      $link = 'index.php?option='.$option; 
      break; 
     default: 
    } 
    $this->setRedirect($link, $msg); 
} 

問題は、それがインスタンスを作成することができないということです。

誰かが解決策を知っている場合は教えてください。

ありがとうございました。

答えて

1

問題は、変数$ rowに存在しないメソッド 'bind'を呼び出すことです。 $ rowを次のように定義しました。$ row = & JTable :: getInstance( 'abc'、 'Table');あなたの問題がすぐそこから始まることを意味します。失敗したデータベースコンテンツを取得しようとしています。私はあなたが本当に何かにパラメータ 'abc'と 'テーブル'を変更することをお勧めします、それは私にサンプルデータのように見えます。

0

フェッチするテーブル名データはjos_abcです。保存機能はmy_componet/controller.phpです。コントローラのクラス名はXyzControllerです:

class XyzController extends JController { 

    function __construct() { 
     //Get View 
     if(JRequest::getCmd('view') == '') { 
      JRequest::setVar('view', 'default'); 
     } 
     $this->item_type = 'Default'; 
     parent::__construct(); 
    } 

    function save() 
    { 
     global $option; 

     JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_tripplanner'.DS.'tables'); 
     $row1 =& JTable::getInstance('xyz', 'jos_abc'); 
     if(!$row1->bind(JRequest::get('post'))) 
     { 
      JError::raiseError(500, $row->getError()); 
     } 
     $row->message = JRequest::getVar('message', '','post', 'string', JREQUEST_ALLOWRAW); 

     if(!$row->store()){ 
      JError::raiseError(500, $row->getError()); 
     } 

     switch($this->_task) 
     { 
      case 'apply': 
       $msg = 'Change Saved'; 
       $link = 'index.php?option='.$option.'&task=edit&cid[]='.$row->id; 
       break; 
      case 'save': 
       $msg = 'Saved'; 
       $link = 'index.php?option='.$option; 
       break; 
      default: 

     } 
     $this->setRedirect($link, $msg); 
    } 
} 

その後も、私は保存できませんよ、私は「非オブジェクトのメンバ関数のバインド()の呼び出し」を取得します。

次のコードがお手伝いします
+0

私はSOLNのおかげです –

1

function addComment($option) 
{ 
    global $mainframe; 
    $row =& JTable::getInstance('comment' , 'Table'); 
    if (!$row->bind(JRequest::get('post'))) 
    { 
    JError::raiseError(500, $row->getError()); 
    } 

    $row->comment_date = date ('Y-m-d H:i:s'); 

    $user =& JFactory::getUser(); 

    if($user->id) 
    { 
    $row->user_id = $user->id; 
    } 

    if(!$row->store()) 
    { 
    JError::raiseError(500, $row->getError()); 
    } 

    $link = JRoute::_('index.php?option='.$option.'&id='.$row->id . '&task=view'); 
    $mainframe->redirect($link, 'Comment Added'); 

} 
関連する問題