Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2007
    Posts
    241
    Plugin Contributions
    0

    help question init_db_config_read.php - overriding 'cgfvalue' after DB read using PHP code

    I have a question regarding some of the ZC3.8 PHP code modules, how they interact with a MySQL database, and how to override data set in this module.

    I have observed that the file init_db_config_read.php reads the configuration fields from the database ('cfgkey'), and then sets each with a value from a different field in the database. '(cfgvalue')

    That much I understand clearly.

    What I wanted to know, because I have a few different ideas in mind, is how I might code an override for a single database config value using additional PHP code.

    I figured that after the init_db_config_read.php module sets up the config values by reading and placing them in the 'cfgvalue' corresponding to the 'cfgkey' , I could just assign new values immediately afterwards, using PHP, in a new module.

    I am not really familiar with PHP, though. I know what I need to code is something like this (in PHP, of course!) :

    if VALUE33 = 5 then 'cfgvalue' (associated with 'CFGkey X ') = "newer"

    OK...I didn't mention that I wanted a place a conditional in here as well, to determine whether to reset the 'cfgvalue'.
    Last edited by Donn; 24 Apr 2009 at 04:38 PM. Reason: clarification......

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

    Default Re: init_db_config_read.php - overriding 'cgfvalue' after DB read using PHP code

    Perhaps you can explain what exactly you want to override and why. ie: which particular config key(s), etc
    .

    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
    Oct 2007
    Posts
    241
    Plugin Contributions
    0

    Default Re: init_db_config_read.php - overriding 'cgfvalue' after DB read using PHP code

    Quote Originally Posted by DrByte View Post
    Perhaps you can explain what exactly you want to override and why. ie: which particular config key(s), etc
    I haven't really gotten very far with this, in terms of any specific goals as of yet, just wondering how it could be done, and *IF* it could be done.

    It seems like a useful idea to me....It may not be, maybe it'll end up just being a good way to play with (and likely mess up...lol) my (test) cart and learn more about the cart AND PHP programming.

    I understand that probably, the way to do this, if I were to do it, keeping to 'good form', would be to have ALL values stored in the database, and not the PHP code itself.

    So, to begin with, in this sort of modular programming, should values ever be 'hard-set' in the manner in which I wanted, directly in the PHP code?

    If not, I suppose I should learn how to set up a database column for the alternative values, and then figure out how to read the values, using PHP. (I'm slowly learning how to code this sort of function by reviewing the parts of ZC that already do this. Even so, so far I am still not really sure of it all.)

    If I end up playing around with this idea, I will probably just skip ahead and do the setting of the values and strings in PHP first (the way I asked about in my initial post), even if that IS poor form.

    Later, if I end up actually finding a use for any of this, I can learn how to actually do it properly, reading the table, if that is the better way to proceed?

    Finally, if referring to table data for ALL configurable values and strings (besides ones that are set in the english.php file and such) IS the 'right way' to do this, I would like to know the reason.


    Thank you...

    Donn

  4. #4
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: init_db_config_read.php - overriding 'cgfvalue' after DB read using PHP code

    I'm not following you. Surely there's a "why" behind your questions.


    At the strictly technical level, yes, you can set a PHP define in a .php file, sometime before the database values are read. But, then your database settings don't actually match what you're forcing the system to do, meaning that you are creating inconsistencies, resulting in difficulties in supporting and diagnosing problems or unexpected behaviors, etc.

    Again, it really depends on what sort of "configurable values and strings" you're contemplating, and why.
    Are you trying to write some sort of addon that bypasses normal already-configured behaviors? If so, it would seem you're getting into dangerous territory.

    But, without knowing the "why" behind your inquiries, it just seems you're poking in dangerous territory.
    .

    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.

  5. #5
    Join Date
    Oct 2007
    Posts
    241
    Plugin Contributions
    0

    Default Re: init_db_config_read.php - overriding 'cgfvalue' after DB read using PHP code

    Quote Originally Posted by DrByte View Post
    I'm not following you. Surely there's a "why" behind your questions.


    At the strictly technical level, yes, you can set a PHP define in a .php file, sometime before the database values are read. But, then your database settings don't actually match what you're forcing the system to do, meaning that you are creating inconsistencies, resulting in difficulties in supporting and diagnosing problems or unexpected behaviors, etc.

    Again, it really depends on what sort of "configurable values and strings" you're contemplating, and why.
    Are you trying to write some sort of addon that bypasses normal already-configured behaviors? If so, it would seem you're getting into dangerous territory.

    But, without knowing the "why" behind your inquiries, it just seems you're poking in dangerous territory.
    Hi again Dr. Byte and forum members!

    I thought the concept of a 'dynamic' cart that could change based on some real-time conditions would be an interesting idea.

    I guess, based on your response, that it COULD work, but it probably isn't a good way of doing things. I see that it could potentially lead to a great deal of confusion later, when trying to work with the cart....

    I really didn't have any specific applications in mind, just the basic idea of some conditional, reflecting SOME thing happening....being able to change (otherwise) set values.

  6. #6
    Join Date
    Oct 2007
    Posts
    241
    Plugin Contributions
    0

    Default Re: init_db_config_read.php - overriding 'cgfvalue' after DB read using PHP code

    (First...Please note that this is NOT a priority for me, just an idea that I was thinking about.....!!)

    Anyway....

    I found a user-written add-on module called 'Template Switch'.

    Template switch checks the DB value for $template_dir, but then may override based on user-defined settings.

    Similar to what I had posted about, though $template_dir is a variable, and not a constant.....

    Even so, this was sort of the type of scenario I was envisioning, in terms of a 'dynamic' cart responding to conditions. (In this case, input, a user-selected template choice.)


    I do have a few (general) questions remaining...

    Is $template the same as TEMPLATE?
    Or do they refer to different things...the VARIABLE $template and the CONSTANT TEMPLATE??

    I've been reading up on PHP, and it SEEMS they are not at all related, but I'd like confirmation on that....

    Also, I am confused...how long to constants stay 'set' for?

    I've read 'for the session'. Does that mean until the user logs off, until the page is reloaded, or something else? I could not find any info regarding this...

    Thanks.............!

  7. #7
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: init_db_config_read.php - overriding 'cgfvalue' after DB read using PHP code

    Quote Originally Posted by Donn View Post
    I do have a few (general) questions remaining...

    Is $template the same as TEMPLATE?
    No
    Quote Originally Posted by Donn View Post
    Or do they refer to different things...the VARIABLE $template and the CONSTANT TEMPLATE??
    Correct.

    Quote Originally Posted by Donn View Post
    Also, I am confused...how long to constants stay 'set' for?
    From the time they are set until the time the PHP script stops executing.
    The next "click" starts with a clean slate, and things get set all over again while the next page draws.
    Unlike variables, constants cannot be "changed" or "unset" once set.

    You can read more about constants and variables in PHP on the PHP website documentation: http://www.php.net/manual/en/language.constants.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.

 

 

Similar Threads

  1. Replies: 5
    Last Post: 3 Jun 2014, 05:42 PM
  2. v151 Using php code in payment module language files?
    By gilby in forum Addon Payment Modules
    Replies: 1
    Last Post: 16 Apr 2013, 05:10 AM
  3. Meta_tags.php not overriding english.php
    By Servelan in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 19 Apr 2011, 12:21 AM
  4. To read session in the init_db_config_read.php
    By arvind21 in forum General Questions
    Replies: 0
    Last Post: 22 Jun 2009, 02:42 PM
  5. hidding affilate code using php
    By bmpt in forum General Questions
    Replies: 7
    Last Post: 16 May 2009, 07:31 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