当我尝试创建 XML/Soap 用户时显示此错误,我单击添加用户并收到此错误。
致命错误:在第 74 行 /var/www/vhosts/domain.com/httpdocs/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php 中调用布尔值的成员函数 getId()
这是我的 UserController.php
<?php
class Mage_Adminhtml_Api_UserController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->_title($this->__('System'))
->_title($this->__('Web Services'))
->_title($this->__('Users'));
$this->_initAction()
->_addContent($this->getLayout()->createBlock('adminhtml/api_user'))
->renderLayout();
}
protected function _initAction()
{
$this->loadLayout()
->_setActiveMenu('system/services/users')
->_addBreadcrumb($this->__('Web Services'), $this->__('Web Services'))
->_addBreadcrumb($this->__('Permissions'), $this->__('Permissions'))
->_addBreadcrumb($this->__('Users'), $this->__('Users'));
return $this;
}
public function newAction()
{
$this->_forward('edit');
}
public function editAction()
{
$this->_title($this->__('System'))
->_title($this->__('Web Services'))
->_title($this->__('Users'));
$id = $this->getRequest()->getParam('user_id');
$model = Mage::getModel('api/user');
if ($id) {
$model->load($id);
if (!$model->getId()) {
Mage::getSingleton('adminhtml/session')->addError($this->__('This user no longer exists.'));
$this->_redirect('*/*/');
return;
}
}
$this->_title($model->getId() ? $model->getName() : $this->__('New User'));
// Restore previously entered form data from session
$data = Mage::getSingleton('adminhtml/session')->getUserData(true);
if (!empty($data)) {
$model->setData($data);
}
Mage::register('api_user', $model);
$this->_initAction()
->_addBreadcrumb($id ? $this->__('Edit User') : $this->__('New User'),
$id ? $this->__('Edit User') : $this->__('New User'))
->_addContent($this->getLayout()->createBlock('adminhtml/api_user_edit') - >setData('action',
$this->getUrl('*/api_user/save')))
->_addLeft($this->getLayout()->createBlock('adminhtml/api_user_edit_tabs'));
$this->_addJs($this->getLayout()->createBlock('adminhtml/template')->setTemplate('api/user_roles_grid_js.phtml'));
$this->renderLayout();
}
public function saveAction()
{
if ($data = $this->getRequest()->getPost()) {
$id = $this->getRequest()->getPost('user_id', false);
$model = Mage::getModel('api/user')->load($id);
if (!$model->getId() && $id) {
Mage::getSingleton('adminhtml/session')->addError($this->__('This user no longer exists.'));
$this->_redirect('*/*/');
return;
}
$model->setData($data);
try {
$model->save();
if ($uRoles = $this->getRequest()->getParam('roles', false)) {
/*parse_str($uRoles, $uRoles);
$uRoles = array_keys($uRoles);*/
if (1 == sizeof($uRoles)) {
$model->setRoleIds($uRoles)
->setRoleUserId($model->getUserId())
->saveRelations();
} else {
if (sizeof($uRoles) > 1) {
//@FIXME: stupid fix of previous multi-roles logic.
//@TODO: make proper DB upgrade in the future revisions.
$rs = array();
$rs[0] = $uRoles[0];
$model->setRoleIds($rs)->setRoleUserId($model->getUserId()) - >saveRelations();
}
}
}
Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The user has been saved.'));
Mage::getSingleton('adminhtml/session')->setUserData(false);
$this->_redirect('*/*/edit', array('user_id' => $model->getUserId()));
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setUserData($data);
$this->_redirect('*/*/edit', array('user_id' => $model->getUserId()));
return;
}
}
$this->_redirect('*/*/');
}
public function deleteAction()
{
if ($id = $this->getRequest()->getParam('user_id')) {
try {
$model = Mage::getModel('api/user')->load($id);
$model->delete();
Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The user has been deleted.'));
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('user_id' => $this->getRequest() - >getParam('user_id')));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find a user to delete.'));
$this->_redirect('*/*/');
}
public function rolesGridAction()
{
$id = $this->getRequest()->getParam('user_id');
$model = Mage::getModel('api/user');
if ($id) {
$model->load($id);
}
Mage::register('api_user', $model);
$this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/api_user_edit_tab_roles')->toHtml());
}
public function roleGridAction()
{
$this->getResponse()
->setBody($this->getLayout()
->createBlock('adminhtml/api_user_grid')
->toHtml()
);
}
protected function _isAllowed()
{
return Mage::getSingleton('admin/session')->isAllowed('system/api/users');
}
}
当我启用错误报告时,我从日志中看到此错误
mod_fcgid: stderr: PHP Fatal error: Call to a member function getId() on boolean in /var/www/vhosts/domain.com/httpdocs/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php on line 74, referer: http://www.domain.com/index.php/admin/api_user/index/key/b2a855c2e5d82b8a3ba010f07f3883af/
当我单击“SOAP/XML-RPC 用户”中的“添加新用户”时,我在浏览器中看到了这一点。
Fatal error: Call to a member function getId() on boolean in /var/www/vhosts/domain.com/httpdocs/app/code/core/Mage/Adminhtml/controllers/Api/UserController.php on line 74
查看 load() 函数在此上下文中返回的内容:
$model = Mage::getModel('api/user')->load($id);
在脚本的前面,您执行了以下操作:
$model = Mage::getModel('api/user');
随后是
$model->load($id);
我想你有:
$model = Mage::getModel('api/user')->load($id);
你同样需要做:
$model = Mage::getModel('api/user');
$model->load($id);
如果您不提供更多代码,我不能肯定地说,但我猜测 load() 函数通过设置某些类变量将相应的 $id 值“加载”到对象中,并返回 True 或 False; 它不返回加载的对象本身。