Next, we introduce the thinkphp framework to develop the mobile End Interface (1), in addition, we can also achieve the mobile end of the thinkphp access to the theme template, so you can also do mobile end access
thinkphp template theme mechanism, if only in the PC, as long as the need to modify Default_theme (the new template theme is empty, indicating that the template theme is not enabled) configuration items can facilitate the implementation of multiple template theme switching.
But for the mobile end and PC side, maybe you will design a completely different theme style, and for different antecedents to provide different rendering methods, one of the more popular method is "responsive design", but in my experience, to achieve full "responsive design" is not so easy, and solve the compatibility problem is also a problem, The assumption is that large sites, such as: Taobao, Baidu, Pat these, responsive design must not meet the needs, but the need for mobile phone access users to provide a separate mobile web site.
Thinkphp is completely achievable and fairly simple. And the TPM Intelligent template switching engine, as long as the antecedents of the judge processing can be.
1. Add IsMobile () to {Project/common/common.php}
function IsMobile () {//If http_x_wap_profile must be a mobile device if (Isset ($_server[' http_x_wap_profile ')) return true;
This article is excerpted from the TPM Intelligent Switch template engine, suitable for TPM development if (Isset ($_server[' http_client ')) && ' phoneclient ' ==$_server[' http_client ']
return true; If the VIA information contains WAP, it must be a mobile device, some of the service Chambers block the information if (Isset ($_server[' Http_via '))/not found to be flase, otherwise return stristr ($_server[' Http_via '], ' WAP '?
True:false; To determine the client flag sent by mobile phone, compatibility needs to be improved if (Isset ($_server[' http_user_agent ')) {$clientkeywords = array (' Nokia ', ' Sony ', ' Ericsson '), ' Mot ', ' Samsung ', ' HTC ', ' SGH ', ' lg ', ' sharp ', ' sie-', ' Philips ', ' Panasonic ', ' Alcatel ', ' Lenovo ', ' iphone ', ' ipod ', ' BlackBerry ', ' Meizu ', ' Android ', ' NetFront ', ' Symbian ', ' UCWeb ', ' windowsce ', ' palm ', ' operamini ', ' Operamobi ', '
Openwave ', ' nexusone ', ' cldc ', ' MIDP ', ' wap ', ' mobile '; Find the keyword if (preg_match) ("/") for the mobile browser from Http_user_agent. Implode (' | ', $clientkeywords).
")/I", Strtolower ($_server[' http_user_agent '))) {return true; }//protocol method, because it may be inaccurate, put to the final Judgment if (Isset ($_server[' http_accept ')) {//If only WML is supported and HTML is not supported it must be a mobile device//If WML and HTML are supported but WML is a mobile device before HTML (strpos ($_server[' http_accept '), ' VND.WAP.WML ' !== false) && (Strpos ($_server[' http_accept '), ' text/html ') = = False | | (Strpos ($_server[' http_accept '], ' vnd.wap.wml ') < Strpos ($_server[' http_accept '], ' text/html ')))
{return true;
return false;
}
2, in {Project/lib/} to create a commonaction.php, if your project has a public controller, you do not need to create, directly added to the inside.
Class Commonaction extends action{public
function _initialize () {
//mobile device browsing, toggle template
if (IsMobile ()) {
// Set the default default theme for mobile
C (' Default_theme ', ' mobile ')
;
//............ More code for you ...
}
Through the above 2 ways to achieve mobile end access, one is the original, one is pseudo native, small partners according to their own project needs to choose.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.