2011-01-03 7 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

변수 $ 행에 존재하지 않는 'bind'메서드를 호출하는 것이 문제입니다. $ row를 다음과 같이 정의했습니다. $ row = & JTable :: getInstance ('abc', 'Table'); 귀하의 문제가 바로 시작된다는 것을 의미합니다. 실패한 데이터베이스 내용을 가져 오려고합니다. 'abc'와 'Table'매개 변수를 실제 값으로 변경하는 것이 좋습니다. 샘플 데이터와 비슷합니다.

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

}