Phpskymvc is a lightweight and simple php

Source: Internet
Author: User
Skymvc is a lightweight and simple phpmvc framework. it draws on the design of various frameworks and uses many excellent functions and classes. skymvc does not encourage silly development, more focus on giving developers more space to think about. 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
Default
Copy codeThe 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 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:
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 file
Copy codeThe code is as follows:
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. php
Copy codeThe 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 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 content
Copy codeThe 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 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 file
Copy codeThe code is as follows:
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. php
Copy codeThe code is as follows:
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 Directory
Copy codeThe 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 a test example: {loop $ test $ t} {$ t}
{/Loop}



Skymvc

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.