Front-to-back thinkphp development Whole station (3)

Source: Internet
Author: User

Continue my third night of this project developed, less time, the code written tonight is not much, tonight is still making wheels write a public controller and a public JS. Go directly to the code!

The following is a public controller that inherits from the background controller, which verifies that the current user is logged in and provides fast access to the currently logged-on user's data.

<?phpnamespace admin\controller;use think\controller;/** * Background Management public controller */class Commoncontroller extends Controller{ Public Function __construct () {parent::__construct (); $this->_init ();} /** * Initialize */private function _init () {//If you have logged $islogin= $this->islogin (), if (! $isLogin) {//Jump to login page $this->redirect ('/admin.php?c=login ');}} /** * Get current login user information */public function Getloginuser () {return session (' AdminUser ');} /** * Determine if login */public function IsLogin () {$user = $this->getloginuser (); return ($user && Is_array ($user));} /** * Update data status */public function SetStatus ($data, $models) {try{if ($_post) {$id = $data [' id ']; $status = $data [' Status '];if (! $id) {return Jsonresult (0, ' id not present ');} $ret =d ($models)->updatestatusbyid ($id, $status), if ($ret) {return Jsonresult (1, ' Operation succeeded ');} Else{return jsonresult (0, ' operation failed ');}} Return Jsonresult (0, ' no content submitted ');} catch (Exception $ex) {return Jsonresult (0, $e->getmessage ());}} /** * Data sort */public function listorder ($model = ") {$listorder =$_post[' listorder ']; $jumpUrl =$_server[' http_REFERER ']; $errors =array (); $resultData =array (' jump_url ' = $JUMPURL); try{if ($listorder) {foreach ($listorder as $ Id=> $v) {$id =d ($model)->updatelistorderbyid ($id, $v), if ($id ===false) {$errors []= $id;}} if (Array_count_values ($errors) >0) {$group =implode (', ', $errors); return Jsonresult (0, "Sort failed-{$group}", $data, $ Resultdata);} Return Jsonresult (1, ' sort succeeded ', $resultData);}} catch (Exception $ex) {return Jsonresult (0, $ex->getmessage ());} Return Jsonresult (0, ' sort failed ', $resultData);}}? >

The following section of JS, mainly to do some form operation method.

var common = function (querydom) {if (!querydom) {console.error (' please pass in the DOM selection character that requires operation '); return;} function Commonobj () {this.dom = ';} function todelete (URL, data) {$.post (Url,data,function (s) {if (s.status = = 1) {return dialog.success (S.message, ');// Jump to the related page} else {return dialog.error (s.message);}}, "JSON");} /** * Submit Form form Action */commonobj.prototype.add = function (Formdom, func) {$ (this.dom). Click (function () {var data = $ (formdom) . Serializearray ();p ostdata = {};$ (data). Each (function (i) {postdata[this.name] = this.value;}); Console.log (postdata);//will get the data to post to the server URL = Scope.save_url;jump_url = Scope.jump_url;$.post (URL, postdata, function (Result) {if (result.status = = 1) {//Success if (typeof (func) = = ' function ') {func ();} else {return dialog.success (Result.message, Jump_ URL);}} else if (Result.status = = 0) {//Failed return Dialog.error (result.message);}}, "JSON");}); /** * Edit Module */commonobj.prototype.click = function () {$ (this.dom). On (' click ', function () {var id = $ (this). attr (' Attr-id ') ; var url = Scope.edit_uRL + ' &id= ' + id;window.location.href = URL;}); /* Delete operation */commonobj.prototype.delete = function () {$ (this.dom). On (' click ', function () {var id = $ (this). attr (' Attr-id ') var a = $ (this). attr ("Attr-a"), var message = $ (this). attr ("Attr-message"); var url = scope.set_status_url;data = {};d ata[ ' id '] = id;data[' status '] = -1;layer.open ({type:0,title: ' Is it submitted? ', btn: [' yes ', ' no '],icon:3,closebtn:2,content: ' OK ' + message,scrollbar:true,yes:function () {//execute related jump Todelete (url , data),},}); /** * Sort Operation */commonobj.prototype.order = function () {$ (this.dom). Click (function () {//Get listorder content var data = $ ("#singcms -listorder "). Serializearray ();p ostdata = {};$ (data). Each (function (i) {postdata[this.name] = this.value;}); Console.log (data), var url = scope.listorder_url;$.post (URL, postdata, function (result) {if (result.status = = 1) {// Successful return dialog.success (Result.message, result[' data ' [' Jump_url ']);} else if (Result.status = = 0) {//Failed return Dialog.error (result.message, result[' data '] [' Jump_uRL ']);}}, "JSON");}); /** * Change Status */commonobj.prototype.updatestatus = function () {$ (this.dom). On (' click ', function () {var id = $ [this]. attr (' at Tr-id '); var status = $ (this). attr ("Attr-status"); var url = scope.set_status_url;data = {};d ata[' id ') = id;data[' status '] = Status;layer.open ({type:0,title: ' Is it submitted? ', btn: [' yes ', ' no '],icon:3,closebtn:2,content: ' Determine Change Status ', Scrollbar:true,yes:function () {//execute related jump todelete (URL, (data),},}); CommonObj.prototype.push = function () {$ (this.dom). Click (function () {var id = $ ("#select-push"). Val (); if (id = = 0) { return Dialog.error ("Please select the recommended bit");} push = {};p ostdata = {};$ ("input[name= ' Pushcheck ']:checked"). each (function (i) {push[i] = $ (this). Val (); postdata[' push '] = push;postdata[' position_id '] = Id;//console.log (postdata); Return;var url = scope.push_url;$.post ( URL, postdata, function (result) {if (result.status = = 1) {//Todoreturn dialog.success (result.message, result[' data '] [' Jump_url ']);} if (Result.status = = 0) {//Todoreturn Dialog.error (Result.messa(GE);}}, "JSON");}); return new Commonobj ();}

Tonight to get so little, anyway slowly, no one urged me project progress, mainly I can insist on this project to finish. Code to write here is late, sleepy, did not go to run, there will be some bugs, and so a module after the development of debugging code it!

Source Address: Https://github.com/YoZiLin/TP-CMS

Front-to-back thinkphp development Whole station (3)

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.