ThinkPHP 5.0 Quick Start

First, the basics:

Create a project: conposer create-project topthink / think tp5 --prefer-dist
Create a project module: php think build --module demo
Access is not configured route: HTTP: // localhost / TP5 /
To turn off debug mode on the line: ' app_debug ' =>   to false , the config.php
// Create a text file needs to inherit the parent controller class 
use of Think \ the Controller; 

class Index the extends the Controller ( $ name = 'Joe Smith' ) { 
public function index ( $ name = 'Joe Smith' ) {
    
$ the this -> assgin ( 'name ' , $ name); // can html {$ name} is output seating
return $ the this -> FETCH ();
  }
}
//创建数据表 -- 记录没试过
CREATE TABLE IF NOT EXISTS `think_data`(
    `id` int(8) unsigned NOT NULL AUTO_INCREMENT,
    `data` varchar(255) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;INSERT INTO `think_data`(`id`,`data`) VALUES
(1,'thinkphp'),
(2,'php'),
(3,'framework');
//连接数据库
use think\Db;

class Index extends Controller{
    public function index(){
        $data = Db::name('data')->find();
        $this->assign('result', $data);
        return $this->fetch();
    }
}

Two, URL and routing:

Access format standard URL: http: //serverName/index.php/ module / controller / action 
// Note: the modular concept in ThinkPHP in fact, is the application directory subdirectories, and the official specification is the directory name in lowercase , Therefore, the module name in all lowercase , regardless of whether the URL open case conversion , module name will be forced to lower case .

 

Guess you like

Origin www.cnblogs.com/xinchenhui/p/11610214.html