我想在zend 1中将多行插入数据库,但是我有一个错误:
致命错误:未捕获异常'Zend_Controller_Dispatcher_Exception',消息'D:\ HR_New \ 30_SourceManagement \ HRSystem \ library \ Zend \ Controller \ Dispatcher \ Standard.php中有'无效控制器指定(错误)':248堆栈跟踪:#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}抛出D:\ HR_New \ 30_SourceManagement \ HRSystem \ library \ Zend \ Controller \ Dispatcher \ Standard.php在第248行
这是我的代码: 在* .phtml中,我有一个ajax函数:
$('#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);
}
});
}
});
使用arrCode是一个对象,数据为:
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
我的控制器的功能如下:
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 ) );
}
}
这个我的模型有一个函数:
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) {
}
}
}
当我使用die($ newStr)时,我得到了一个SQL。但$ this-&gt; db-&gt;查询($ newStr)未运行。谁能帮我 ?谢谢!
答案 0 :(得分:0)
我找到了理由:
$this->view->layout ()->disableLayout ();
$this->_helper->viewRenderer->setNoRender ( TRUE );
我有:
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();
}
}