Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2012
    Posts
    452
    Plugin Contributions
    0

    Default How to load shared functions?

    I have several custom functions that I need on both the store side and admin side. To date, I've been duplicating the functions on both sides creating problems with maintenance and taking up extra memory. So I put all the shared functions in a shared functions file on the store side and tried to auto-load the file in the admin. The code I used is:
    Code:
    if (!defined ('IS_ADMIN_FLAG')) { 
        die ('Illegal Access'); 
    }
    $autoLoadConfig[0][] = array(
        'autoType' => 'require',
        'loadFile' => DIR_WS_FUNCTIONS . 'extra_functions/shared_functions.php',
    );
    which is placed in a file named config.shared_functions.php located in admin/includes/auto_loaders/.

    But it doesn't work. I still get call to undefined function fatal error. The undefined function is in the shared_functions.php file located in includes/functions/extra_functions/. There are no other errors. I followed the instructions in the docs.

    What am I doing wrong?

    Dave

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,343
    Plugin Contributions
    94

    Default Re: How to load shared functions?

    Quote Originally Posted by Dave224 View Post
    I have several custom functions that I need on both the store side and admin side. To date, I've been duplicating the functions on both sides creating problems with maintenance and taking up extra memory. So I put all the shared functions in a shared functions file on the store side and tried to auto-load the file in the admin. The code I used is:
    Code:
    if (!defined ('IS_ADMIN_FLAG')) { 
        die ('Illegal Access'); 
    }
    $autoLoadConfig[0][] = array(
        'autoType' => 'require',
        'loadFile' => DIR_WS_FUNCTIONS . 'extra_functions/shared_functions.php',
    );
    which is placed in a file named config.shared_functions.php located in admin/includes/auto_loaders/.

    But it doesn't work. I still get call to undefined function fatal error. The undefined function is in the shared_functions.php file located in includes/functions/extra_functions/. There are no other errors. I followed the instructions in the docs.

    What am I doing wrong?

    Dave
    If that's the admin auto-loader, you need to use
    Code:
    $autoLoadConfig[0][] = array(
        'autoType' => 'require',
        'loadFile' => DIR_FS_CATALOG . DIR_WS_FUNCTIONS . 'extra_functions/shared_functions.php',
    );

  3. #3
    Join Date
    Jun 2012
    Posts
    452
    Plugin Contributions
    0

    Default Re: How to load shared functions?

    Thank you, thank you, thank you! It works!

  4. #4
    Join Date
    Jun 2012
    Posts
    452
    Plugin Contributions
    0

    Default Re: How to load shared functions?

    lat9,
    Can the same technique be used for common store and admin defines in zc 1.5.7, and in zc 1.5.8 and beyond with the new lang. approach?
    Dave

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,343
    Plugin Contributions
    94

    Default Re: How to load shared functions?

    Quote Originally Posted by Dave224 View Post
    lat9,
    Can the same technique be used for common store and admin defines in zc 1.5.7, and in zc 1.5.8 and beyond with the new lang. approach?
    Dave
    Yep. In the admin, the DIR_WS_* definitions refer to the like-named directories in the admin. You need to prefix those definitions with DIR_FS_CATALOG to pull in the storefront/common files.

    Just remember for language files, that the file (with or without the lang. prefix) could be present in a template-specific sub-directory.

  6. #6
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,754
    Plugin Contributions
    30

    Default Re: How to load shared functions?

    Since a file in the admin .../extra_functions is loaded automatically, I have a file in there that just includes the store function file....no need to edit the auto loader.

    Or am I missing something?
    Steve
    github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

  7. #7
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,343
    Plugin Contributions
    94

    Default Re: How to load shared functions?

    Quote Originally Posted by torvista View Post
    Since a file in the admin .../extra_functions is loaded automatically, I have a file in there that just includes the store function file....no need to edit the auto loader.

    Or am I missing something?
    It's an alternate approach if there are functions available only to the admin in addition to those 'shared' ones. If a site is just using a set of shared functions, then it's just as easy to create an entry in an auto_loader instead of an admin /extra_functions file.

 

 

Similar Threads

  1. v156 /includes/functions /admin/includes/functions Why do the same functions exist?
    By shrimp-gumbo-mmmhhh in forum General Questions
    Replies: 2
    Last Post: 8 May 2019, 08:00 AM
  2. Category section load slow after moving from shared to VPS?
    By tripflex in forum General Questions
    Replies: 14
    Last Post: 4 Jun 2011, 04:14 AM
  3. how to add class or id to zen functions ?
    By tony_sar in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 17 Mar 2010, 02:09 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR