Dat Posted July 19, 2008 Share Posted July 19, 2008 How can I get $TEMPLATE's default value as true; So that later when I create $TEMPLATE[uSER_CAN_EDIT] = false; I can use that later with if (TEMPLATE[uSER_CAN_EDIT] == true) { //Something } else if (TEMPLATE[uSER_CAN_EDIT] == false) { //Something else } I want all of the array's of $TEMPLATE's value to be true as default; so when if i were to change them later I can do what is above. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 19, 2008 Share Posted July 19, 2008 You can't? Well, you can like this: $TEMPLATE['USER_CAN_EDIT'] = true; But that's pointless...you should just use some database logic and find out whether or not they can use it. Also, for the record, use ' ' around your array keys. Please. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 19, 2008 Share Posted July 19, 2008 In short, you can't do that. What you could do is check to see if a particular key has been set. Indeed, i'd reverse your logic. It would make more sense from a safety point of view to ensure that each option is false to start with. It should only be set to true if the required authorization is met. Doing it your way leaves you open to making a mistake allowing access to something you did not wish. So, i'd do this: if(isset($TEMPLATE['USER_CAN_EDIT'])){ //allow editing }else{ //don't allow } You would then allow editing just be adding the key to the array: //conditions have been met to allow editing $TEMPLATE['USER_CAN_EDIT'] = TRUE;//the actual value assigned would be irrelevant Note that you would only add the key if you want to allow it. You wouldn't, for example, set $TEMPLATE['USER_CAN_EDIT'] to false to prevent editing, you would just not set it at all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.