Heim  >  Artikel  >  Backend-Entwicklung  >  PHP框架queryphp课程:入门七 给模板赋值

PHP框架queryphp课程:入门七 给模板赋值

WBOY
WBOYOriginal
2016-06-13 13:03:52694Durchsuche

PHP框架queryphp教程:入门七 给模板赋值

可以使用smarty模板引擎,参见core/view.php类

但是最好不使用smarty类,直接使用php原生模板标签,因为还可以给模板赋对象。比如pager分面类。

赋值例子:

class productsRouter extends controller{?
? function index()?
? {?
? ? ?Return false;?
? }?
? public function show() {?
? ? ? $id=intval($_GET['proid']);?
? ? if($id!='')?
? ? {?
? ? ? $pro=M("products");?
? ? ? $pro->get($id);?
? ? ? //给模板中$proshow赋值?
? ? ? $this->proshow=$pro->edit()->getData();?
? ? ? if($pro->getPdflist1()!='' )?
? ? ? {?
? ? ? ? $pdflist=explode(",",$pro->getPdflist1());?
? ? ? ? $sql='';?
? ? ? ? if(is_array($pdflist))?
? ? ? ? {?
? ? ? ? ? foreach($pdflist as $key=>$value)?
? ? ? ? ? {?
? ? ? ? ? ? $sql.=intval($value).",";?
? ? ? ? ? }?
? ? ? ? ? if($sql!='')?
? ? ? ? ? {?
? ? ? ? ? ? ?$sql=substr($sql,0,-1); ? ?
? ? ? ? ? ? ?$yangben=M("yangben");?
? ? ? ? ? ? ?//给模板中$pdflist赋值,其中是数组?
? ? ? ? ? ? ?$this->assign("pdflist",$yangben->select("yangid,yangname,pdfimage")->whereIn("yangid",$sql)->fetch()->getRecord());?
? ? ? ? ? }?
? ? ? ?}?
? ? ? }?
? ? ? //产品导航部分内容输出?
? ? ? $nav=DM("navpro");?
? ? ? $this->assign("navbar",$nav->getTree());?
? ? }?
? }?
? public function prolist() {?
? ? //产品导航部分内容输出 树形输出?
? ? ? $nav=DM("navpro");?
? ? $this->assign("navbar",$nav->getTree());?
? ? $pro=M("products");?
? ? $smallid=intval($_GET['smallid']);?
? ? $count=$pro->where("classid",$smallid)->count();?
? ? //直接给模板赋值对像?
? ? $this->pager=C("pager");?
? ? $this->pager->setPager($count,10); //默认是使用$_GET['page']取得分页页数可以是这样是一样的setPager($count,10,'page');
? ? //给模板赋值,list为内容列表 //上面设置过where("classid",$smallid),所以下面不用设置。因为默认取得总数不会清除查询条件的,其它会清除
? ? $this->list=$pro->select("id,classid,typeno,title,dest,ico,img")->orderby("id desc")->limit($this->pager->offset(),10)->fetch()->getRecord();?

? ? $this->assign("smallid",$smallid);?
? }?
}?
?>?

模板中使用pager对象

getWholeBar(url_for("products/prolist/smallid/".$smallid."/page/:page")); ?>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn