Where can I put scripts so templates and protected content can use them?

Discussion in 'Templates customization' started by engineerwsu, Oct 6, 2015.

  1. engineerwsu

    engineerwsu New Member

    Joined:
    Sep 18, 2014
    Messages:
    19
    I am having some difficulty with the mod_rewrites I think. I am trying to use my navigation scripts on both my custom template pages (the layout.phtml) as well as in my protected content. I will give a simple explanation of what I need to do.

    Custom layout.phtml page
    /amember/application/default/themes/mytheme/layout.phtml
    include '/amember/myfolder/menu.php' - this doesn't work

    Protected Folder
    /amember/myfolder
    $path=$_SERVER['DOCUMENT_ROOT']
    $path .= "/amember/myfolder/menu.php"
    include ($path)

    Menu scripts
    /amember/myfolder/menu.php
    /amember/myfolder/menu.js (this uses AJAX and references the php file)

    When the menu scripts are included into the templates their "absolute" path is a little different than the protected content pages I think because of the mod_rewrite occurring.

    I don't want to try to manage two copies of the scripts (one for the themes and one for protected content). Where can I locate my php and js scripts where both my custom templates AND all my protected content can reference them using an absolute path?
  2. engineerwsu

    engineerwsu New Member

    Joined:
    Sep 18, 2014
    Messages:
    19
    Here's what I found. PHP doesn't care about the mod_rewrite directives when processing include paths. I had to step away from the computer for a bit for this thought to occur to me. Since mod_rewrite is processed by the web server (not the PHP interpreter), it won't look at mod_rewrites. So, in this case, I simply use $mypath = $_SERVER['DOCUMENT_ROOT']; $mypath .= "/level1/level2/somefile.file"; Seems to work.

    I also thought there was an issue with css and js file includes, but I just used absolute paths instead of relative. I suppose when using absolute paths it doesn't matter which directory you put files into as long as you reference it using an absolute reference.

    I was getting hung up on the fact that sometimes you cannot directly access files inside a protected directory with .htaccess. If you attempt to open a php file (depending on the .htaccess parameters), you will be denied, which is intended.
  3. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,669
    Yes, you are right. By the way I do not recommend to put your content to subfolder of amember folder (/amember/myfolder). It is better to use folder outside of amember forlder for it eg.: /myfolder
  4. engineerwsu

    engineerwsu New Member

    Joined:
    Sep 18, 2014
    Messages:
    19
    Thanks Cesar. I'll probably take your advice and locate my codes somewhere else. Just so I know - why do you recommend putting content somewhere else? Code security, upgrade simplicity, etc?
  5. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,669
    It is better to keep stuff organized and do not mess different software in same folder.
    Also aMember uses special .htaccess rules that can conflict with your application.
    Best practice is not put anything to folder with amember.

Share This Page