Home > Backend Development > PHP Tutorial > php skymvc a simple php

php skymvc a simple php

高洛峰
Release: 2023-03-01 09:58:01
Original
1389 people have browsed it

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 a configuration file skyMVC supports automatically creating a website directory: enter http://locahost/skymvc/install.php to automatically create a
file directory. If you want to recreate it after creating it, delete the install.lock file and you can.
Recommend automatic creation.
You can also create it manually: the directories can be customized
When customizing the directory, you need to configure the program 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 back-end template
tpl/default
Default template
js directory
plugin plug-in directory
admin.php back-end entry file
index.php front-end entry file
2. Entry file


skymvc uses a single entrance mode, but it is not the only entrance. It is recommended to use two entrances. One is the front entrance and the other is the back entrance.
1. Front-end entry file example: index.php file name can be customized to recommend index or
default
Copy the 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"));
//End of configuration pseudo-static
$method=isset ($_GET['a'])
&& method_exists($control,'on'.$_GET['a'])?
'on'.$_GET['a']:"onDefault";
$control- >$method();
?>

2. Backend entry file: admin.php The file name can be customized
Copy the 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()
?>

Explanation: 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 to skymvc, let's work together!");
$this->tpl->assign("who",$_ENV['indexModel']->test());
//Backstage
//$this->tpl->assign("who ",$_ENV['admin_indexModel']->test());
$this->tpl->display("index");
}
?>

4. Model file
Main model file It is used to process data. Of course, it can also handle other logic, but it is not recommended. File naming convention: class.model.php
For example: index.model.php.
The model file is located under the model directory: such as model directory
Example: index.model.php
Copy the 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 file: The front and backend are the same but the storage place is different
5.hello world
Hello word of kymvc framework!
If the directory is automatically created.
Configure the database
index.php
Write the entry file.
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 in 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 the code The code is as follows:
class
helloControl extends skymvc
{

function __construct ()
{
$this->helloControl();
}
function
helloControl()
{
parent::__construct();
$this->loadModel("hello");//Load the model
You can load any model but not models of the same class
}
//Default action naming convention 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");

}
}?>

in the model directory Next
Create hello.model.php
Copy 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;
}
//Above There is no need to change
function gettest(){
return $this->db->getRow("select * from test
limit 1");//Read data
}
}
?>

Create a new hello.html in the tpl directory
Copy the 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!
Here is an example of a test: {loop $test $t} {$t}
{/loop}

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template