Skip to main content
added 1530 characters in body
Source Link
AKM
  • 87
  • 10

How to call the controller method from model?

Or

How to programmatically reindexing using API?


Here is my code.Below code gives me error like below.

{ "messages": { "error": [ { "code": 500, "message": "Fatal Error: 'Class Inchoo\Hello\Model\Hello contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Magento\Framework\App\ActionInterface::execute)' in 'C:\new\xampp\htdocs\ChoiceWholesale\app\code\Inchoo\Hello\Model\Hello.php' on line 5", "trace": "Trace is not available." } ] } }

<?php
namespace Inchoo\Hello\Model;
use Inchoo\Hello\Api\HelloInterface;

class Hello extends \Magento\Framework\App\Action\Action implements HelloInterface
{

    protected $indexFactory;
    protected $indexCollection;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Indexer\Model\IndexerFactory $indexFactory,
        \Magento\Indexer\Model\Indexer\CollectionFactory $indexCollection
    )
    {
        $this->indexFactory = $indexFactory;
        $this->indexCollection = $indexCollection;
        return parent::__construct($context);
    }

    public function name() {

        $indexerCollection = $this->indexCollection->create();
        $indexids = $indexerCollection->getAllIds();

        foreach ($indexids as $indexid)
        {
          $indexidarray = $this->indexFactory->create()->load($indexid);

          //If you want reindex all use this code.
           $indexidarray->reindexAll($indexid);

          //If you want to reindex one by one, use this code
           $indexidarray->reindexRow($indexid);

           echo "Reindexing Id :: " .$indexid ."<br>"; 

        }
        echo "Reindexing Completed";
        exit;
        
    }
}

How to call the controller method from model?

Or

How to programmatically reindexing using API?

How to call the controller method from model?

Or

How to programmatically reindexing using API?


Here is my code.Below code gives me error like below.

{ "messages": { "error": [ { "code": 500, "message": "Fatal Error: 'Class Inchoo\Hello\Model\Hello contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Magento\Framework\App\ActionInterface::execute)' in 'C:\new\xampp\htdocs\ChoiceWholesale\app\code\Inchoo\Hello\Model\Hello.php' on line 5", "trace": "Trace is not available." } ] } }

<?php
namespace Inchoo\Hello\Model;
use Inchoo\Hello\Api\HelloInterface;

class Hello extends \Magento\Framework\App\Action\Action implements HelloInterface
{

    protected $indexFactory;
    protected $indexCollection;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Indexer\Model\IndexerFactory $indexFactory,
        \Magento\Indexer\Model\Indexer\CollectionFactory $indexCollection
    )
    {
        $this->indexFactory = $indexFactory;
        $this->indexCollection = $indexCollection;
        return parent::__construct($context);
    }

    public function name() {

        $indexerCollection = $this->indexCollection->create();
        $indexids = $indexerCollection->getAllIds();

        foreach ($indexids as $indexid)
        {
          $indexidarray = $this->indexFactory->create()->load($indexid);

          //If you want reindex all use this code.
           $indexidarray->reindexAll($indexid);

          //If you want to reindex one by one, use this code
           $indexidarray->reindexRow($indexid);

           echo "Reindexing Id :: " .$indexid ."<br>"; 

        }
        echo "Reindexing Completed";
        exit;
        
    }
}

Magento 2: Call Controller method call from Model class

How to call the controller method call from model function?

Or

How to programmatically reindexing using API?

Magento 2: Call Controller method call from Model class

How to controller method call from model function?

Or

How to programmatically reindexing using API?

Magento 2: Call Controller method from Model

How to call the controller method from model?

Or

How to programmatically reindexing using API?

Source Link
AKM
  • 87
  • 10

Magento 2: Call Controller method call from Model class

How to controller method call from model function?

Or

How to programmatically reindexing using API?