This paper analyzes the issue of thinkphp Mall announcement function development. Share to everyone for your reference, as follows:
The effect is as follows
1. Set in the head
Position:fixed;z-index:999;top:0;opacity:1;
2.ajax Processing JSON data
Get Mall Announcement Function Getnotice () {//Get announcement functions var res; $.ajax ({ type: "POST", URL: "{sh::u (' Store/mall/ajaxgetnotice ', Array (' mid ' = + $mid)}", DataType: ' JSON ',//set to JSON, it is good to handle the obtained JSON data, Json.status async:false, success:function (JSON) { res = JSON; } }); return res;}
After setting datatype: ' JSON ', the JSON data can be processed directly via JSON.
3. Last loaded, the page looks better.
$ (document). Ready (function (e) {//main function //Get announcement var action_name = "{sh::action_name}";//page Use thinkphp constant var JSON = Getnotice (); if (Action_name = = ' Index ' && json.status = = 1) {//home page and Announcements exist $ (". Top"). CSS ("Margin-top", "70px");//jquery Set CSS $ (". Main-sidebar"). CSS ("Top", "70px"); var html = '; $.each (Json.info, function (i, n) {//n = text content HTML + = "
"+n.content+"" }); $ (". Top-notice"). Show (); $ (' #notice ul '). HTML ("" +html); $ (' #notice '). Unslider (); Carousel });
4. Get thinkphp processing of SQL statements
Get Announcement Function Ajaxgetnotice () { if (is_ajax) { $this->mid; Obtain a valid, and end time greater than the current time, or a date equal to 0 of the announcement $mallNoticeModel = M (' Mall_notice '); $where [' mall_id '] = $this->mid; $where [' status '] = 1; $where [' endtime '] = Array (array (' EQ ', 0), array (' GT ', Time ()), ' or '); SELECT * from Sh_mall_notice where mall_id = 9 and Status = 1 and (endtime = 0 or endtime>1458354366); $notice = $mallNoticeModel->where ($where)->order (' sort desc ')->select (); if (!empty ($notice)) { $this->ajaxreturn (' status ' = ' 1 ', ' info ' + $notice, ' msg ' = = ' get success '), ' JSON '); } else { $this->ajaxreturn (' status ' = ' 2 ', ' info ' = = $notice, ' msg ' = ' "announcement not Present"), ' JSON ');}}
$where [' endtime '] = Array (array (' EQ ', 0), array (' GT ', Time ()), ' or ');
This logical relationship is handled skillfully.
More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "CodeIgniter Getting Started Tutorial", "CI ( CodeIgniter) Framework Advanced Tutorial, Zend Framework Introduction tutorial, Smarty Template Primer Basic Tutorial and PHP template technology summary.
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.