Home  >  Article  >  Backend Development  >  Self-study PHP environment setting_PHP tutorial

Self-study PHP environment setting_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:11:421060browse

Self-study PHP environment setting

1. First install phpStudy2013.exe

The program integration package may have the port occupied after installation and needs to be set manually

Default username root Password root

2. Build thinkphp framework

First go to http://www.thinkphp.cn to download the core package or the complete package

1. Create a project folder in the root directory, such as GuestBook_Think, copy ThinkPHP into it, and create the folder GuestBook to store this project, and then create a new PHP file index.php to define the entrance. The code is as follows:

[php]
// Define ThinkPHP path
define('THINK_PATH','./ThinkPHP/');
// Define project name
define('APP_NAME','GuestBook');
// Define project path
define('APP_PATH','./GuestBook');
// Load entry file
require(THINK_PATH.'/ThinkPHP.php');
// Instantiate this project
$App = new App();
//Perform initialization
$App->run();
?>

//Define ThinkPHP path
define('THINK_PATH','./ThinkPHP/');
//Define project name
define('APP_NAME','GuestBook');
//Define project path
define('APP_PATH','./GuestBook');
//Load entry file
require(THINK_PATH.'/ThinkPHP.php');
// Instantiate this project
$App = new App();
//Perform initialization
$App->run();
?>Note:

About the definition of constant THINK_PATH:
ThinkPHP 2.x
define('THINK_PATH', '../ThinkPHP');

ThinkPHP 3.x
define('THINK_PATH', '../ThinkPHP/');


If there are no other problems, it’s a smiley face. Welcome to ThinkPHP!


2. Create a config.Php file under the conf folder (it should already exist, just need to be modified), modify the configuration information as follows:

[php]
if (!defined('THINK_PATH')) exit();
return array(
'DB_TYPE'=>'mysql', // The database used is mysql
'DB_HOST'=>'localhost',
'DB_NAME'=>'myguestbook',//Database name
'DB_USER'=>'root',
'DB_PWD'=>'',//Fill in your password to connect to the database
'DB_PORT'=>'3306',
'DB_PREFIX'=>'think_', // Prefix of data table name
);
?>

if (!defined('THINK_PATH')) exit();
return array(
'DB_TYPE'=>'mysql', // The database used is mysql
'DB_HOST'=>'localhost',
'DB_NAME'=>'myguestbook',//Database name
'DB_USER'=>'root',
'DB_PWD'=>'',//Fill in your password to connect to the database
'DB_PORT'=>'3306',
'DB_PREFIX'=>'think_', // Prefix of data table name
?>
3. Create some new PHP files in the LibModel directory, corresponding to the database tables
File name specification: table name + Model.class.php (without think_ prefix)
For example: GuestBookInfoModel.class.php indicates that there is a table in the database called guestbookinfo
The code inside is like:
[php]
class GuestBookInfoModel extends Model { }
?>

class GuestBookInfoModel extends Model { }
?>

4. Next it’s time to write the template. Create the index.html file under TpldefaultIndex. The writing method of the template is similar to smarty. The code is as follows:


Define some tags in the static template and display them through php file assignment,
Basic tag definition specification: {$variable name}

5. Assign a value to the variable in the action, LibAction. For example, write the assignment code in the IndexAction.class.php file


[php]
class IndexAction extends Action{
public function index(){
$this->assign("title","Test title");
$this->assign('name',"haha");
$this->display();
}
}
?>

class IndexAction extends Action{
public function index(){
$this->assign("title","Test title");
$this->assign('name',"haha");
$this->display();
}
}
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477300.htmlTechArticleBuilding an environment for self-study PHP 1. First install phpStudy2013.exe. After the program integration package is installed, the port may be occupied and you need to manually Set the default username root and password root 2. Build thinkph...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn