Home >Backend Development >PHP Tutorial >php skymvc A lightweight and simple php_PHP tutorial

php skymvc A lightweight and simple php_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:27:25831browse

The modified framework is mainly used to achieve collaborative development among multiple programmers and the implementation of the mvc development model. skymvc adopts the mvc development method, and the framework itself is easy to expand. As the basic framework of the Skynet Project, skymvc adheres to the fine tradition of ease of use, ease of learning, and joint development. We are committed to creating an excellent PHP
mvc framework. Everyone is welcome to make suggestions.
1. Create configuration files skyMVC supports automatic creation of website directories: enter http://locahost/skymvc/install.php to automatically create
file directories. If you want to recreate it after creating it, delete the install.lock file and you can.
Automatic creation is recommended.
It can also be created manually: the directories can be customized
When customizing the directory, the program needs to be configured accordingly
admin backend directory
admin/model
admin/ctrl
attach
Uploaded attachment directory
ctrl control file directory
data directory
data/config.php
Configuration file
data/cache cache directory
data/cache/css
css cache
data/cache/file file cache
data/cache/tpl template cache
data/cache/js
js cache
model model file directory
tpl template directory
tpl/admin backend template
tpl/default
Default template
js directory
plugin plug-in directory
admin.php backend entry file
index.php frontend entry file
2 .Entry file


skymvc adopts single entry mode, but it is not the only entry. It is recommended to use two entries. One is the front entrance and the other is the back entrance.
1. Example of front-end entry file: index.php The file name can be customized to recommend index or
default

Copy code The code is as follows:

require
"data/config.php";//Load the configuration file
require("skymvc/skymvc.php");//Reference the framework file
//Determine whether the controller is legal
$_GET['m']=isset($_GET['m'])
&&
in_array($_GET['m'],array( 'index'))?$_GET['m']:'index';
//End of judgment
require_once(CTRL_DIR."/{$_GET['m']}.ctrl.php");
$classname
= $_GET['m'].'Control';
$control = new
$classname();
//Configure pseudo-static
$control ->tpl->rewrite=false;
$control->tpl->rewrite_rule=array(array("/index.php/i"),array("index.html"));
//Configure pseudo-static end
$method=isset($_GET['a'])
&& method_exists($control,'on'.$_GET['a'])?
' on'.$_GET['a']:"onDefault";
$control->$method();
?>

2. Backend entry file: admin The .php file name can be customized
Copy code The code is as follows:

require
"data/config.php";
require("skymvc/skymvc.php");
$_GET['m']=isset($_GET['m'])
&&
in_array($_GET['m'],array('index','article'))?$_GET['m']:'index';
require_once(ADMIN_DIR."/".CTRL_DIR."/{ $_GET['m']}.ctrl.php");
$classname
= $_GET['m'].'Control';
$control = new
$classname() ;
//Configure pseudo-static
$control->tpl->tplid="admin";
$control->tpl->currdir="admin";
$ control->tpl->rewrite_on=true;
$control->tpl->rewrite_rule=array(array("/index.php/","index.html"));
$ method=isset($_GET['a'])
&& method_exists($control,'on'.$_GET['a'])?
'on'.$_GET['a']:" onDefault";
$control->$method()
?>

Note: There is not much difference between the front and back entry files, mainly in the folders where the model and control files are located .
3. Controller file
Copy code The code is as follows:

class indexControl extends skymvc
{
function
__construct()
{
$this->indexControl();
}

function
indexControl()
{
parent::__construct();//Parent class initialization
$this->loadModel("index");
//Backend

//$this-> ;loadAdminModel("index");
}
function
onDefault()
{

$this->tpl->assign("welcome","Welcome skymvc, let's work together! ");
$this->tpl->assign("who",$_ENV['indexModel']->test());
//Backend
//$this->tpl->assign("who",$_ENV['admin_indexModel']->test());
$this->tpl->display("index ");
}
?>

4. Model file
Model files are mainly used to process data. Of course, they can also handle other logic, but they are not recommended. File naming convention: class.model.php
such as: index.model.php.
The model file is located under the model directory: such as model directory
Example: index.model.php
Copy code The code is as follows:

class
indexModel
{
public $base;
function
__construct(&$base)
{
$ this->indexModel($base);
}
function
indexModel(&$base)
{
$this->base=$base;
$this- >db=$base->db;
}
function
test()
{
echo "This is a model test";
}

}
?>

Model files: The front and backend are the same but the storage places are different
5.hello world
Hello word of kymvc framework!
If it is automatic If you create a directory.
The database is configured
index.php
The entry file is written.
index.php content
Copy code The code is as follows:

require
"data/config.php";//Load the configuration file
require("skymvc/skymvc.php");//Reference the framework file
//Determine whether the controller is legal
$_GET['m ']=isset($_GET['m'])
&&
in_array($_GET['m'],array('index','article'))?$_GET['m']: 'index';//Put all modules that appear at the index.php entry into array()
//End of judgment
require_once(CTRL_DIR."/{$_GET['m']}.ctrl .php");
$classname
= $_GET['m'].'Control';
$control = new
$classname();
$method=isset($ _GET['a']) &&
method_exists($control,'on'.$_GET['a'])?
'on'.$_GET['a']:"onDefault";
$control->$method();?>

Create the
hello.ctrl.php file in the ctrl directory
Copy Code The code is as follows:

class
helloControl extends skymvc
{

function __construct()
{
$this->helloControl();
}
function
helloControl()
{
parent::__construct() ;
$this->loadModel("hello");//Loading model
You can load any model but not a model of the same class
}
//The default action name Standard on function name
function
onDefault()
{
echo "hello world
"; $this->smarty->display("hello.html");
}
//When m=hello, a=test
Execute the following function
function
onTest(){
$this->tpl->assign("test" ,$_ENV['helloModel']->gettest());

$this->tpl->display("hello.html");

}
}?>

Create hello.model.php in the model directory

Copy the code The code is as follows:

class helloModel
{
public
$base;
function
__construct(&$base)
{
$this->helloModel($base);
}

function
helloModel(&$base)
{
$this->base=$base;
$this->db=$base->$db;
}
//No need to change the above
function gettest(){
return $this->db ->getRow("select * from test
limit 1");//Read data
}
}
?>

in the tpl directory Create new hello.html
Copy code The code is as follows:

PUBLIC "-//W3C //DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


content="text/html; charset=gb2312"
/ >
Untitled Document


This is the first example: Hello World!
This is Test example: {loop $test $t} {$t}
{/loop}



skymvc download address

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323756.htmlTechArticleThe modified framework is mainly used to achieve collaborative development between multiple programmers and the implementation of the mvc development model. skymvc adopts MVC development method, the framework itself is easy to expand. skymvc serves as the basic framework of the Skynet project...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn