Php skymvc is a lightweight and simple php

Source: Internet
Author: User

The framework is mainly used to implement collaborative development among multiple programmers and implement the mvc development mode. skymvc adopts the mvc development mode, and the framework itself is easy to expand. As the basic framework of skymvc's Skynet program, adhering to the excellent tradition of easy to use, easy to learn, and joint development, we are committed to creating an excellent php
Mvc framework. You are welcome to give more suggestions.
1. Create the configuration file skyMVC to automatically create the website directory: Enter http: // locahost/skymvc/install. php to automatically create
File directory. If you want to create a new one, delete the install. lock file.
Automatic creation is recommended.
You can also manually create: directories can be customized.
Configure the program when creating a custom directory
Admin background directory
Admin/model
Admin/ctrl
Attach
Uploaded attachment directory
Ctrl control file directory
Data Directory
Data/config. php
Configuration File
Data/cache directory
Data/cache/css
Css Cache
Data/cache/file cache
Data/cache/tpl template cache
Data/cache/js
Js Cache
Model file directory
Tpl template directory
Tpl/admin background Template
Tpl/default
Default Template
Js directory
Plug-in Directory
Admin. php background portal File
Index. php front-end entry file
2. Entry File

Skymvc adopts a single portal mode, but it is not the only portal. Two portals are recommended. One is the frontend portal and the other is the background portal.
1. Front-end portal file instance: index. php file name can be customized to recommend index or
DefaultCopy codeThe Code is as follows: <? Php
Require
"Data/config. php"; // load the configuration file
Require ("skymvc/skymvc. php"); // reference the framework File
// Determine whether the controller is valid
$ _ GET ['M'] = isset ($ _ GET ['M'])
&&
In_array ($ _ GET ['M'], array ('index '))? $ _ GET ['M']: 'index ';
// Judge the end
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 ("/index. php/I"), array ("index.html "));
// Configure pseudo-static termination
$ Method = isset ($ _ GET ['a'])
& Method_exists ($ control, 'on'. $ _ GET ['a'])?
'On'. $ _ GET ['a']: "onDefault ";
$ Control-> $ method ();
?>

2. the admin. php file name can be customized.Copy codeThe Code is as follows: <? Php
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 ("/index. php/", "index.html "));
$ Method = isset ($ _ GET ['a'])
& Method_exists ($ control, 'on'. $ _ GET ['a'])?
'On'. $ _ GET ['a']: "onDefault ";
$ Control-> $ method ()
?>

Note: there is little difference between the front and back-end entry files, mainly in the folder where the model and control files are located.
3. Controller FileCopy codeThe Code is as follows: <? Php
Class indexControl extends skymvc
{
Function
_ Construct ()
{
$ This-> indexControl ();
}

Function
IndexControl ()
{
Parent: :__ construct (); // initialize the parent class
$ This-> loadModel ("index ");
// Background

// $ This-> loadAdminModel ("index ");
}
Function
OnDefault ()
{

$ This-> tpl-> assign ("welcome", "welcome to skymvc. Let's work together! ");
$ This-> tpl-> assign ("who", $ _ ENV ['indexmodel']-> test ());
// Background
// $ This-> tpl-> assign ("who", $ _ ENV ['admin _ indexmodel']-> test ());
$ This-> tpl-> display ("index ");
}
?>

4. Model files
Model files are mainly used to process data. Of course they can also process other logic, but are not recommended. File naming rules: class. model. php
For example, index. model. php.
The model file is located under the model directory, for example, the model directory.
Example: index. model. phpCopy codeThe Code is as follows: <? Php
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 back ends are stored differently.
5. hello world
Hello word of the kymvc framework!
If the directory is automatically created.
Configure the database
Index. php
Write the entry file.
Index. php contentCopy codeThe Code is as follows: <? Php
Require
"Data/config. php"; // load the configuration file
Require ("skymvc/skymvc. php"); // reference the framework File
// Determine whether the controller is valid
$ _ 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 ().
// Judge the end
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 in the ctrl directory
Hello. ctrl. php fileCopy codeThe Code is as follows: <? Php // hellControl class naming convention class name Control
Class
HelloControl extends skymvc
{

Function _ construct ()
{
$ This-> helloControl ();
}
Function
HelloControl ()
{
Parent: :__ construct ();
$ This-> loadModel ("hello"); // load the Model
Any model can be loaded but cannot be a model of the same class.
}
// Name of the action executed by default
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 ");

}
}?>

Under the model directory
Create hello. model. phpCopy codeThe Code is as follows: <? Php
Class helloModel
{
Public
$ Base;
Function
_ Construct (& $ base)
{
$ This-> helloModel ($ base );
}

Function
HelloModel (& $ base)
{
$ This-> base = $ base;
$ This-> db = $ base-> $ db;
}
// You do not need to modify the above
Function gettest (){
Return $ this-> db-> getRow ("select * from test
Limit 1 "); // read data
}
}
?>

Create hello.html In the tpl directoryCopy codeThe Code is as follows: <! DOCTYPE html
PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type"
Content = "text/html; charset = gb2312"
/>
<Title> untitled document </title>
</Head>
<Body>
This is the first example: Hello World!
This is a test example: {loop $ test $ t} {$ t}
{/Loop}
</Body>
</Html>

Skymvc

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.