Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    98
    Plugin Contributions
    1

    help question How to require a /includes/classes file from admin page?

    Hiya,

    I'm having trouble require'ing a class file from an admin file. I have zen cart 1.3.8a in a normal apache install, located at web root, nothing fancy. I've written a custom class (or three) e.g. /includes/classes/warranty.base.php which work fine from the customer-facing /includes/... side of things.

    My admin side has a helper class in /admin/includes/classes/warranty.php. How should I require my warranty.base.php file from the admin's warranty.php file? That is, a class file in /admin/includes/classes is trying to include a class file from /includes/classes. I'd like to use the zen cart defines such as DIR_WS_WHATEVER if possible.

    PHP Code:
    require(DIR_WS_CLASSES 'warranty.base.php'); 
    generates:

    Code:
    PHP Warning:  require(includes/classes/warranty.base.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in <obscured>/admin/includes/classes/warranty.php on line 8
    That makes sense, the path should not be relative to admin, it should be relative to web root. A very basic hardcoded attempt that I thought should work..

    PHP Code:
    require('/includes/classes/warranty.base.php'); 
    generates:

    Code:
    PHP Warning:  require(/includes/classes/warranty.base.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in <obscured>/admin/includes/classes/warranty.php on line 8
    I'm confused as to why that second attempt failed.
    The warranty.base.php file definitely exists, I can direct my browser to my.site.com/includes/classes/warranty.base.php and get 200 OK.

    Annoyingly, this does work:

    PHP Code:
    require(DIR_WS_CLASSES "../../../includes/classes/warranty.base.php"); 
    This would seem to resolve to "includes/classes/../../../includes/classes/warranty.base.php", which relative to the /admin/includes/classes/warranty.php file would be "/admin/includes/classes/../../../includes/classes"

    Thanks!
    Nick

  2. #2
    Join Date
    Jan 2004
    Posts
    66,440
    Plugin Contributions
    279

    Default Re: How to require a /includes/classes file from admin page?

    Either of these will work:
    Code:
     require('../includes/classes/warranty.base.php');  
    
     require(DIR_FS_CATALOG . '/includes/classes/warranty.base.php');
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Feb 2009
    Posts
    98
    Plugin Contributions
    1

    Have a Drink Re: How to require a /includes/classes file from admin page?

    Quote Originally Posted by DrByte View Post
    Either of these will work:
    Code:
     require('../includes/classes/warranty.base.php');
    Ah, so the paths are relative to the page loading them (/admin/my_page.php) not the php file in which you place the require() directive (/admin/includes/classes/thing.php).

    Many thanks for the pointer. I'm now using the DIR_FS_CATALOG approach, as my require's are in an /admin/include/classes file that I want to be able to require from any admin page without worrying about the position of that admin page in the file structure.

    +1
    Nick

 

 

Similar Threads

  1. Version help with admin/includes/classes/order.php
    By Brent in forum General Questions
    Replies: 2
    Last Post: 4 Jan 2011, 03:25 PM
  2. What does this (admin/includes/classes/transliteration/) folder do?
    By mikecnz in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 4 Nov 2010, 02:17 AM
  3. Replies: 0
    Last Post: 10 Oct 2009, 02:38 AM
  4. require(includes/index_filters/default): No such file or directory
    By bluefirefly in forum General Questions
    Replies: 2
    Last Post: 17 Sep 2009, 03:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg