php编码中的问题

时间:2010-05-11 06:42:56

标签: php joomla

大家好我不熟悉PHP和Joomla,我在Joomla中开发了一个组件,但是我的代码给了我错误。我试图解决这个问题,但我无法解决它。所以有人能告诉我我的代码有什么问题吗?提前谢谢。

以下是我的两个文件:

第一次view.html.php

defined('_JEXEC') or die('=;)');

jimport('joomla.application.component.view');

class namnamViewlistrestaurant extends JView
{
    function display($tpl = null)
    {
        $item = 'item';
        RestUser::RestrictDirectAccess();
        //-- Custom css
        JHTML::stylesheet( 'style.css', 'components/com_namnam/assets/css/' );

        $cuisine=Lookups::getLookup('cuisine');
        $lists['cuisine'] = JHTML::_('select.genericlist', $cuisine, 'idcuisine[]', 'class="inputbox" size="7"', 'value', 'text', $item->idcuisine);

        $category=Lookups::getLookup('restcategory');
        $lists['category'] = JHTML::_('select.genericlist', $category, 'idcategory[]', 'class="inputbox" multiple="multiple" size="7"', 'value', 'text', $item->idcategory);

        $items  = & $this->get('Data');
        $pagination =& $this->get('Pagination');

        $lists = & $this->get('List');

        $this->assignRef('items', $items);
        $this->assignRef('pagination', $pagination);
        $this->assignRef('lists', $lists);
        parent::display($tpl);

    }//function

}//class

第二名是listrestaurant.php

defined('_JEXEC') or die('=;)');

jimport('joomla.application.component.model');

class namnamModellistrestaurant extends JModel
{
    var $_data;
    var $_total = null;
    var $_pagination = null;

    function __construct()
    {
        parent::__construct();
        global $mainframe, $option;

        $limit      = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
        $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
        $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
        $this->setState('limit', $limit);
        $this->setState('limitstart', $limitstart);
    }

    function _buildQuery()
    {
        $where = array();
        $where[]=" idowner=".RestUser::getUserID()." ";
        if ($this->search)
        {
            $where[] = 'LOWER(name) LIKE \''. $this->search. '\'';
        }

        $where =( count($where) ) ? ' WHERE ' . implode( ' AND ', $where ) : '';
        $orderby = '';

        #_ECR_MAT_FILTER_MODEL1_

        if (($this->filter_order) && ($this->filter_order_Dir))
        {
            $orderby    = ' ORDER BY '. $this->filter_order .' '. $this->filter_order_Dir;
        }

        $this->_query = ' SELECT *'
        . ' FROM #__namnam_restaurants '
        . $where
        . $orderby
        ;

        return $this->_query;
    }


    function getData()
    {
        if (empty($this->_data))
        {
            $query = $this->_buildQuery();
            $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
        }
        return $this->_data;
    }

    function getList()
    {
        // table ordering
        $lists['order_Dir'] = $this->filter_order_Dir;
        $lists['order']     = $this->filter_order;

        // search filter
        $lists['search']= $this->search;

        return $lists;
    }

    function getTotal()
    {
        // Load the content if it doesn't already exist
        if (empty($this->_total))
        {
            $query = $this->_buildQuery();
            $this->_total = $this->_getListCount($query);
        }

        return $this->_total;
    }

    function getPagination()
    {
        // Load the content if it doesn't already exist
        if (empty($this->_pagination))
        {
            jimport('joomla.html.pagination');
            $this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
        }

        return $this->_pagination;
    }




}//class

错误是:

  

注意:尝试在第26行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ views \ listrestaurant \ view.html.php中获取非对象的属性

     

注意:尝试在第29行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ views \ listrestaurant \ view.html.php中获取非对象的属性

     

注意:未定义的属性:namnamModellistrestaurant :: $在第38行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ models \ listrestaurant.php中搜索

     

