Use laravel controller

Using the controller
1. First understand what is MVC architecture
M: Model
V: View
C: Controller
object: the user input and output separately (facilitate programming), the controller for receiving a user request to schedule model (M) for data interaction table, it is possible to return data, and return the data exchange views for display (controller to pass data to the view, then the data by the view), the controller has a leading role
so that the action controller : responsible for receiving user input request, scheduling model for data processing using the final view shows data
2. where the controller to write?
Controller.php is the base class controller framework of
Here Insert Picture Description
questions: if the controller can manage sub-directory?
Yes,
when you need to manage sub-directory?
Only the foreground or background is not required, if there are multiple platforms need to be sub-directory management (that is, depending on the project itself), sub-directory management is actually management sub-module
named file:
large hump Controller.php +
3. Structure Code how to write?
NOTE: it does not require manual controller to write the underlying code, automatically generated by the artisan command
to first review the command learned earlier:
PHP artisan route: List (list query routing)
PHP artisan serve (laravel start frame)
corresponding to the command :
PHP the make Artisan: the controller name of the controller (large hump) the controller
(Note: Do not write php, and want to start (shift + right-click in the current folder))
Here Insert Picture Description
The above is displayed successfully created a style
and created the controller in our controllers folder, as shown below
Here Insert Picture Description
and will create some basic things (namespace, request, class inheritance), as shown below
Here Insert Picture Description
if you want to create your own directory again to create, in the same manner just created in the command window, as shown
Here Insert Picture Description
displayed in the controller
Here Insert Picture Description
Here Insert Picture Description
3. the controller routes (in this embodiment project-based)
access routes used earlier routing manner is accessed, suitable for single file access, but is not suitable for the project, to be accessed by the controller routing
how to use the method of routing rules under controllers call, rather than walk the callback function. As shown in FIG.
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
4. receiving user input
class for receiving user input: Illuminate \ Support \ Facades \ Input (Input Facade)

Here Insert Picture Description

Released nine original articles · won praise 0 · Views 309

Guess you like

Origin blog.csdn.net/Ya_Tou945/article/details/105045843