how to use a PHP Constant that gets pulled from a database

Posted by Ronedog on Stack Overflow See other posts from Stack Overflow or by Ronedog
Published on 2010-05-14T18:41:13Z Indexed on 2010/05/14 18:44 UTC
Read the original article Hit count: 234

Filed under:
|

Can you read out the name of a PHP constant from a database and use it inside of a php variable, to display the value of the constant for use in a menu?

For example here's what I'm trying to accomplish

In SQL: select menu_name AS php_CONSTANT where menu_id=1 the value returned would be L_HOME which is the name of a CONSTANT in a php config page. The php config page looks like this define('L_HOME','Home'); and gets loaded before the database call. The php usage would be $db_returned_constant which has a value of L_HOME that came from the db call, then I would place this into a string such as $string = '<ul><li>' . $db_returned_constant . '</li></ul>' and thus return a string that looks like $string = '<ul><li><a href="#" onclick="path_from_db">Home</a></li></ul>'.

To sum up what I'm trying to do

  1. Load a config file based on the language preference
  2. query the db to return the menu name, which is the name of a CONSTANT in the config file loaded in step one, and also retrieve the menu_link which is used in the "onclick" event.
  3. Use a php variable to hold the name of the CONSTANT
  4. Place the variable into a string that gets echo'd out to create the menu displaying the value of the CONSTANT.

I hope this makes enough sense...is it even possible to use a constant like this?

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about constants