Book connection
This section analyzes the layout method of wojilu. Web. Controller. layouts sitelayoutcontroller.
Public override void layout (){
Load ("topnav", new topnavcontroller (). Index );
View the front-end view in framework \ views \ layouts \ sitelayout \ layout.htmlCodeTake a look
The following code snippet
<Body>
# {Topnav}
<Div id = "pagewrap">
<Div id = "pagewrapinner">
# {Header}
<Div id = "pagemainwrap">
Load ("topnav", new topnavcontroller (). Index );
YesWhat value does topnav assign to variables? Let's take a look at the definition of load.
Protected void load (string sectionname, Aaction action ){
Set (sectionname, loadhtml (Action ));
}
It can be seen that the content of framework \ views \ layouts \ topnav \ index.html is filled and replaced# {Topnav}
Similarly, load ("Header", new topnavcontroller (). header );
Is to fill in the content of framework \ views \ layouts \ topnav \ header.html, replace # {header}
Next, let's take a look at whether topnavcontroller (). Index and framework \ views \ layouts \ topnav \ index.html can be mined.
We can see that the last sentence of topnavcontroller (). index is set ("navurl", T2 (NAV ));
Assign values to the variable # {navurl} at the end of framework \ views \ layouts \ topnav \ index.html. See the following:
<SCRIPT type = "text/JavaScript"> var CTX = NULL;VaR navurl = '# {navurl }'; </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "~ JS/wojilu. Site. topnav. js? V =#{ jsversion} "> </SCRIPT>
For more information, see wojilu. web \ static \ JS \ wojilu. Site. topnav. js.
$ (Document). Ready (function (){
Navurl = (navurl + '? Url = '+ window. Location. href). toajax ();
......
$. Post (navurl, function (data ){
CTX = data;
......
}
Here, the Ajax POST method is used to request the nav action of the server topnavcontroller () again.
Public void NAV (){
// If todo is accessing the user space, judge whether it is a friend or followed.
Echojson (getloginjsonstring ());
}
The NAV () method returns a piece of JSON to the client. Dynamically set user statuses and permissions.
Load ("Header", new topnavcontroller (). header );
It mainly loads the menu and sub-menu of the site. I will discuss it in depth when I have time.
To sum up,The whole process involves two server accesses, one is page loading, and the other is JSON data of the JS request topnav.