Modify a php file that contains definition in a form
I have a file that has a load of definitions in it. I want to be able to modify these definitions from a form.
Lets say I have a file with;
When my form is submited I will have the number and the name being passed to it.
default for template 4
defaults for template 5
defaults for template 6
So lets say I want to add "Some text" to template 5 I would want it to go UNDER the DB_MENU_5_CLOSE and NOT just appended to the bottom as:
I am obviosly creating a string above but my problem is finding how to input it in the correct location on the definitions page.
define(DB_MENU_5_SOMETEXT, "Some text"); // Added DATETIME
There will be consistency with the \*** begining a template and obviously \*** will start the next one see we kinda have the point of references.
I am hoping that the same would apply if I wanted to alter the value of a definition?
Last edited by k0r54; 05-26-2010 at 11:29 AM.
You might find this response odd...
First off, define() creates a constant which, according to PHP's own reference page for that function, can only be changed in one way -- if set to the value of another constant. You can see if it's been defined already using defined() but a constant really is an identifier to a variable who's value "cannot change during the execution of a script" as per the PHP docs on constants. There are a few magic constants such as the ever popular "__FILE__" which change based on where they're used, but a normal constant is SUPPOSED to be just that -- constant, unchanging.
But guess what...
The results of that, with no errors, are:
string(3) "foo" string(3) "bar"
This is true in PHP 5.3.2 on my system - and seems to exploit a weakness in the third parameter of the define() function which is supposed to determine case sensitivity when creating the constant. It seems if you explicitly define true (even though its the default, case insensitive) this behavior occurs. Bug?
Just because you can do this now doesn't mean you should!
So I'm saying don't use constants for things like what you're trying to do.
Ok, was affraid of something like that. It means a complete rebuild of the system.
What I might do as a work around for the moment is put all these into a database and at the begining of the script create a definition from the results of the sql statement.
Not sure what speed implications that would have but it is a step in the correct direction whilst I trawl through all parts of the code removing any definition that should not be used in this way.
thanks for the insight!
That would work, or a simple XML file, or CVS, or custom .ini file. Also, you can still generate the PHP script with constants, code a back end CONFIGURATION TOOL or utility which allows admins to create and update said file (i.e. formats suggested above or your current format), just keep the admin config and interface separate, or standalone. No changing the existing code, just extending it. A few cosmetic changes to link the admin page, and maybe store the admin password encrypted in any of said formats or methods.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)