: This article describes how to obtain template functions. if you are interested in the PHP Tutorial, refer to it.
Public function actionChangetemplate () {$ status = true; $ interactive_id = (int) filter_input (INPUT_POST, 'id'); // post [id] $ template_id = (int) filter_input (INPUT_POST, 'mb'); // find the page $ interactives = Interactives: model ()-> findByPk ($ interactive_id); // Obtain the template $ interactiveTemplate = InteractiveTemplate :: model ()-> findByPk ($ template_id); // modify the template $ interactives-> template_id = $ template_id; $ interactives-> save (); // set different content based on the selected template $ template_info = $ interactiveTemplate-> template_content; $ interactiveContent = new InteractiveContent (); $ interactivePic = new InteractivePic (); // add the content. the following regular expression matches the content to generate the corresponding contentif (preg_match_all ('/preview_t _ [0-9] +/', $ template_info, $ arr) {// delete $ res = InteractiveContent: model ()-> deleteAll ("interactive_id =: ID", array (": ID "=> $ interactive_id); foreach ($ arr [0] as $ key => $ value) {$ content = new InteractiveContent (); $ content-> interactive_id = $ interactive_id; $ content-> color = "rgba (0,0, 0, 0.1)"; $ content-> content ='\ N \ tText input box <\/strong> <\/span> \ n <\/p> \ n
\ N \ t you can enter, copy, and paste the text. adjust the font size, color, alignment, and line spacing. you can also set the background color and transparency of the text box. <\/Span> \ n <\/p> '; $ content-> c_time = date ("y-m-d H: I: s "); $ ret = $ content-> save (); if ($ ret> 0) // if yes, the result is true $ status = $ status & true; else $ status = $ status & false ;}// add the image if (preg_match_all ('/preview_p _ [0-9] +/', $ template_info, $ arr )) {// delete $ res = InteractivePic: model ()-> deleteAll ("interactive_id =: ID", array (": ID "=> $ _ POST ['id']); for ($ I = 1; $ I <= count ($ arr [0]); $ I ++) {$ interactivePic = new InteractivePic (); $ interactivePic-> interactive_id =$ _ POST ['id']; $ interactivePic-> pic_scale = 2.2; $ interactivePic-> pic_src = "/images/editinteractive/pcover_000.jpg"; $ interactivePic-> pic_width = 30; $ interactivePic-> pic_height = 30; $ interactivePic-> pic_x = 0; $ interactivePic-> pic_y = 0; $ interactivePic-> tag = $ I; $ interactivePic-> c_time = date ("y-m-d H: I: s "); $ ret = $ interactivePic-> save (); if ($ ret> 0) // if it is correct, the result is true $ status = $ status & true; else $ status = $ status & false ;}} if (preg_match_all ('/preview_s1_prop p [0-9] +/', $ template_info, $ arr )) {// delete $ res = InteractivePic: model ()-> deleteAll ("interactive_id =: ID", array (": ID "=> $ _ POST ['id']); for ($ I = 1; $ I <= count ($ arr [0]); $ I ++) {$ interactivePic = new InteractivePic (); $ interactivePic-> interactive_id =$ _ POST ['id']; $ interactivePic-> pic_scale = 2.2; $ interactivePic-> pic_src = "/images/editinteractive/pcover_000.jpg"; $ interactivePic-> pic_width = 33; $ interactivePic-> pic_height = 44; $ interactivePic-> pic_x = 33; $ interactivePic-> pic_y = 44; $ interactivePic-> tag = 33; $ interactivePic-> c_time = date ("y-m-d H: I: s "); $ ret = $ interactivePic-> save (); if ($ ret> 0) // if it is correct, the result is true $ status = $ status & true; else $ status = $ status & false ;}} if (preg_match_all ('/preview_s1_0000t [0-9] +/', $ template_info, $ arr )) {// delete $ res = InteractiveContent: model ()-> deleteAll ("interactive_id =: ID", array (": ID "= >$ _ POST ['id']); foreach ($ arr [0] as $ key => $ value) {$ content = new InteractiveContent (); $ content-> interactive_id = $ _ POST ['id']; $ content-> color = "rgba (0.1, 0,)"; $ content-> content ='
\ N \ tText input box <\/strong> <\/span> \ n <\/p> \ n
\ N \ t you can enter, copy, and paste the text. adjust the font size, color, alignment, and line spacing. you can also set the background color and transparency of the text box. <\/Span> \ n <\/p> '; $ content-> c_time = date ("y-m-d H: I: s "); $ ret = $ content-> save (); if ($ ret> 0) // if yes, the result is true $ status = $ status & true; else $ status = $ status & false ;}} if (preg_match_all ('/preview_s1_1_t _ [0-9] +/', $ template_info, $ arr )) {// delete $ res = InteractiveContent: model ()-> deleteAll ("interactive_id =: ID", array (": ID "= >$ _ POST ['id']); foreach ($ arr [0] as $ key => $ value) {$ content = new InteractiveContent (); $ content-> interactive_id = $ _ POST ['id']; $ content-> color = "rgba (0.1, 0,)"; $ content-> content ='
\ N \ tText input box <\/strong> <\/span> \ n <\/p> \ n
\ N \ t you can enter, copy, and paste the text. adjust the font size, color, alignment, and line spacing. you can also set the background color and transparency of the text box. <\/Span> \ n <\/p> '; $ content-> c_time = date ("y-m-d H: I: s "); $ ret = $ content-> save (); if ($ ret> 0) // if yes, the result is true $ status = $ status & true; else $ status = $ status & false ;}} if ($ status) {echo json_encode (array (// success 'status' => 'success '));} else {echo json_encode (array ('status' => 'fail '));}}
The above describes how to obtain template functions, including some content, and hope to be helpful to friends who are interested in PHP tutorials.