Data Add function instance
Data add public
function NewData ($strName = "")
{if
(is_post) {
//If user submits data
$model = D ("$strName");
if (! $model->create ()) {
//If the creation fails indicating that the validation did not pass the output error message
$info = Array (
"info" => "{$model->geterror ()} ",
" status "=>" n ",
);
$this->ajaxreturn ($info, ' json ');
Exit ();
} else {
if ($model->add ()) {
$info = array (
"info" =>) Congratulations on the success of the operation! ","
status "=>" Y ",
);
$this->ajaxreturn ($info, ' json ');
} else {
$info = array (
"info" => operation failed!) ","
status "=>" n ",
);
$this->ajaxreturn ($info, ' json ');}}}
Data Update Function instance
Data Update public
function Update ($strName = "")
{if
(is_post) {
//If user submits data
$model = D ("$strName");
if (! $model->create ()) {
//If the creation fails indicating that validation did not pass the output error message
$info = Array (
"info" => "{$model->geterror () } ",
" status "=>" n ",
);
$this->ajaxreturn ($info, ' json ');
Exit ();
} else {
if ($model->save ()) {
$info = array (
"info" =>) Congratulations on the success of the operation! ","
status "=>" Y ",
);
$this->ajaxreturn ($info, ' json ');
} else {
$info = array (
"info" => operation failed!) ","
status "=>" n ",
);
$this->ajaxreturn ($info, ' json ');}}}
Data deletion function instance
Data Delete public
function Delete ($strNmae = ')
{
if (is_post)
{
$id = I (' post.id ');
if (!empty ($id))
{
//user submits data deletes the current ID
$model = D ("$strName");
$result = $model->delete ("$id");
if ($result!== false) {
$info = array (
"info =>" Operation succeeded!) ","
status "=>" Y ",
);
$this->ajaxreturn ($info, ' json ');
} else{
$info = Array (
"info" => operation failed!) ","
status "=>" n ",
);
$this->ajaxreturn ($info, ' json ');}}}
The above article thinkphp uses the model general data edits to add and deletes the example code is the small series to share to everybody's content, hoped can give everybody a reference, also hoped that everybody supports the cloud habitat community.