http://127.0.0.1/user/add 报错页面如下图
控制器文件 application\index\controller\UserController.php
<?php
namespace app\index\controller;
use app\index\model\User;
class UserController
{
// 新增用户数据
public function add()
{
$user = new User();
$user->nickname = '流年';
$user->email = 'thinkphp@qq.com';
$user->birthday = strtotime('1977-03-05');
if ($user->save()) {
return '用户[ ' . $user->nickname . ':' . $user->id . ' ]新增成功';
} else {
return $user->getError();
}
}
}
?>
模型文件:application\index\model\User.php
<?
namespace app\index\model;
use think\Model;
class User extends Model
{
protected $name = 'user';
protected $connection = [
'type' => 'mysql',
'hostname' => '127.0.0.1',
'databa
'username' => 'root',
'password' => 'root',
'hostport' => '3306',
'params' => [],
'charset' => 'utf8',
'prefix' => 'think_',
'debug' => true,
];
}
?>
最佳答案