First, the construction of PHP environment
Before writing PHP, first build PHP environment, I chose one-stop installation software wampserver,wampserver: http://www.wampserver.com/
The latest version of Wampserver 2.5 is built in:
Apache 2.4.9
PHP 5.5.12
MySQL 5.6.17
Installation is also very simple, all the way next, done! After the installation is successful, accessing http://localhost/will display the following:
Second, PHP development Framework Selection
PHP has a lot of third-party development frameworks, and I've chosen a simple and easy-to-use framework by contrast Thinkphp,thinkphp's official website is: http://www.thinkphp.cn/
The latest version of thinkphp is 5.0, but I've chosen a wide range of 3.2.3, the official offer two versions of the download, one is the core version, the other is the full version. See what others mean is a master with the core version, ordinary developers with the full version, as a side dish, I choose the full version.
My wamp is installed in the D:\Program Files\wamp directory, where I extract the thinkphp directory to D:\Program files\wamp\www\thinkphp directory, Access http://localhost/ thinkphp, if the following appears, indicates that the thinkphp installation was successful:
Third, write Hello World with thinkphp
After accessing the first page of thinkphp, thinkphp automatically creates a home folder in the Thinkphp/application directory and creates a series of files under the home folder.
We just visited the homepage, actually is in visit thinkphp/application/home/controller/indexcontroller.class.php
Let's write our own code.
Create the Demo1Controller.class.php file under the thinkphp/application/home/controller/directory, as follows:
<? phpnamespace Home\controller; Use Think\controller; class extends Controller { publicfunction index () { echo ' Hello World ' ; }}
The corresponding access address is: Http://localhost/thinkphp/index.php/Home/Demo1/index
The exciting moment came, and that was my first PHP code: Hello World appeared
The rules for accessing addresses are HTTP///project/Portal File/Module name/method name/Key 1/value 1/Key 2/value 2
index.php for import files
Home/demo1 for Module name
Index is the method name
That seems to correspond to this? Think of it this way for the moment.
Anyway, at least you can celebrate, write your own Hello World in PHP.
Iv. presenting Hello World in an MVC fashion
Modify the above code slightly, put the background code in the controller, the view display is placed in the view
The Demo1Controller.class.php code is modified as follows:
<? phpnamespace Home\controller; use Think\controller; class Demo1controller extends Controller { Span style= "color: #0000ff;" >public function index () {
echo ' Hello World '
;
public
function
Test1 () {
$this ->assign (' name ',
"H Ello World '
);
$this ->
display (); }}
Then create the Demo1 folder under the thinkphp/application/home/view/directory and create the file test1.html file under the Demo1 folder as follows:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Demo1</title></Head><Body>{$name}!</Body></HTML>
The corresponding access address is: Http://localhost/thinkphp/index.php/Home/Demo1/test1
In this way, the code for displaying Hello World in MVC is done.
Write my first piece of code in PHP: Hello World