Depending on which file you're in, using __DIR__ could be useful (as opposed to __FILE__), as it gives you current directory information.
Depending on which file you're in, using __DIR__ could be useful (as opposed to __FILE__), as it gives you current directory information.
.
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.
Challenge accepted?! :)
The second link provides functionality that would get you to the point of loading and instantiating an observer class through the use of the auto_loaders type structure. Basically whatever "function" you wanted to be done would be the 'autoType' in the auto_loaders file. Effectively the method called within the InitSystem is 'processAutoLoader' . $var['autoType'] (yes there is some case play, but lets say you wanted to load a class file (such as an observer), then the 'autoType' would be 'class' to load the class, then 'classInstantiate' to initialize the class (calling its __construct method).)
To "simply" require a file would in fact need some "path" information as discussed above about "finding" where things are currently located so that the associated processAutoLoaderRequire method could pull in the correct file(s).
For loading a class would likely have the autoloader look something like:
This seems as if it would load an observers class in the admin directory of the plugins section for "this" version of the plugin.Code:<?php if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } $autoLoadConfig[200][] = [ 'autoType' => 'class', 'classPath' => 'observers/', 'loadFile' => 'new_observer.php', ]; $autoLoadConfig[200][] = [ 'autoType' => 'classInstantiate', 'className' => 'zcObserverNewObserverClass', 'objectName' => 'myObsVariable', 'classSession' => false, 'checkInstantiated' => false, ];
The last two variables of the classInstantiate section are not required, but at least provide a template for what might be expected in instantiating a class through the plugin controller...
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
noted.
as i just learned about the auto. loading of observers, i have previous done all of the "heavy lifting" myself. so this is not a problem.
ok... i will debug and find out where i am going wrong. or if there is an issue in the initSystem. i'm guessing now that this is where i will be looking.
https://github.com/zencart/zencart/b...System.php#L82
i ended up using:
which i think is cleaner, in-line with what you are saying, and easier to read. i will perhaps investigate the aforementioned ZC function though.PHP Code:
$path_info = dirname(__DIR__);
thanks again. i will let you know where i have gone adrift in the loading of the observer.
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
correct. yes.
Code:[236] => Auto Type Method - processAutoTypeClass [237] => processing class - /var/www/base157/zc_plugins/shipAdmin/1.0.0/admin/includes/classes/observers/my_bloody_observer.php [238] => loading class - /var/www/base157/zc_plugins/shipAdmin/1.0.0/admin/includes/classes/observers/my_bloody_observer.php - SUCCESS
Seems like it would be a good idea in the docs to indicate that constants such as DIR_WS_INCLUDES should not be used in plugins when referring to directories such as the classes and/or other "defined" paths...
Reason? those particular constants are associated with the store and not with the plugins where plugins should be developed to be applicable to "any" store's configuration. Meaning, the path used should be relative to the plugin's directory structure and not the store's directory structure when referencing items within the plugin's folder...
I was otherwise going to suggest actually using DIR_WS_CLASSES (which I thought was going to be used by the plugin loader path until you made the change identified above and showing the processed path here).
Btw, in line with DrByte's previous statement about loading a class file, using the above 'class'/'classInstantiate' would allow you to declare a variable name that can be used within your other plugin areas. That variable is the 'objectName'. In this way you don't have to "chase" down the current path for the file being loaded, just load the class as part of your plugin and reference it from within the plugin...
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
interesting. perhaps i will look into it.
next hurdle to jump over is some javascript files that need to get loaded on the page load. again trying to keep everything within the encapsulated plugin directory. i suppose i could load the contents into the page load as opposed to a reference to the file (which would necessitate being outside of the plugin). but i am open to other ideas.
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
ok, thanks for this. it seems that i had some difficulty with file names that had multiple words in them. for example, if my filename was bloody.php, includes/javascript/bloody.js would load as well as includes/javascript/bloody_rsvp-min-3.1.0.min.js. if, my filename was bloody_mask.php; i had some difficulty getting the .js files to load.
could be me.
but, again, i do appreciate the help. using the ZC file naming for loading javascript works out better here.
best.
Bookmarks