Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to use magento class in an outside Magento php script ? 
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

I wrote a php script completly outside Magento folder structure, but this script need to use one of my Magento module class.
My script find well the file where my class is but i get this error ::

Fatal error: Class ‘Mage_Adminhtml_Controller_Action’ not found in /var/users/n.pegourie/Tests/Projet/magento4/magento/app/code/local/MyCompany/MonModule/controllers/ImportController.php

The final goal of my script is to call a method of my controller, I succefully use this method with a button pointing on a url, but i want to be able to call it iautomatically with a script

It’s possible and how ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

You need to require_once the Mage class.  I would think that would work.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ron Phillips
Member
 
Total Posts:  57
Joined:  2008-04-16
 

I needed to include a product sample block on the customers blog, this is the code I generated the product with. So yes, as was stated above, include the Mage class and instantiate it as I have. This creates a shell class so there isn’t as much overhead as a standard call.

<?php

require_once '/home/boomstud/public_html/app/Mage.php';
    
Mage::app('default');

$className Mage::getConfig()->getBlockClassName('catalog/product_bydate');
$block = new $className();
$block->setCategoryId(8);
$block->setNumProducts(4);
$block->setDisplayOrder("rand()");
$block->setTemplate('catalog/product/releasebydate.phtml');

echo 
$block->renderView();

//Mage::getLayout()->createBlock('catalog/product_list')->setCategoryId(8)->toHtml();    

?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

Sorry do not thanks you sooner but i was on a another problem.

Thanks a lot for your anwser, it works.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top