注意:第48行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ models \ listrestaurant.php中的未定义属性:namnamModellistrestaurant :: $ filter_order

     

注意:未定义的属性:namnamModellistrestaurant :: $在第38行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ models \ listrestaurant.php中搜索

     

注意:第48行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ models \ listrestaurant.php中的未定义属性:namnamModellistrestaurant :: $ filter_order

     

注意:第76行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ models \ listrestaurant.php中的未定义属性:namnamModellistrestaurant :: $ filter_order_Dir

     

注意:第77行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ models \ listrestaurant.php中的未定义属性:namnamModellistrestaurant :: $ filter_order

     

注意:未定义的属性:namnamModellistrestaurant :: $在第80行的C:\ wamp \ www \ namnam.com \ components \ com_namnam \ models \ listrestaurant.php中搜索

2 个答案:

答案 0 :(得分:1)

我会说错误很自我解释。究竟是什么问题?

view.html.php中,您拥有变量$item并尝试访问属性$item->idcuisine$item->idcategory但实际上,$item只是一个字符串

 $item = 'item';

因此无法拥有属性。


listrestaurant.php中,您的班级似乎没有属性searchfilter_order。您没有在类中定义它们,但我不知道父类JModel

答案 1 :(得分:-1)

defined('_JEXEC') or die('=;)');

jimport('joomla.application.component.model');

