I have used below code to print response from my Model file.
<?php
class CountrylistManagement implements
\Vendor\Module\Api\CountrylistManagementInterface
{
protected $_storeManager;
protected $objectManager;
protected $_resource;
protected $resultJsonFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\ObjectManagerInterface $objectManager,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
$this->_objectManager = $objectManager;
$this->_storeManager = $storeManager;
$this->_resource = $resource;
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($context);
}
public function postCountrylist($params)
{
$resultArr = array();
$request = json_encode($params);
$resultArr['message'] = "Success";
$resultArr['code'] = 200;
$resultJson = $this->resultJsonFactory->create();
$resultJson->setData($resultArr);
return $resultJson;
}
}
Here I am trying to print the json response from the model file, The above code works well from controller.
Can we use $resultJson = $this->resultJsonFactory->create(); to print the response from model file?
right now its not working for me. if anyone can look into this and update where i am doing wrong please.