Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
joomla函数绑定问题_Joomla_Joomla1.5 - Fatal编程技术网

joomla函数绑定问题

joomla函数绑定问题,joomla,joomla1.5,Joomla,Joomla1.5,我正在为我的工作编写一个自定义组件。我正在使用hello组件来构建它。当我编辑并保存表单时,会出现以下错误: 对非对象调用成员函数bind() 我的代码: function save() { global $option; JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_abc'.DS.'tables'); $row =& JTable::getInstance('abc',

我正在为我的工作编写一个自定义组件。我正在使用hello组件来构建它。当我编辑并保存表单时,会出现以下错误:

对非对象调用成员函数bind()

我的代码:

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);
}
问题是它无法创建实例

如果有人知道解决方案,请告诉我


谢谢。

问题在于调用变量$row上不存在的方法“bind”。
您将$row定义为:$row=&JTable::getInstance('abc','Table');这意味着你的问题就从这里开始。它正在尝试获取失败的数据库内容。我建议您将参数“abc”和“Table”更改为真实的参数,对我来说它看起来像示例数据。

我要获取的表名数据是
jos\u abc
。save函数位于
my\u 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);
    }
}

即使我无法保存,我也会得到“对非对象调用成员函数bind()”。

以下代码将帮助您:

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

}