Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access Magento from CodeIgniter?
    text
    copied!<p>I have a default CodeIgniter 2.1 install with Magento 10.4.4 installed in a subdir called store.</p> <p>The following code works when run from web root (with .htaccess disabled). It will give the firstname, lastname of the logged in Magento user.</p> <pre><code>&lt;?php $site_root = '/var/www/mysite/www/httpdocs'; require_once ($site_root . '/store/app/Mage.php'); umask(0); // Initialize Magento and hide sensitive config data below site root $name='frontend'; $options = array('etc_dir' =&gt; realpath('../magento-etc')); Mage::app('default','store', $options); Mage::getSingleton("core/session", array("name" =&gt; $name)); $websiteId = Mage::app()-&gt;getWebsite()-&gt;getId(); echo "websiteid: $websiteId&lt;br&gt;"; $store = Mage::app()-&gt;getStore(); $customer = Mage::getModel("customer/customer"); $customer-&gt;website_id = $websiteId; $customer-&gt;setStore($store); echo 'customerwebsiteId: ' . $customer-&gt;website_id . '&lt;br&gt;'; $session = Mage::getSingleton('customer/session'); $magento_message = 'Welcome '; // Generate a personalize greeting if($session-&gt;isLoggedIn()){ $magento_message .= $session-&gt;getCustomer()-&gt;getData('firstname').' '; $magento_message .= $session-&gt;getCustomer()-&gt;getData('lastname').'!'; }else{ $magento_message .= 'Guest!'; } echo $magento_message; ?&gt; </code></pre> <p>But, if I run this in a CodeIgniter model, then <code>isLoggedIn</code> returns false. </p> <p>Here is the CodeIgniter page:</p> <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Test_mage extends CI_Controller { function __construct() { parent::__construct(); } public function index() { $site_root = '/var/www/mysite/www/httpdocs'; require_once ($site_root . '/store/app/Mage.php'); umask(0); // Initialize Magento and hide sensitive config data below site root $name='frontend'; $options = array('etc_dir' =&gt; realpath('../magento-etc')); Mage::app('default','store', $options); Mage::getSingleton("core/session", array("name" =&gt; $name)); $websiteId = Mage::app()-&gt;getWebsite()-&gt;getId(); echo "websiteid: $websiteId&lt;br&gt;"; $store = Mage::app()-&gt;getStore(); $customer = Mage::getModel("customer/customer"); $customer-&gt;website_id = $websiteId; $customer-&gt;setStore($store); echo 'customerwebsiteId: ' . $customer-&gt;website_id . '&lt;br&gt;'; $session = Mage::getSingleton('customer/session'); $magento_message = 'Welcome '; // Generate a personalize greeting if($session-&gt;isLoggedIn()){ $magento_message .= $session-&gt;getCustomer()-&gt;getData('firstname').' '; $magento_message .= $session-&gt;getCustomer()-&gt;getData('lastname').'!'; }else{ $magento_message .= 'Guest!'; } echo $magento_message; } } </code></pre> <p>CodeIgniter is doing something that I have not been able to track yet. The websiteId is returned correctly, but <code>isLoggedIn</code> returns false.</p> <p>Anyone have any ideas? THANKS!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload