Webutility 0.1.28 MVC Framework User Guide

Source: Internet
Author: User

The MVC framework can be divided into M, V, and C. M stands for the object class (model), which is used to transmit data. V is the view layer ), in this framework, an HTML page is used for implementation. c is the control class (Controller). It is the combination of background data and foreground performance.

View Director data presentation logic, all the display-related things should be implemented here (why is it true, because some logics cannot be implemented using the syntax currently supported by the template, so we have to implement it in C ). Currently, view supports the IF, foreach, and write statements. Write statements support two forms. One is write ("something ") one is the <% = "something" %> of the output content in HTML directly. The if statement is similar to that in C #, but currently it does not support if () elseif () the form of else only supports the form of IF () else (). The foreach statement is also similar to the foreach statement in C #, but does not support strong types, it should be written as foreach (VAR table in tables ). the following is an example:

Use of IF Statements:

(Example 1)

: $ A is the variable set in control class C. It is recommended that all variable names set in the background start with $, when reading the template, we can easily find out which variables are set in the control class.

Use of foreach statements:

(Example 2)

Note: Currently, $ tables can only be an array or an object that implements the ilist or icollection interface.

From the above two statements, we can see the two application forms of the Write statement. Note that currently, the Write statement only supports the output of a single simple object and does not support operation expressions, if this restriction has a great impact on our use, we will modify it later.

The Controller is mainly used for data filling and data receiving. It is recommended to write the specific business logic to the BLL layer. All page control classes must inherit pagecontroller, But I have added two page control base classes basepagecontroller and restrictedpagecontroller to the project. They all inherit from pagecontroller, therefore, in actual development, we can inherit these two classes as needed, or create our own basic control classes as needed. All page control classes should have a public void run () method. The run () method is the default method, that is to say, this method will be executed if no method name is specified when you access this page. The page control class has a strict restriction, that is, neither it nor its base class can have a public function with the same name, that is, overload is not supported.

The page control class supports three methods: setting methods starting with setup, uninstalling Methods Starting with teardown, and Ajax Methods Starting with Ajax, the other is a common method that does not use the above three symbols as the prefix. The setting method is executed before the normal method, and the uninstallation method is executed after the normal method. If you request the Ajax method, the setting and uninstallation methods are not executed.

The control class method supports single-type parameters and arrays as well as objects that implement the ilist and idictionary interfaces. Strings transmitted from the foreground must comply with the JSON format, it is automatically deserialized to the corresponding parameter.

An example of a complete background control class:

(Example 3)

Note: viewdata ["$ A"] represents the variable $ A in the foreground template. See example 1; viewdata ["$ tables"] indicates the variable $ tables in the foreground template. We set the data source for it in the control class.

Example 3 output results after parameter execution are not provided:

Note: because a is the run parameter, we didn't provide the parameter when requesting this page, so its default value is 0. Therefore, if it is greater than 10, it is false, therefore, this result is output.

The execution result after parameter A = 20 is provided:

The correspondence between the Request Path and C and V:

Example: if there is a directory such as helpers/codehelper. aspx, the corresponding control class is the codehelper class under the CVV. webapp. helpers namespace, and the corresponding template is helpers/codehelper.html.

Let's talk about it first. If you don't understand it, you can ask me directly. Thank you for your cooperation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.