我成功创建了一个自定义管理模块,并在菜单中成功加载并成功呈现了phtml文件。
然后我尝试在单击按钮时使用angularJS在相同的管理模块中通过ajax加载一些虚拟数据,但是ajax调用返回magento admin的仪表板的html内容。
我遵循了link
以下是控制器的代码
@Query("select category from Category category where category.isDelete=false and category.status='A' AND " +
"category.id in (select cat.id from Category cat where cat.isDelete=false and cat.status='A' and cat.parentCategory IS NOT NULL)")
@Query("select category from Category category where category.isDelete=false and category.status='A' and category.parentCategory IS NOT NULL")
以下是phtml文件中使用的JS代码
<?php
namespace DVendor\DemoModule\Controller\Adminhtml\DemoPart;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Controller\Result\JsonFactory;
class Index extends \Magento\Backend\App\Action
{
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
protected $jsonPageFactory;
public function __construct(Context $context,PageFactory $resultPageFactory,JsonFactory $jsonPageFactory){
$this->resultPageFactory = $resultPageFactory;
$this->jsonPageFactory = $jsonPageFactory;
parent::__construct($context);
}
public function execute()
{
if($this->getRequest()->isAjax()){
$result = $this->jsonPageFactory->create();
$test=array(
'Firstname' => 'What is your firstname',
'Email' => 'What is your emailId',
'Lastname' => 'What is your lastname',
'Country' => 'Your Country'
);
return $result->setData($test);
}
else{
return $resultPage = $this->resultPageFactory->create();
}
}
}
?>