PHP架構queryphp課程:入門七 給模板賦值

來源:互聯網
上載者:User
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")); ?>


  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.