ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Cannot Continue, with PHP only Echo works

December 20, 2012 11:51pm

Subscribe [2]
  • #1 / Dec 20, 2012 11:51pm

    vw000

    482 posts

    I was trying to modernize my web systems and modifying some PHP files to work inside EE for better management and in the future to be able to use EE features for them.

    But im really stuck because EE variables does not seems to work in PHP at all.

    This works for example in a PHP tag:

    $uid = '{username}';
    echo $uid;

    Ok, so the username is displayed with PHP using echo, in the template. Very simple. Which is nice. But that is where luck ends. That is all what works, only echo. You cannot use the EE variables inside PHP.

    For example I tried to load a simple XML file with PHP using the username as path like this:

    $xml_document = simplexml_load_file('/home/website/'.$uid.'/file.xml');

    Notice that UID in this case is supposed to be the logged in EE user.

    It does not work. In the first example if I change $uid to a a fixed text like “joe” it will work in the XML documenting loads.

    Before EE I had the $uid being printed by another PHP system, so this code actually worked nice. Since I want to integrate this files into EE I need to be able to use the EE username authentication and features, but it seems impossible.

    In Google I found someone asking exactly a similar question here:
    http://stackoverflow.com/questions/6171828/expressionengine-tags-inside-php

    And it seems nobody found a solution based on the replies.

    If this cannot be done, then there is really no point in trying to use EE at all for my PHP files, because I could not use its variables in PHP. Would I be just better off not using PHP files with EE?

    This would mean again maintaining 2 different websites, one in EE and one for PHP files which is what I wanted to avoid by centralize everything under EE. How else are people doing this? I don“t think anyone would be crazy enough to drop PHP just because they are using EE as well.

    So my development is actually stopped because if I cannot even use a simple username from EE, then I did not even went to adventure as far as to try more advanced stuff.

    Help would be extremely appreciated.

  • #2 / Dec 21, 2012 11:00am

    Gareth Davies

    491 posts

    A lot of these issues usually have to do with parse order. Firstly is your php set to input or output?

    For the code with $uid, this should work:

    $uid = $this->EE->session->userdata('member_id');
    $xml_document = simplexml_load_file('/home/website/'.$uid.'/file.xml');

    Here is a helpful guide by Low that details the order in which things are parsed in EE: http://loweblog.com/downloads/ee-parse-order.pdf

  • #3 / Dec 22, 2012 7:53am

    vw000

    482 posts

    Actually before posting this there, I did tried the parse order, input, output, etc, it did not made any difference.

    Your code worked. The first line did the trick. I guess I can use that one for every code with EE then.

    Thanks Gareth your a good person.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases