Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
a tiny framework base on php
PHP Shell
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app
config
lib
sql
.htaccess
README.md
index.php

README.md

Sunphp

Sunphp is a tiny mvc framework base on php.

Requirement

You must understand MVC structure before you use the sunphp. And PHP >5.3

How to

Controller

1.Add a controller file in "app/controllers":

demoController.php

2.The most basic structure like in the "demoController.php":

class DemoController extends ApplicationController {

}

3.Add a action in the controller :

class DemoController extends ApplicationController {

    function sayhello{
        echo "helloworld";
    }

}

4.Call the url "yoursite/demo/sayhello", you can see "helloworld" in the screen.

Model

1.Add a model file in "app/models", like:

user.php

2.Code is following :

class User extends ActiveRecord {

}

3.Create table "users" in mysql:

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT, 
#####Yours field start ######

  `name` varchar(255) DEFAULT NULL,

  `birthday` varchar(255) DEFAULT NULL,

#####Yours field end ###### 
  `updated_at` datetime NOT NULL, 
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;

4.Ok,now you can use the model in the controller like:

class DemoController extends ApplicationController {

    function newuser(){
        //add a record
        $user = new User;
        $user->name="sunphp";
        $user->birthday="1985-12-29";
        $user->save();

        //delete record
        $user->delete();

        //find a record
        $user2 = User::find(3);

        //change
        $user2->name = "sunphp2";
        $user2->save();
    }

}

Veiw

1.Add a "sayhello.html.php" in "app/views/demos" , edit it like:

<b><?=$hello?></b>

2.Edit the controller:

class DemoController extends ApplicationController {

    function sayhello(){

        $this->hello = "say hello to the world";

        //respond to the view
        $this->respond_to();
    }

}

3.Call the url "http://yoursite/demo/sayhello", display as follows:

<b>say hello to the world</b>

Author

kirch

weibo: @kirch

License

Copyright 2012 kirch

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Enjoy it!

Something went wrong with that request. Please try again.