class namnamModelajax extends JModel
{
var $_data;
var $_total = null;
var $_pagination = null;

function __construct()
{
    parent::__construct();
    global $mainframe, $option;

    $limit      = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
    $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
    $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
    $this->setState('limit', $limit);
    $this->setState('limitstart', $limitstart);
}

function _buildQuery()
{
    $where = array();
    $where[]=" idowner=".RestUser::getUserID()." ";
    if ($this->search)
    {
        $where[] = 'LOWER(name) LIKE \''. $this->search. '\'';
    }

    $where =( count($where) ) ? ' WHERE ' . implode( ' AND ', $where ) : '';
    $orderby = '';

    #_ECR_MAT_FILTER_MODEL1_

    if (($this->filter_order) && ($this->filter_order_Dir))
    {
        $orderby    = ' ORDER BY '. $this->filter_order .' '. $this->filter_order_Dir;
    }

    $this->_query = ' SELECT *'
    . ' FROM #__namnam_restaurants '
    . $where
    . $orderby
    ;

    return $this->_query;
}


function getSponRest($limiter)
{
    $db=$this->_db;
    $query="SELECT id as id,restaurant_name as name FROM #__namnam_restaurants where published=1 and issponsored=1 limit $limiter";
    $db->setQuery($query);
    //$result =$db->loadResult();
    $result =$db->loadObjectList();
    return $result;
}

function getAllRestaurants($limiter)
{
    $db=$this->_db;
    $query="SELECT id as id,restaurant_name as name FROM #__namnam_restaurants where published=1 limit $limiter";
    $db->setQuery($query);
    $result =$db->loadObjectList();
    return $result ;
}

function getStaffFavs($limiter)
{
    $db=$this->_db;
    $query="SELECT id as id,restaurant_name as name FROM #__namnam_restaurants where published=1 and stafffav=1 limit $limiter";
    $db->setQuery($query);
    $result =$db->loadObjectList();
    return $result ;
}


function getCuisines()
{
    $db=$this->_db;
    $query="select id as id,name as name from jos_namnam_cuisine where id in(select distinct idcuisine from jos_namnam_relcuisine)";
    $db->setQuery($query);
    $result =$db->loadObjectList();
    return $result ;
}


function getCategories()
{
    $db=$this->_db;
    $query="select id as id,name as name from jos_namnam_restcategory where id in(select distinct idcategory from jos_namnam_relcategory)";
    $db->setQuery($query);
    $result =$db->loadObjectList();
    return $result ;
}
function getRestByCuisine($limiter,$id)
{
    $db=$this->_db;
    $query="SELECT j.id as id, j.restaurant_name as name FROM jos_namnam_restaurants j, jos_namnam_relcuisine b where b.idforeign=j.id and b.idcuisine=$id limit $limiter";
    $db->setQuery($query);
    $result =$db->loadObjectList();
    return $result ;
}
function getRestByCategory($limiter,$id)
{
    $db=$this->_db;
    $query="SELECT j.id as id, j.restaurant_name as name FROM jos_namnam_restaurants j, jos_namnam_relcategory b where b.idforeign=j.id and b.idcategory=$id limit $limiter";
    $db->setQuery($query);
    $result =$db->loadObjectList();
    return $result ;
}

function RegisterUser($post)
{

}

function login()
{
    // Check for request forgeries
    //JRequest::checkToken('request') or jexit( 'Invalid Token' );

    global $mainframe;

    $options = array();
    $options['remember'] = JRequest::getBool('remember', false);
    $options['return'] = $return;

    $credentials = array();
    //$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
    //$credentials['password'] = JRequest::getString('passwd', '', 'post', JREQUEST_ALLOWRAW);

    $credentials['username'] = JRequest::getString('username');
    $credentials['password'] = JRequest::getString('passwd');

    //preform the login action
    $error = $mainframe->login($credentials, $options);

    if(!JError::isError($error))
    {
        //login succeeded
        return true;
    }
    else
    {
        //login failed
        //$arrayError[0]="#error";
        //$arrayError[1]="Invalid Username or Password";
        //$arrayError[2]="#error";
        //return '{"jsonValidateReturn":'.json_encode($arrayError).'}';
        print_r($error);
        $msg="Please enter correct Username and Password";
        return $msg;

    }
}



function getRestDetails($restID){

    $db=$this->_db;
    //$query="SELECT id as id,restaurant_name as name FROM #__namnam_restaurants where published=1 limit $limiter";
    $query='select r.id as id, r.restaurant_name as name,
        (select group_concat(a.name) as cuisinename from jos_namnam_cuisine a,jos_namnam_relcuisine b
        where a.id=b.idcuisine and b.idforeign=r.id) as cuisine,
        (select group_concat(rcat.name) as categoryname from jos_namnam_restcategory rcat,jos_namnam_relcategory relcat
        where rcat.id=relcat.idcategory and relcat.idforeign=r.id) as category,
        r.budget as budget,
        (SELECT group_concat(concat_ws("/",cty.cityname,dst.districtname,cnt.name)) as location
        FROM jos_namnam_restlocations restloc,jos_namnam_cities cty,jos_namnam_districts dst,
        jos_namnam_countries cnt where cty.id=restloc.idcity and dst.id=restloc.iddistrict and
        cnt.id=restloc.idcountry and restloc.idrestaurant=r.id) as locations,
        r.hotline as hotline,
        r.logo as logo,
        (select group_concat(rrloc.phone) as phone from jos_namnam_restlocations rrloc where rrloc.idrestaurant=r.id) as branchphones
        from jos_namnam_restaurants r where r.id='.$restID;

    $db->setQuery($query);
    $result =$db->loadObjectList();
    return $result ;


}


function getData()
{
    if (empty($this->_data))
    {
        $query = $this->_buildQuery();
        $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
    }
    return $this->_data;
}

function getList()
{
    // table ordering
    $lists['order_Dir'] = $this->filter_order_Dir;
    $lists['order']     = $this->filter_order;

    // search filter
    $lists['search']= $this->search;

    return $lists;
}

function getTotal()
{
    // Load the content if it doesn't already exist
    if (empty($this->_total))
    {
        $query = $this->_buildQuery();
        $this->_total = $this->_getListCount($query);
    }

    return $this->_total;
}

function getPagination()
{
    // Load the content if it doesn't already exist
    if (empty($this->_pagination))
    {
        jimport('joomla.html.pagination');
        $this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
    }

    return $this->_pagination;
}

}//class