Reputation: 2800
Inside my Magento Project folder I want to install laravel so that I can access Mage
from laravel. Directory structure is following
Magento(root)
--laravel
--app
...
...
How can I achieve That? Or suggest any other way so that I can access magento from laravel like following.
require_once ('../app/Mage.php');
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
UPDATE
Controller Location relative to magento
D:\xampp\htdocs\magento\custom\app\controllers\ProductsController.php
Upvotes: 0
Views: 1433
Reputation: 4369
Maybe someone useful:
require_once (dirname(dirname(dirname(dirname(realpath(__FILE__))))).'/../app/Mage.php');
\Mage::app();
$blocks = \Mage::getModel('cms/block')->getCollection();
foreach ($blocks as $block) {
echo $block->getTitle()."<br>";
}
Upvotes: 0
Reputation: 2800
I have used dirname()
function to solve this problem.
require_once (dirname(dirname(dirname(dirname(realpath(__FILE__))))).'/app/Mage.php');
I don't think this the nice or smart way, but it works. Thanks.
Upvotes: 0
Reputation: 7798
Your path ( require_once ('../app/Mage.php');
) is not correct that's why you are facing this issue.Except this logic wise your code is correct.
If you are running your code from somefile.php in laravel then it should work.
Magento(root)
--laravel
|__somefile.php
--app
...
...
Upvotes: 1
Reputation: 1042
Make sure the path is correct, it should work.
Use this one
require_once (realpath(dirname(__FILE__) . '/../app/Mage.php'));
Upvotes: 1