Brand.class.php 1.53 KB
<?php
/**
 * 默认控制器
 */
class Controller_Brand extends Controller_Abstract
{
    
    public function indexAction()
    {
        $banners = Facade_Index::getIndex(3);
        $this->_view['banners'] = $banners;
        $this->_view['brandTotal'] = Facade_Brand::getBrandTotal(1);
    }
    
    /**
     * 详情页
     */    
    public function detailAction()
    {
        $id = intval($this->_request->id);
        $info = Facade_Brand::getBrandbyID($id);
        $relas = Facade_Brand::getBrandNewsRelaByBrandID($id);
        $news = array();
        foreach ($relas as $rela)
        {
            $new = Facade_News::getOneById($rela['news_id']);
            if($new)
            {
                $news[] = $new;
            }
        }
        $news = array_slice($news, 0, 3);
        $this->_view['info'] = $info;
        $this->_view['news'] = $news;
    }
   
    /**
     * 获取品牌
     * 
     * @return json
     */
    public function getbrandAction()
    {
    	$brand = trim($this->_request->query('brand', ''));
    	$brand = str_replace(array('%'), array('\%'), $brand);
    	$brands = $list = array();
    	if($brand == '')
    	{
    	    $brands = Facade_Brand::getBrandByState(0, 200, 1);
    	}
    	else
    	{
    	    $brands = Facade_Brand::getBrandByName($brand, 1);
    	    
    	}
    	foreach($brands as $key => $brand)
    	{
    	    $list[$key] = array('id' => $brand['id'],'name' => $brand['name'],'logo'=> $brand['logo']);
    	}
    	return $this->returnJson(true, 200, array_values($list));
    }
    
    
}