url:美化看这篇文章
https://blog.csdn.net/qq_37805832/article/details/122087080
sql:
-- phpMyAdmin SQL Dump -- version 4.5.1 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: 2022-03-02 04:08:09 -- 服务器版本: 10.1.13-MariaDB -- PHP Version: 5.6.21 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; ; ; ; ; -- -- Database: `qq` -- -- -------------------------------------------------------- -- -- 表的结构 `news` -- CREATE TABLE `news` ( `id` int(10) UNSIGNED NOT NULL, `title` varchar(50) NOT NULL, `thumb` varchar(250) DEFAULT NULL, `content` text, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATe CURRENT_TIMESTAMP, `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- 转存表中的数据 `news` -- INSERT INTO `news` (`id`, `title`, `thumb`, `content`, `created_at`, `updated_at`) VALUES (1, '1111', NULL, '1111', '0000-00-00 00:00:00', '0000-00-00 00:00:00'), (2, '2222', NULL, '1111', '0000-00-00 00:00:00', '0000-00-00 00:00:00'), (3, '1111', 'upload/火狐截图_2017-08-21T03-07-27.499Z.png', '1111', '0000-00-00 00:00:00', '0000-00-00 00:00:00'), (4, 'Hello World', NULL, NULL, '2017-08-21 10:25:17', '0000-00-00 00:00:00'), (5, 'ppp', NULL, NULL, '2022-03-02 03:07:33', '0000-00-00 00:00:00'); -- -- Indexes for dumped tables -- -- -- Indexes for table `news` -- ALTER TABLE `news` ADD PRIMARY KEY (`id`); -- -- 在导出的表使用AUTO_INCREMENT -- -- -- 使用表AUTO_INCREMENT `news` -- ALTER TABLE `news` MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6; ; ; ;
'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookievalidationKey' => '69PsZ-icrXqKv5ww8q_yDKP4vN1VdBhi',
'parsers' => [
'application/json' => 'yiiwebJsonParser',
]
],
'cache' => [
'class' => 'yiicachingFileCache',
],
'user' => [
'identityClass' => 'appmodelsUser',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yiiswiftmailerMailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yiilogFileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'urlManager' => [
'enablePrettyUrl' => true,
'showscriptName' => false,
'rules' => [
[
'class' => 'yiirestUrlRule',
'controller' => 'v1/news'
]
],
]
],
'params' => $params,
'modules' => [
'v1' => [
'class' => 'appmodulesv1Module',
],
],
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yiidebugModule',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yiigiiModule',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
return $config;
注意一下这里:
'request' => [
'parsers' => [
'application/json' => 'yiiwebJsonParser',
]
]
和这里:
'urlManager' => [
'enablePrettyUrl' => true,
'showscriptName' => false,
'rules' => [
[
'class' => 'yiirestUrlRule',
'controller' => 'v1/news'
]
],
]
然后是:
'modules' => [
'v1' => [
'class' => 'appmodulesv1Module',
],
],
放在这里:
然后是:
生成数据库中news表的gii:model放进appmodels里面
然后是:生成控制器:
然后是修改控制器:appmodulesv1controllersNewsController.php
创建:
查看:删除
更新:



