第1行第2行的错误:PHP公共函数中文档末尾的额外内容

时间:2017-06-09 07:55:47

标签: php mysql xml zend-framework

我有功能:

    protected function getFeedCategory($lng) {
    $params = $this->dispatcher->getParam('format', null, '/id/1');
    $pArr = explode("/", $params);
    $limit = 10;
    //varDump($pArr);
    //varDump($this->dispatcher->getParams());
    try {

        $categoryId = (isset($pArr[2])) ? (int)$pArr[2] : 1;
        $cache_key = 'Frontend_Feed_getFeedCategory_' . $categoryId . '_limit_' . $limit . '_' . $lng;
        //$this->_cache->delete($cache_key);
        if (($items = $this->_cache->get($cache_key)) == null || $this->cache_renew_data->can_refrash) {
            $items = $this->db->fetchAll("SELECT n.date_show, n.title_{$lng} AS title,n.id,n.is_ru,n.is_md,n.is_new,n.thumb_md,n.thumb_ru,
                                          n.thumb_en
                                          FROM news AS n
                                          LEFT JOIN news_categories AS nc ON nc.news_id=n.id
                                          WHERE n.is_{$lng} = 1 AND n.date_show < '" . date(MYSQL_DATE_FORMAT) . "'
                                          AND nc.categories_id = {$categoryId}
                                          ORDER BY n.date_show DESC LIMIT 0," . $limit);
            //varDump($items);
            if (count($items)) {
                $this->_cache->save($cache_key, $items);
            }
        }


    } catch (\Exception $e) {
        return $this->getAll($lng, 20);
    }

    return $items;
}

第1行第2行的返回错误:文档末尾的额外内容,我如何修复它?

case 'feed-category' : $items = $this->getFeedCategory($lng); break;

此代码通过网址获取内容!

1 个答案:

答案 0 :(得分:0)

public function getFeedCategory($lng) {
    $params = $this->dispatcher->getParam('format', null, '/id/1');
    $pArr = explode("/", $params);
    $limit = 10;

    try {
        $categoryId = (isset($pArr[2])) ? (int)$pArr[2] : 1;
        $cache_key = 'Frontend_Feed_getFeedCategory_' . $categoryId . '_limit_' . $limit . '_' . $lng;

        if (($items = $this->_cache->get($cache_key)) == null || $this->cache_renew_data->can_refrash) {
            $items = $this->db->fetchAll("SELECT n.date_show, n.title_{$lng} AS title,n.id,n.is_ru,n.is_md,n.is_new,n.thumb_md,n.thumb_ru,
                                          n.thumb_en
                                          FROM news AS n
                                          LEFT JOIN news_categories AS nc ON nc.news_id=n.id
                                          WHERE n.is_{$lng} = 1 AND n.date_show < '" . date(MYSQL_DATE_FORMAT) . "'
                                          AND nc.categories_id = {$categoryId}
                                          ORDER BY n.date_show DESC LIMIT 0," . $limit);

            if (count($items)) {
                $this->_cache->save($cache_key, $items);
                return $items;
            }
        }
    } catch (\Exception $e) {
        return $this->getAll($lng, 20);
    }
}