Zend 框架中的 Ajax Post

微爱Linux

我对 Zend Framework 非常陌生。我想通过 $.post 在 jQuery 中删除未完成的 db 中的一行。我也在谷歌和 Youtube 上做了很多研究,但我没有得到结果,很遗憾。请帮我。采埃孚版本:1.11.2

应用程序/Bootstrap.php:

protected function _initDb(){
$con=array('host'=>'127.0.0.1','username'=>'root','password'=>'','dbname'=>'sample_db');
    $db=Zend_Db::factory('Pdo_Mysql',$con);$db->query("SET NAMES 'utf8'");
    Zend_Registry::set('db',$db);
}

应用程序/控制器/DashboardController.php:

public function indexAction(){
    $this->_helper->layout->setLayout('a');
}

应用程序/视图/脚本/仪表板/index.phtml:

<a href="javascript:deleteTest('62989c12369ea3c1')">DELETE</a>

公共/js/0.js:

function deleteTest(id){
    if(confirm('Are you sure?'))
        $.post('http://127.0.0.1/Sample4/application/models/Guestdb.php',{funcName:'Delete_Test',id:id},function(r){alert(r)})
}

应用程序/模型/Guestdb.php:

class Model_Guestdb{
    public function Delete_Test(){
    $db=Zend_Registry::get('db');
        $r=$db->query("DELETE FROM `prac` WHERE `id`='".trim((new Zend_Filter_Decrypt(array('adapter'=>'mcrypt','key'=>'thisisakeytolock','vector'=>'myvector')))->filter(hex2bin($this->getRequest()->getPost()['id'])))."'");
        echo$r?'t':'f';
    }
}
$a=new Model_Guestdb();
if(isset($_POST['funcName']))call_user_func(array($a,$_POST['funcName']));
elseif(isset($_GET['funcName']))call_user_func(array($a,$_GET['funcName']));

输出:

Fatal error: Uncaught Error: Class 'Zend_Registry' not found in C:\xampp\htdocs\Sample4\application\models\Guestdb.php:6 Stack trace: #0 C:\xampp\htdocs\Sample4\application\models\Guestdb.php(35): Model_Guestdb->Delete_Test() #1 {main} thrown in C:\xampp\htdocs\Sample4\application\models\Guestdb.php on line 6

对不起,我的英语
请帮助我
提前致谢

微爱Linux

我解决了这个问题如下:

应用程序/视图/脚本/仪表板/index.phtml:

<a href="javascript:del('210')">DELETE</a>

公共/js/0.js:

function del(id){
    if(confirm('Are you sure?'))
        $.post('ajax',{func:'del',table:'prac',id:id},
            function(r){r=='t'?location.reload():alert('Error!')})
}

应用程序/控制器/DashboardController.php:

<?php
class DashboardController extends Zend_Controller_Action{
    public function ajaxAction(){
        $this->_helper->layout->disableLayout();
        $ajax=$this->getRequest()->getPost();$func=$ajax['func'];
        (new Model_Guestdb)->$func($ajax['table'],$ajax['id']);
    }
}

应用程序/模型/Guestdb.php:

class Model_Guestdb{
    public function del($table,$id){
        echo Zend_Registry::get('db')->query
        ("DELETE FROM `$table` WHERE `id`='$id'")?'t':'f';
    }
}

感谢朋友的评论。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章