最短(est)版本:我创建了一个简单的CMS,允许用户从4个模板中进行选择。每个模板都有不同的面板类型。对于此示例,我显示了一个只有一个整页面板的整页模板。
基本上,面板提供了TinyMCE的实例,以允许用户为面板创建文本/图像内容。
流为: 内容->(已分配)->面板->(已分配)->页面->(已分配)->显示
因此,在这种情况下,用户选择一个链接,该链接通过URL传递值,在这种情况下,该值为1。这将告诉templates.php包含fullWidth.php
因此,templates.php具有一个带有提交按钮的保存表单,而加载的fullWidth.php文件具有面板模板,该模板为我们提供了面板类型的编号以及文本区域中的内容。
我的问题是,我需要完全实现一个保存页面的功能(通过代理,它还可以保存内容和面板的记录)
因此,使用下面的代码,我基本上将插入3个不同的表中,但是panels
表正在插入外键;新创建的pages
条目的ID以及新插入的content
条目的ID。
我知道其中大部分只是在数据库中插入一些表单值,但这里有两个主要障碍:
对于此示例,我要发布的代码(假设用户正在选择下面使用的硬编码<options>
),我将插入:
saveContentPage.php
//This is complete pseudo code, I'm not sure how the syntax would change for the different types
$title= $_POST['$title'];
$pageType= $_POST['$value'];
$displayId = $_POST['#areaSelect'];
$start_time = now();
$end_time = $_POST['#datePicker'];
$slide_order = $_POST['#orderSet'];
$duration = $_POST['#durationSet'];
$sql="INSERT INTO pages(title, page_type_id, display_id, start_time, end_time, slide_order, duration)
VALUES ('$title','$pageType','$displayId','$start_time','$end_time','$slide_order','$duration')";
//Here I need to pass the content from the included fullwidth.php to get the textarea content and the panel_type_id
$content = $_POST['textArea']
$sql = "INSERT INTO content(content)
Values('$content')";
if(#id = FullPage){
$panel_type = 1;
}
$sql = INSERT INTO panels (panel_type_id, page_id, cont_id)
VALUES ('$panel_type', /*ID that was created from 'pages' insert*/, /*ID that was created from 'content' INSERT*/)
如何创建执行必要插入操作的函数?
代码:
templates.php
<!-- check GET 'value' -->
<?php $value = isset($_GET['value']) ? $_GET['value'] : 1;?>
<!-- If value is 1 then load the full page template class -->
<?php if($value == 1){?>
<?php include 'class/fullWidth.php'?>
<!-- Submit button that links to modal with a 'save page' form inside -->
<div class="modal fade" id="savePageModal" tabindex="-1" role="dialog" aria-labelledby="savePageLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="savePageLabel">Page Details:</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<!-- this is the URL value i.e. templates.php?value=1 and should insert into pages.page_type_id -->
<label>Page Type: <?php echo $value;?></label>
</br>
<!-- This is page title, should map to pages.title -->
<label for="addTitle">Page Title:</label>
<input class="form-control" id="addTitle">
</input>
<!-- This shows the displays, will save the ID of the selected option to pages.display_id -->
<label for="areaSelect">Select An Area</label>
<select class="form-control" id="areaSelect">
<option>4</option>
</select>
<!-- Input for seconds, will save to pages.duration -->
<label for="durationSet">Set A Duration (in seconds)</label>
<input class="form-control" id="durationSet">
</input>
<!-- User selects order of slide -->
<label for="orderSet">Set Slide Order</label>
<select class="form-control" id="orderSet">
<option>3</option>
</select>
<!-- This datepicker allows user to pick a date and time, will save as TIMESTAMP to pages.end_time -->
<label for="expirationSelect">Set Expiration Date/Time</label>
<div class="form-group">
<div class="datepick input-group date" id="datetimepicker" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker"/>
<span class="input-group-addon" data-target="#datetimepicker" data-toggle="datetimepicker">
<span class="fa fa-calendar"></span>
</span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
fullwidth.php
<!-- This file is loaded based on page type ($value) from templates.php
It loads an HTML template which has a main div houseing the panel_type and it has
a textarea that houses the content -->
<div class="row middle">
<div class="col-lg-12 fullWidth">
<!-- This Div ID is 1 which maps to the panel_type of this div, so upon saving It should insert to panels.panel_type_id a value of 1 -->
<div class="fullContent" id="fullPage" style="background-color: white; height: 100%;">
<!-- THis is simply a modal that givees the user an interface to use TinyMCE in order to fill the content of mytextarea3 -->
<div class="modal fade bd-example-modal-lg" id="fullModal" tabindex="-1" role="dialog" aria-labelledby="fullLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="fullModal">Content Library:</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h3>Create your own content</h3>
<form id="form-data3" method="post">
<!-- This is the text area that should be saved to content.content -->
<textarea id="mytextarea3"></textarea>
<input type="submit" value="Get Data">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>