I want to get customer session in a dir which is outside of my magento main dir. For e.g. root/magento/ => is my installation dir
root/temp/ => is my test folder
root/checksession.php => is the file on root of magento installation
root/temp/checksession.php => is the file outside of magento dir and inside of external dir.
Here i am getting the customer session in root/checksession.php but i dont know why the same coding is not working with root/temp/checksession.php
Have tried include, define and php session method, but still its not working.
Do any one have idea, how it is possible to get magento session in root/temp/checksession.php file???
require_once 'app/Mage.php';
Mage::app("default");
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));
session_start();
$_SESSION["coreSession"] = $coreSession;
echo "<pre>";print_r($coreSession);
I think you forgot the following:
Mage::app('admin')->setUseSessionInUrl(false);
Related
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
Make sure the path is correct, it should work.
Use this one
require_once (realpath(dirname(__FILE__) . '/../app/Mage.php'));
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
...
...
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.
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>";
}
I'm having trouble installing/moving laravel to web server, i downloaded and set laravel on my local linux server but when i moved it to web server ,it shows a blank page.
I uploaded the public folder contents to public_html and other contents outside the public, also i changed the public DIR from paths.php on bootstrap folder as follow: 'public' => __DIR__.'/../public_html/' so what is the exact problem? Please help me with this issue. Is composer a problem? or what?
1) Create a new directory called ‘laravel4′ adjacent to ‘public_html’ so that your remote file structure now looks like this:
[.htpasswds]
[etc]
[laravel4]
[mail]
[public_ftp]
[public_html] etc etc varies depending on server
2) Upload the contents of your local ‘public’ directory to the remote directory ‘public_html’. Note: Be sure not to copy the whole ‘public’ directory, JUST it’s contents.
3) Upload everything else within your local Laravel project to the new remote ‘laravel4′ directory. Check: Now when you view the ‘laravel4′ folder over FTP/SSH/Whatever, you should see all your ‘app’ & ‘bootstrap’ directories along with all the other files and directories, but NOT ‘public’.
4) Edit the remote file ‘public_html/index.php’ and make the following change:
//from:
require __DIR__.'/../bootstrap/autoload.php';
//and
$app = require_once __DIR__.'/../bootstrap/start.php';
//to:
require __DIR__.'/../laravel4/bootstrap/autoload.php';
//and
$app = require_once __DIR__.'/../laravel4/bootstrap/start.php';
5) Edit the remote file ‘laravel4/bootstrap/paths.php’ and make the following change:
//from:
'public' => __DIR__.'/../public',
//to:
'public' => __DIR__.'/../../public_html',
6) That should be it. In my case, that was enough to restructure everything. Routes are working with the default .htaccess file. If you have problems, let me know, or ask on the ever-helpful
Reference: http://myquickfix.co.uk/2013/08/hosting-laravel-4-on-cpanel-type-hosting-public_html/
I am trying to use the following code to get Admin session to check whether admin is logged in or not. File created at the level of /app folder.
include('app/Mage.php');
Mage::app();
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
if(Mage::getSingleton('admin/session')->isLoggedIn()){
Mage::getSingleton("core/session")->setAdminLogin("1");
echo "Admin Logged In..";
}
else
{
echo "go away bad boy";
}
This code is working fine at the level of /app.
But when I put this file within a folder at the level of /app, then it works only first time.
Can I have a best solution for this issue ?
I'm about to deploy laravel 4 on a shared web host into a subdomain and I'm a bit confused about what to do. I got it working on a hostpapa account but wasnt happy with the configuration and switched providers for the testing environment.
I've created the following folders:
domain/private/myApps/golfmanager
I've placed in here all the files and folders except the public folder
I've then placed the contents of the public folder into this folder:
domain/subdomains/golfmanager/httpddocs
I'm not sure what to do now! I understand I need to change the paths in bootstrap/path.php
Can someone provide some pointers of what needs to be changed for this folder set up. Don't want to break it!!
Thanks
This is super easy on shared hosting.
Step 1: Understanding your folder structure. The layout of your shared hosting should generally look something like this:
/
username
home
public_html
subdomain-name
laravel-files (optional)
...other folders etc
As you hopefully know, all your public files for your site will be in your public_html folder.
Note: sometimes a subdomain will be inside the public_html folder. That is okay but I recommend creating your subdomain folder above the root for a little bit of extra security. You can do that easily in cPanel but changing the path to the subdomain when you are creating it.
Step 2: Upload your Laravel files above the root (above public_html) or in a subfolder if you want it to be cleaner.
For a small project I generally upload the files into the "home" folder above. But for cleaner structure you may want to create a folder inside that "home" folder called "laravel-files".
What follows is how to do it in an "laravel-files" folder. If you upload them to "home" instead then all you need to do is get rid of all references to "/laravel-files" below.
Step 3: edit your public/index.php and your bootstrap/paths.php files:
In paths.php
change
'app' => __DIR__.'/../app',
to:
'app' => __DIR__.'/../laravel-files/app',
change:
'public' => __DIR__.'/../public',
to:
'public' => __DIR__,
change:
'base' => __DIR__.'/..',
to:
'base' => __DIR__.'/../laravel-files',
change:
'storage' => __DIR__.'/../app/storage',
to:
'storage' => __DIR__.'/../laravel-files/app/storage',
In index.php
change:
require __DIR__.'/../bootstrap/autoload.php';
to:
require __DIR__.'/../laravel-files/bootstrap/autoload.php';
change:
$app = require_once __DIR__.'/../bootstrap/start.php';
to:
$app = require_once __DIR__.'/../laravel-files/bootstrap/start.php';
Now what you'll need to do is, as I said upload your laravel project to your "laravel files" folder.
The only thing you wont upload there is the contents of your laravel "public" folder, which should instead be uploaded to your "subdomain-name" folder (this includes your index.php and all your css js files etc).
Hope this helps!
Please note my answer is based on this question: How to install Laravel 4 to a web host subfolder without publicly exposing /app/ folder? but tailored for your situation.
I'm not sure this is the way to go, because, since your folders are completely different, it's doable but you probably will need to create symlinks for this to work this way.
Laravel is supposed to have the folder hiearchy you see in your application and you should have
domain/subdomains/golfmanager/httpddocs/app
domain/subdomains/golfmanager/httpddocs/bootstrap
domain/subdomains/golfmanager/httpddocs/public
domain/subdomains/golfmanager/httpddocs/vendor
So, what I think you can do it to put everything on
domain/subdomains/golfmanager/httpddocs
And ask your domain administrator to set the document root of your application to
domain/subdomains/golfmanager/httpddocs/public
This way, when you point your browser to
http://golfmanager.yourdomain.com
It will access this index file:
domain/subdomains/golfmanager/httpddocs/public/index.php
This is how Laravel is supposed to work.
Josh answer was very helpful, but it did not work or did not matched my case.
I will tailor my solution like his one, so everyone could follow easily:
Step 1: My chosen folder structure:
/
home
username
public_html
subdomain-name
laravel-files
...other folders etc
Note: my subdomain is inside the public_html folder.
Step 2: Uploaded my Laravel files above the root (above/out of public_html) in a subfolder: laravel-files (//home/username/laravel-files)
Step 3: edit your public/index.php and your bootstrap/paths.php files:
In paths.php
Don't change:
'app' => __DIR__.'/../app',
to:
'app' => __DIR__.'/../../laravel-files/app',
because it's useless - it will evaluate to the following path:
"/home/username/laravel-files/bootstrap/../../laravel-files/app"
so the default is enough to just get out of bootstrap and enter app.
Instead, change:
'public' => __DIR__.'/../public',
to:
'public' => __DIR__.'/../../public_html/subdomain-name',
Also, don't change:
'base' => DIR.'/..',
'storage' => DIR.'/../app/storage',
In index.php
change:
require __DIR__.'/../bootstrap/autoload.php';
to:
require __DIR__.'/../../laravel-files/bootstrap/autoload.php';
and change:
$app = require_once __DIR__.'/../bootstrap/start.php';
to:
$app = require_once __DIR__.'/../../laravel-files/bootstrap/start.php';
Upload your laravel project to the "laravel-files" folder, except the public folder.
Content of "public" folder, should instead be uploaded to the "subdomain-name" folder.
I am running Magento CE 1.7.0.2 and am trying to set up a second store using the 'subdirectory method' described here: http://www.crucialwebhost.com/blog/how-to-setup-multiple-magento-stores/
When I try to navigate to my new storefront it gives me this error:
"[my root directory]/[my new store's subdirectory]/app/Mage.php was not found"
Everything else in the backend of Magento seems to be setup fine - can anybody help?
Thanks
After you copy the index.php to the sub directory, you would need to change the index.php in the subdirectory to point it to the app/Mage.php.
Find the following in the subdirectory index.php
$mageFilename = 'app/Mage.php';
and replace it with
$mageFilename = '../app/Mage.php';
For completeness you should do the same thing for the $compilerConfig variable
$compilerConfig = '../includes/config.php';