search
HomePHP FrameworkThinkPHPWhat should I do if the new thinkphp controller cannot be used?

ThinkPHP is a PHP framework. It is an open source lightweight PHP development framework. It is released under the Apache2 open source agreement and is a powerful development tool. ThinkPHP has many excellent features, such as modular development, MVC support, template engine, data validation, etc. However, anyone who has used ThinkPHP knows that sometimes the newly created controller cannot be used, which is a headache. So, how do we solve this problem?

  1. First determine the location of the controller

In ThinkPHP, the controller class file is generally placed in the controller directory of the application. For example, the application name is home, then The controller directory is /home/Application/Home/Controller/. When you create a new controller, make sure the file name is the same as the class name, and the file suffix is ​​.php.

  1. Check whether the definition of the controller class is correct

In ThinkPHP, the definition of the controller class must inherit the base class Controller, for example:

<?php namespace Home\Controller;
use Think\Controller;

class IndexController extends Controller {
    public function index(){
        echo "Hello World!";
    }
}

It should be noted that the first line of the controller class should import the base class Controller. After defining the controller class, you can access the corresponding controller in the browser.

  1. Check whether the access path of the controller is correct

In ThinkPHP, the access path of the controller is "http://domain name/application name/controller name/ Method name", for example:

http://localhost/home/index/index

where home is the application name, index is the controller name, and index is the method name. If you have any problems when accessing, you can check whether the access path is correct.

  1. Check whether there are controllers with duplicate names

In ThinkPHP, controller names cannot be repeated, otherwise calling errors will occur. Therefore, when creating a new controller, you need to pay attention to whether it has the same name as the controller that comes with the system.

Summary

ThinkPHP is a very excellent PHP framework, but some problems will inevitably occur during use. When you create a new controller and it cannot be used, it may be due to problems with the location, definition, access path, or duplicate name of the controller. If this happens, you can troubleshoot according to the methods mentioned above, I believe it will be of great help to you.

The above is the detailed content of What should I do if the new thinkphp controller cannot be used?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool