سؤال

I want to insert multiple rows into database in zend 1, but I have an error:

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in D:\HR_New\30_SourceManagement\HRSystem\library\Zend\Controller\Dispatcher\Standard.php:248Stack trace:#0 D:\HR_New\30_SourceManagement\HRSystem\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))#1 D:\HR_New\30_SourceManagement\HRSystem\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()#2 D:\HR_New\30_SourceManagement\HRSystem\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()#3 D:\HR_New\30_SourceManagement\HRSystem\index.php(11): Zend_Application->run()#4 {main} thrown in D:\HR_New\30_SourceManagement\HRSystem\library\Zend\Controller\Dispatcher\Standard.php on line 248

And this my code : in *.phtml, I have an ajax function:

$('#btnSubmit').bind({
        "click": function(){
            $.ajax({
                type: 'GET',
                dataType: 'JSON',
                url: 'change-authorize-data',
                data: {
                        arrCode: arrCode,
                },
                success: function(data){
                    alert("authorize success !");
                },
                error: function(xhr, ajaxOptions, thrownError){
                    alert("authorize fail!");
                    console.log("xhr.status: "+xhr.status);
                    console.log("thrownError: "+thrownError);
                }
            });
        }   
    }); 

with arrCode is an object has data as :

arrCode[0][role_id]:4
arrCode[0][screen_id]:9SE902
arrCode[0][access_status]:1
arrCode[1][role_id]:5
arrCode[1][screen_id]:9SE902
arrCode[1][access_status]:1

And my controller have a function as:

public function changeAuthorizeDataAction(){
    $authorizeModel = new Default_Model_AuthorizeModel();
    if($this->_request->isGet()){
        $arrCode = $this->_request->getParam ( 'arrCode' );
        try {
            $authorize = $authorizeModel->addAuthorize($arrCode);
        } catch (Exception $e) {
            $authorize = $authorizeModel->updateAuthorize($arrCode);
        }

        $this->_response->setBody ( json_encode ( $authorize ) );
    }
}

And this my Model have a function as:

public function addAuthorize($insertArr){
     $strInsert = " insert into `tbl_authorization` (`role_id`,`screen_id`,`access_status`) values _value";
    $valueInsert = "";
    $count = count($insertArr);
    if($count > 0) {
        for($i = 0 ; $i<$count ; $i++) {
            $valueInsert .= "("
                    .$insertArr[$i]['role_id'] .",'"
                            .$insertArr[$i]['screen_id']. "',"
                                    .$insertArr[$i]['access_status'] .")";

            if($i < $count - 1) {
                $valueInsert .= ",";
            }
        }

        $newStr = str_replace("_value",$valueInsert,$strInsert);

        try {
            //die($newStr);
            $this->db->query($newStr);
        } catch (Exception $e) {

        }
    }
}

When I use die($newStr), I get an SQL. but $this->db->query($newStr) not run . Who can help me ? thanks !

هل كانت مفيدة؟

المحلول

I found reason :

$this->view->layout ()->disableLayout ();
$this->_helper->viewRenderer->setNoRender ( TRUE );

I had :

public function userauthorizingAction() {
    $userInfo = Zend_Auth::getInstance ()->getStorage ()->read ();
//add tow rows below
    $this->view->userLogin = $userInfo->employee_name;
    $this->EmpID = $userInfo->employee_id;

    $requestForm = new Default_Model_RequestformModel ();
    $this->view->role = $requestForm->getRoleUserCurent ( $this->EmpID );

    if($this->_request->isGet()){
        $sreenModel = new Default_Model_ScreenModel();
        $roleModel = new Default_Model_RoleModel();

        $this->view->screenData = $sreenModel->loadScreenList();
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top