歡迎使用skymvc框架,簡單易用的php框架

skymvc是一款輕量、簡單易用的php mvc框架,通過多個項目實踐改良。php

特色:html

1.mvc架構緩存

2.m、v、c之間能夠互相調用架構

3.簡單的路由控制 R("/index.php");mvc

4.強大的模版,模版能夠直接調用m和c內容app

5.語言包支持框架

6.hook機制

7.數據緩存

8.全文索引

9.靜態生成post

控制器:網站

index.ctrl.phpthis

<?php
class indexControl extends skymvc
{
	function __construct()
	{
		parent::__construct();
		$this->loadModel(array("article"));
	}

	public function onDefault()
	{
		$option=array();
 		$rscount=true;
		$data=$this->article->select($option,$rscount);
		$pagelist=$this->pagelist($rscount,20,APPINDEX."?m=index&a=default");
		$this->smarty->assign(array(
			"data"=>$data,
			"rscount"=>$rscount,
			"pagelist"=>$pagelist
		));
		$this->smarty->display("index.html");
	}
	
	public function onShow(){
		$id=get('id','i');
		$id && $data=$this->article->selectRow(array("where"=>"id=$id"));
		$this->smarty->assign(array(
			"data"=>$data
		));
		$this->smarty->display("show.html");
	}
	
	public function onAdd(){
		$id=get('id','i');
		$id && $data=$this->article->selectRow(array("where"=>"id=$id"));
		$this->smarty->assign(array(
			"data"=>$data
		));
		$this->smarty->display("add.html");
	}
	
	public function onSave(){
		$id=get_post("id","i");
		$data["title"]=get_post("title","h");
		$data["content"]=get_post("content","h");
		$data["dateline"]=time();
		if($id){
			$this->article->update($data,array('id'=>$id));
		}else{
			$this->article->insert($data);
		}
		$this->gomsg($this->lang["save_success"]);
	}
	
	public function onDelete(){
		$id=get_post("id","i");
		$this->article->delete("id=$id");
		$this->gomsg($this->lang["delete_success"]);
	}
}

?>

模型:article.model.php

<?php
class articleModel extends model
{
	public $base;
	function __construct(&$base)
	{
		parent::__construct($base);
		$this->base=$base;
		$this->table='article';
	}

	 
	
}

?>

View模版:

{include file="header.html"}
<table class="table table-bordered" width="100%">
	<tr>
    <td width="11%">ID</td>
    <td width="49%">標題</td>
    <td width="20%">發佈時間</td>
    <td width="20%">操做</td>
    </tr>
    
    {foreach item=c from=$data}
    <tr>
    <td>{$c.id}</td>
    <td><a href="{R("$appindex?m=index&a=show&id=$c.id")}">{$c.title}</a></td>
    <td>{$c.dateline|date:Y-m-d H:i:s}</td>
    <td><a href="{R("$appindex?m=index&a=add&id=$c.id")}">編輯</a> 
    	<a href="{R("$appindex?m=index&a=delete&id=$c.id")}">刪除</a></td>
    </tr>
    {/foreach}
</table>
{$pagelist}
{include file="footer.html"} 

QQ交流羣:61469962
官方網站:http://www.skymvc.com 歡迎你們使用交流。

下載地址: http://www.skymvc.com/down.html

相關文章
相關標籤/搜索