ThinkPHP表单令牌错误的相关解决方法分析,thinkphp令牌
ThinkPHP表单令牌错误的相关解决方法分析,thinkphp令牌
本文分析了ThinkPHP表单令牌错误的相关解决方法。分享给大家供大家参考,具体如下:
今天在用ThinkPHP做程序的时候,以前用create创建数据的时候,出现了错误提示“表单令牌错误”,然后各种百度各种谷歌,得到的网上解答给出了以下的建议
1、清缓存: 用了,我把所有的Cache下的文件都删掉了,并将~app.php和~runtime.php两个文件同时都删掉了,但是没有效果。
2、将TOKEN_ON参数设置为FALSE: 试过了,但是也不行,虽然不提示表单令牌错误了,但是添加到数据库的数据是空的。
3、在模板文件的表单中添加{__NOTOKEN__}:添加了,但是结果同样是无效!
到这里我就开始无语了,难道就我电脑上的ThinkPHP不行?我觉得应该不是,我又重新写了一个添加函数,结果正常,这时候我就开始想,是不是我的上一个函数写错了?但是检查之后发现没错!后来慢慢的一个个文件开始那个查看啊,终于让我发现了原因:
在ThinkPHP自动生成的各个文件夹中,有一个叫做“Data”的文件夹,下面有个“_fields”文件夹,这个文件夹中存放的是各个模型中数据表中的相关信息,也就算是映射(我的理解),我仔细检查了一个,发现,有两个文件中只有“'_autoinc' => true,”这一项,其他的都有很多,类似于:
<?php return array ( 0 => 'id', 1 => 'title', 2 => 'content', 3 => 'publishedtime', 4 => 'userid', 5 => 'params', '_autoinc' => true, '_pk' => 'id', ); ?>
到这个时候就可以知道原因了,是某个操作将这些数据给删掉了一部分,这样ThinkPHP在进行表单验证的时候,无法进行数据的映射,也就导致了ThinkPHP的错误,将他们按照数据表中的顺序进行添加之后,重新运行,正常!
到此,这个问题解决~~~~
(本文所述thinkPHP环境为早期版本,用户在使用新版的时候可参考对应目录)
PS:这里推荐几款本站的格式化/美化/转换工具可以帮助你整理杂乱无章的代码,相信大家在以后的开发中能够用得上:
php代码在线格式化美化工具:
http://tools.jb51.net/code/phpformat
JavaScript代码美化/压缩/格式化/加密工具:
http://tools.jb51.net/code/jscompress
在线XML格式化/压缩工具:
http://tools.jb51.net/code/xmlformat
JSON代码格式化美化工具:
http://tools.jb51.net/code/json
在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson
json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.jb51.net/code/jsoncodeformat
sql代码在线格式化美化工具:
http://tools.jb51.net/code/sqlcodeformat
更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《PHP中cookie用法总结》、《smarty模板入门基础教程》及《PHP模板技术总结》。
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

How to use JavaScript to realize the automatic prompt function of the input box content of the form? Introduction: The automatic prompt function of the form input box content is very common in web applications. It can help users quickly enter the correct content. This article will introduce how to use JavaScript to achieve this function and provide specific code examples. Create the HTML structure First, we need to create an HTML structure that contains the input box and the auto-suggestion list. You can use the following code: <!DOCTYP

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

How to use JavaScript to implement real-time verification of the input box content of a form? In many web applications, forms are the most common way of interaction between users and the system. However, the content entered by the user often needs to be validated to ensure the accuracy and completeness of the data. In this article, we will learn how to use JavaScript to implement real-time verification of the content of the form's input box and provide specific code examples. Creating the form First we need to create a simple table in HTML

How to use HTML, CSS and jQuery to implement the advanced function of automatic saving of forms. Forms are one of the most common elements in modern web applications. When users enter form data, how to implement the automatic saving function can not only improve the user experience, but also ensure data security. This article will introduce how to use HTML, CSS and jQuery to implement the automatic saving function of the form, and attach specific code examples. 1. Structure of HTML form. Let’s first create a simple HTML form.
