I'm trying to adapt a module from prestashop to Magento. In this module my page is calling a script js with angular.js then the script himself have some function to interact from the controller who's getting a function from a class.

so i have in my phtml (the code is still for Prestashop for the moment):

<tr ng-repeat="(keyDescReplace,descReplace) in descReplaces">
                <td>{{ descReplace.toreplace }}</td>  //this is the calling of angular js
                <td>{{ descReplace.replaceby }}</td>  //this is the calling of angular js

then in my js script i have


in my controller i have

public function ajaxProcessGetDescReplaces()
            'descReplaces' => getAll()

and finally in my class i have

public function getAll(){
    $data = array();
    $model = $this->contactFactory->create();
    $newData = $model->getCollection();
    foreach ($newData as $d )  {
        echo $d->getToreplace();
        echo $d->getReplaceby();

    // the base code was   return Db::getInstance()->executeS('SELECT * FROM `my table');

i know it's not very clear but can someone help me pls to adapt the code to link the controller to the block so he can get the getAll() function.

  • Welcome to Stack Exchange, @Antoine553 Jul 6, 2017 at 13:11

1 Answer 1


You can call Block function inside controller using below way,

$getBlock = $this->getLayout()->createBlock("Mymodule\Adminpange\Block\Customblock");

Where Mymodule\Adminpange\Block\Customblock pass your block class path.

  • hello @Rakesh Jesadiya , i used this but getting internal server 500 error in my controller Jul 18, 2019 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.