0

我正在尝试将“ajaxCRUD”类(http://ajaxcrud.com/)与 WordPress 集成。我希望实现的是有一个页面模板,它使用这个特定的类显示来自数据库的值。

ajaxCRUD 本身是可靠的,单独工作也很好。但是,我认为与 WordPress 中的某些内容存在一些冲突,因为一旦我将其放入页面模板中,我就失去了更新记录的能力。此时正在显示数据表,但在编辑/提交任何值时,正在加载 wordpress 主页/索引页面。奇怪的是,在加载索引页面而不是更新值时,URL 中有一个参数,其中包含我试图更新的列名和值!

EX:链接显示:localhost/dealerwp/?text_tblDemofldField11=myupdatetext 其中 fldField1 是我要更新的列,(pkID 为 1)& tblDemo 是表的名称 & myupdatetext 是我在尝试更新时输入的文本价值

这里会发生什么?

我迷路了,拔掉剩下的头发……会不会是与 WordPress 的 ajax 冲突?或者也许是.htaccess?我一生都无法弄清楚为什么曾经包装在一个 wordpress 页面模板中,以前工作的代码现在被破坏了,并将数据发布到它应该用来更新表格的 URL 参数。

如果有人想看一看,我正在使用的代码如下。

再次,提前感谢您的任何帮助/指向正确的方向。

<?php
/**
 * Template Name: DealerCRUD Template
 * Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts
 *
 * The showcase template in Twenty Eleven consists of a featured posts section using sticky posts,
 * another recent posts area (with the latest post shown in full and the rest as a list)
 * and a left sidebar holding aside posts.
 *
 * We are creating two queries to fetch the proper posts and a custom widget for the sidebar.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */
require_once('./preheader.php'); // <-- this include file MUST go first before any HTML/output

#the code for the class
include ('./ajaxCRUD.class.php'); // <-- this include file MUST go first before any HTML/output

#this one line of code is how you implement the class
########################################################
##

$tblDemo = new ajaxCRUD("Item", "tblDemo", "pkID", "/");

##
########################################################

## all that follows is setup configuration for your fields....
## full API reference material for all functions can be found here - http://ajaxcrud.com/api/
## note: many functions below are commented out (with //). note which ones are and which are not

#i can define a relationship to another table
#the 1st field is the fk in the table, the 2nd is the second table, the 3rd is the pk in the second table, the 4th is field i want to retrieve as the dropdown value
#http://ajaxcrud.com/api/index.php?id=defineRelationship
//$tblDemo->defineRelationship("fkID", "tblDemoRelationship", "pkID", "fldName", "fldSort DESC"); //use your own table - this table (tblDemoRelationship) not included in the installation script

#i don't want to visually show the primary key in the table
$tblDemo->omitPrimaryKey();

#the table fields have prefixes; i want to give the heading titles something more meaningful
$tblDemo->displayAs("fldField1", "Field1");
$tblDemo->displayAs("fldField2", "Field2");
$tblDemo->displayAs("fldCertainFields", "Certain Fields");
$tblDemo->displayAs("fldLongField", "Long Field");
$tblDemo->displayAs("fldCheckbox", "Is Selected?");

#set the textarea height of the longer field (for editing/adding)
#http://ajaxcrud.com/api/index.php?id=setTextareaHeight
$tblDemo->setTextareaHeight('fldLongField', 150);

#i could omit a field if I wanted
#http://ajaxcrud.com/api/index.php?id=omitField
//$tblDemo->omitField("fldField2");

#i could omit a field from being on the add form if I wanted
//$tblDemo->omitAddField("fldField2");

#i could disallow editing for certain, individual fields
//$tblDemo->disallowEdit('fldField2');

#i could set a field to accept file uploads (the filename is stored) if wanted
//$tblDemo->setFileUpload("fldField2", "uploads/");

#i can have a field automatically populate with a certain value (eg the current timestamp)
//$tblDemo->addValueOnInsert("fldField1", "NOW()");

#i can use a where field to better-filter my table
//$tblDemo->addWhereClause("WHERE (fldField1 = 'test'");

#i can order my table by whatever i want
//$tblDemo->addOrderBy("ORDER BY fldField1 ASC");

#i can set certain fields to only allow certain values
#http://ajaxcrud.com/api/index.php?id=defineAllowableValues
$allowableValues = array("Allowable Value 1", "Allowable Value2", "Dropdown Value", "CRUD");
$tblDemo->defineAllowableValues("fldCertainFields", $allowableValues);

//set field fldCheckbox to be a checkbox
$tblDemo->defineCheckbox("fldCheckbox");

#i can disallow deleting of rows from the table
#http://ajaxcrud.com/api/index.php?id=disallowDelete
//$tblDemo->disallowDelete();

#i can disallow adding rows to the table
#http://ajaxcrud.com/api/index.php?id=disallowAdd
//$tblDemo->disallowAdd();

#i can add a button that performs some action deleting of rows for the entire table
#http://ajaxcrud.com/api/index.php?id=addButtonToRow
//$tblDemo->addButtonToRow("Add", "add_item.php", "all");

#set the number of rows to display (per page)
$tblDemo->setLimit(3);

#set a filter box at the top of the table
//$tblDemo->addAjaxFilterBox('fldField1');

#if really desired, a filter box can be used for all fields
$tblDemo->addAjaxFilterBoxAllFields();

#i can set the size of the filter box
//$tblDemo->setAjaxFilterBoxSize('fldField1', 3);

#i can format the data in cells however I want with formatFieldWithFunction
#this is arguably one of the most important (visual) functions
$tblDemo->formatFieldWithFunction('fldField1', 'makeBlue');
$tblDemo->formatFieldWithFunction('fldField2', 'makeBold');

//$tblDemo->modifyFieldWithClass("fldField1", "zip required");  //for testing masked input functionality
//$tblDemo->modifyFieldWithClass("fldField2", "phone");         //for testing masked input functionality

//$tblDemo->onAddExecuteCallBackFunction("mycallbackfunction"); //uncomment this to try out an ADD ROW callback function

?>
            <div style="float: left">
            Total Returned Rows: <b><?=$tblDemo->insertRowsReturned();?></b>    <br />
    </div>

    <div style="clear:both;"></div>

<?

     #actually show the table
     $tblDemo->showTable();

    #my self-defined functions used for formatFieldWithFunction
    function makeBold($val){
    return "<b>$val</b>";
  }

    function makeBlue($val){
    return "<span style='color: blue;'>$val</span>";
  }

    function myCallBackFunction($array){
    echo "THE ADD ROW CALLBACK FUNCTION WAS implemented";
    print_r($array);
  }
?>
4

1 回答 1

0

您的脚本是否位于 ajaxCRUD 目录中?在 ajaxCRUD.class.php 中检查 $ajaxcrud_root 的设置(在第 307 行附近)一旦你设置了它,你就可以摆脱, "/"

$tblDemo = new ajaxCRUD("Item", "tblDemo", "pkID", "/");
于 2013-05-16T23:46:54.957 回答