Home > Article > Backend Development > Find the solution to synchronize the front-end URL with the back-end in the MVC framework, mvcurl_PHP tutorial
Basic idea:
First use URL tags to generate complete URL characters, the front-end dynamic parameters are filled in with adapters first, and finally the dynamic parameters are replaced using regular matching.
This method can be applied in various MVC frameworks, which is wonderful.
No nonsense, just code.
<span>var</span> url = "{url app=xxxxn&act=yyy&id=[0]}"<span>; url </span>= url.format({$id});
<span>//</span><span>String.format 同时匹配[](){}内容方式</span> <span>if</span> (!<span>String.prototype.format) { String.prototype.format </span>= <span>function</span><span> () { </span><span>var</span> args =<span> arguments; </span><span>var</span> tag = ''<span>; </span><span>return</span> <span>this</span>.replace(/(\{|\(|\[)(\d+)(\}|\)|\])/g, <span>function</span><span> (match, m0,m1,m2) { tag </span>= m0+<span>m2; </span><span>if</span>(tag=='()' || tag == '{}' || tag == '[]') <span>return</span> <span>typeof</span> args[m1] != 'undefined'? args[m1]: (m0+m1+<span>m2); }); }; }</span>
The method of the String object has been changed using the prototype method above, which can be rewritten appropriately and turned into a general function parameter transfer.
Put the login information in the Session, and then judge, if (session==null) {jump to the login page}.
Basically, ajax is used to submit to the background or obtain data from the background.