我开始玩ajaxCRUD,这似乎是简单而有效的课程
我有一个像这样的用户表:
CREATE TABLE tbl_users (
usr_id INT NOT NULL AUTO_INCREMENT ,
usr_name VARCHAR( 64 ) NOT NULL DEFAULT '' ,
usr_surname VARCHAR( 64 ) NOT NULL DEFAULT '' ,
usr_pwd VARCHAR( 64 ) NOT NULL ,
usr_level INT( 1 ) NOT NULL DEFAULT 0,
PRIMARY KEY ( usr_id )
) ENGINE = InnoDB;
我的PHP代码是:
<?php
$tblUsers->omitPrimaryKey();
$tblUsers->displayAs("usr_name", "Nome");
$tblUsers->displayAs("usr_surname", "Cognome");
$tblUsers->displayAs("usr_pwd", "Password");
$tblUsers->displayAs("usr_level", "Livello");
$tblUsers->omitField("usr_pwd");
$tblUsers->modifyFieldWithClass("usr_pwd", "password");
$allowable_vals = array(1 => "USER", 2 => "ADMIN", 3 => "SUPERUSER");
$tblUsers->defineAllowableValues("usr_level", $allowable_vals);
$tblUsers->formatFieldWithFunction('usr_level', 'make_usr_level');
$tblUsers->onAddExecuteCallBackFunction("AddCallBack");
$tblUsers->addButtonToRow("Dettagli", "UserDetails.php");
$tblUsers->addButtonToRow("Collega case", "HousesList.php");
$tblUsers->setLimit(30);
#my self-defined functions used for formatFieldWithFunction
function make_usr_level($val){
return FAUser::LevelToString($val);
}
function AddCallBack($array)
{
//these indexes are the fields of the db
$success = qr("INSERT INTO tbl_users
( usr_id,
usr_name,
usr_surname,
usr_pwd,
usr_level )
VALUES (NULL,
'" . $array[usr_name] . "',
'" . $array[usr_surname] . "',
AES_ENCRYPT('" . $array[usr_pwd] . "',
SHA2('FonteAlma_2013', 512)),
" . $array[usr_level] . ");");
}
#actually show to the table
$tblUsers->showTable();
?>
表格显示正确并显示已插入的用户,但是当我添加新用户时,我得到:
4 - TheGivenName - TheGivenSurname - [BLOB - 7 B] - 0
因此密码和用户级别设置不正确。
另外,当我将水平字段编辑到表格中时,这是一个包含三个级别的组合框,无论我选择什么值,我总是得到0。
哪里错了?
问候。
答案 0 :(得分:0)
我编写了我的解决方案。
也许这不是最佳/正确的解决方案......但似乎有效。
我在执行ADD查询之前添加了一个方法onBeforeAddExecuteCallBackFunction()。 如果此回调返回FALSE,则执行结束(函数doAction返回)。否则继续。
这是差异文件:
263d262
< var $onBeforeAddExecuteCallBackFunction;
352d350
< $this->onBeforeAddExecuteCallBackFunction = '';
653,657d650
< function onBeforeAddExecuteCallBackFunction($function_name){
< $this->onBeforeAddExecuteCallBackFunction = $function_name;
< $this->ajax_add = false;
< }
<
900,906d892
< // Added
< if ($this->onBeforeAddExecuteCallBackFunction != '') {
< // If the Callback return FALSE, I quit
< if (!call_user_func($this->onBeforeAddExecuteCallBackFunction, $submitted_array))
< return;
< }
<