Update 13.3.md
typographical errors and improved readability
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 13.3 Designing controllers
|
||||
|
||||
Most traditional MVC frameworks are based on suffix action mapping. Nowadays, the REST style web architecture is becoming increasingly popular. One can implement REST-style URLs by filtering or rewriting them, but why not just design a new REST-style MVC framework instead? This section is based on this idea, and focusses on designing and implementing a controller based, REST-style MVC framework from scratch. Our goal is to simplify the development of web applications, perhaps even allowing us to write a single line of code capable of serving "Hello, world".
|
||||
Most traditional MVC frameworks are based on suffix action mapping. Nowadays, the REST style web architecture is becoming increasingly popular. One can implement REST-style URLs by filtering or rewriting them, but why not just design a new REST-style MVC framework instead? This section is based on this idea, and focuses on designing and implementing a controller based, REST-style MVC framework from scratch. Our goal is to simplify the development of web applications, perhaps even allowing us to write a single line of code capable of serving "Hello, world".
|
||||
|
||||
## The controller's role
|
||||
|
||||
@@ -118,10 +118,10 @@ Then add the route handling function described earlier in this chapter. When a r
|
||||
Above, the controller base class already implements the functions defined in the interface. Through our routing rules, the request will be routed to the appropriate controller which will in turn execute the following methods:
|
||||
|
||||
Init() initialization routine
|
||||
Prepare() pre-initialization routine; each inheritting subclass may implement this function
|
||||
Prepare() pre-initialization routine; each inheriting subclass may implement this function
|
||||
method() depending on the request method, perform different functions: GET, POST, PUT, HEAD, etc. Subclasses should implement these functions; if not implemented, then the default is 403
|
||||
Render() optional method. Determine whether or not to execute according to the global variable "AutoRender"
|
||||
Finish() is executed after the action been completed. Each inheritting subclass may implement this function
|
||||
Finish() is executed after the action been completed. Each inheriting subclass may implement this function
|
||||
|
||||
## Application guide
|
||||
|
||||
@@ -143,7 +143,7 @@ Above, we've just finished discussing Beego's implementation of the base control
|
||||
this.TplNames = "index.tpl"
|
||||
}
|
||||
|
||||
In the code above, we've implemented a subclass of `Controller` called `MainController` which only implements the `Get()` method. If a user tries to access the resource using any of the other HTTP methods (POST, HEAD, etc), a 403 Forbidden will be returned. However, if a user submits a GET request to the resource and we have have the `AutoRender` variable set to `true`, the resource's controller will automatically call its `Render()` function, rendering the corresponding template and responding with the following:
|
||||
In the code above, we've implemented a subclass of `Controller` called `MainController` which only implements the `Get()` method. If a user tries to access the resource using any of the other HTTP methods (POST, HEAD, etc), a 403 Forbidden will be returned. However, if a user submits a GET request to the resource and we have the `AutoRender` variable set to `true`, the resource's controller will automatically call its `Render()` function, rendering the corresponding template and responding with the following:
|
||||
|
||||

|
||||
|
||||
|
||||
Reference in New Issue
Block a user