I try to call a function from a module A to a module B
here is the module A code
namespace AEpaymentModel;
class Etransactions
{
public function customPayment{
return "test";
}
and module b code
namespace BPaymentControllerIndex;
class Payment extends MagentoFrameworkAppActionAction
{
protected $_pageFactory;
protected $_transaction;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $pageFactory,
ETransactionsEpaymentModelEtransactions $transaction
)
{
$this->_pageFactory = $pageFactory;
$this->_transaction = $transaction;
parent::__construct($context);
}
public function execute()
{
echo "Hello World".PHP_EOL;
$foo="a";
echo $foo;
echo $this->_transaction->customPayment();
//echo $this->customPayment();
echo $foo;
exit;
}
}
this code return the “hello world”, the first $foo, not the second and doesn’t display any error
can someone explain me where is my error ?
EDIT: i didn’t change anything but it works fine now.
thanks for the answers anyway
2
Answers
The object you want create the path your are injecting is incorrect.
Kindly use exception handling.
In Magento, Helper classes are available to use anywhere (Block, Controller, Model, Observer, View). So you should create a method in helper class and call it anywhere by the following way.
Declar the helper class and method:
ModuleAEpaymentHelperData
.Call the method:
Note: If the object manager is not injected in your class. Please follow the steps below:
1) declare private property:
2) inject in the constructor to initialize:
3) use in some method: