Reputation: 373
I am creating a script that will accomplish some tasks automatically from CRON which are now done from the backend(admin manually). How can I invoke the Magento extensions' controller, its methods and pass necessary parameters from code?
I thought about using curl using admin login and make necessary requests. But I was wondering if there is an easy way to accomplish this without curl and if is just simply about including some files and call the necessary classes and methods, or if there is a way to extend the extensions' classes and work with them directly.
For example,
require "Mage.php";
$testcontroller = New TestController();
$testcontroller->method();
Upvotes: 1
Views: 647
Reputation: 373
I was able to implement a solution and it is working fine like I needed. Thanks to this link and thanks to others who are posting answers as well.
The following code lives on an external script. The parameters value will come through my custom SQL scripts.
require "Mage.php";
require "PATH TO YOUR MAGENTO EXTENSION CONTROLLER.php";
umask ( 0 );
Mage::app ( 'admin' );
Mage::app()->getRequest()->setParam('TEST','123');
$testcontroller = New TestController(Mage::app()->getRequest());
$testcontroller->method();
Upvotes: 2
Reputation: 3534
In order for Magento/Zend to put together all of the correct objects like Request/Response, you'll need the server environment variables like $_POST,$_GET,$_COOKIE etc. So don't do that.
Your controller action should just be acting on some models and calling their methods. It should not contain the application logic itself, but act as just a "controller". In that case, you should open your config.xml in your module's etc directory and create a cron task:
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job
This way you are triggering your application logic without a server environment and no longer need the controller.
Upvotes: 0