<?php
namespace admin\Controller;
use Think\Controller;
class SeoController extends CommonController {
 
 	public function _initialize(){
		 F('seo',NULL);
	}
	public function lists(){
		$seo=D('Seo')->get_list($map,true,'','');
		$this->assign('seo',$seo);
		$this->display();
	}
	public function allsave(){
		$id = I('post.id');
        $title = I('post.title');
		$keywords = I('post.keywords');
		$description = I('post.description');
		$num = 0;
		$data = M("Seo");
		if (is_array($id) && count($id)>0)
        {
            foreach($id as $k=>$v)
            {
                unset($map);
                $map['id'] = intval($v);
                $map['title']=trim($title[$k]);
                $map['keywords']=trim($keywords[$k]);
				$map['description']=trim($description[$k]);
				$data->save($map);
                $num++;
         
            }
        }
		if($num>0){
            $this->success('成功保存'.$num.'条信息！');
        }else{
            $this->error('未保存任何信息！');
        }
	}
	 public function add(){
		if(IS_POST)
		{
				$data = D("Seo");
				if (!$data->create()){
					$this->error($data->getError());
				}
				else
				{
					$data->add();
					$this->success('保存完成','lists');				
				}
		}
		else
		{
		 	$this->display();
		}
	}
	public function edit(){
		if(IS_POST)
		{
				$data = D("Seo");
				if (!$data->create()){
					$this->error($data->getError());
				}
				else
				{
					$data->save();
					$this->success('保存完成','lists');				
				}
		}
		else
		{
			$id=I('get.id','','intval');
			if ($id)
			{
				$data = M("Seo");
				$map['id']=$id;
				$show=$data->where($map)->find();
				$this->assign('show',$show);
				$this->display();
				//dump($show);
			}
			else
			{
			$this->error('非法请求');
			}
		}
	}
	
	public function delete(){
	
		$ids = I('request.id');
		$ids = is_array($ids)?implode(",",$ids):$ids;
		if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/",$ids))
		{
			$data = M("Seo");
			$s=$data->delete($ids);
			$this->success("成功删除{$s}条数据");
		}
		else
		{
		$this->error('请选择要删除的信息！');
		}
	
 	}
 
}
?>