Jump to content

Include file that uses variable before set

- - - - -

  • Please log in to reply
No replies to this topic

#1
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Hi there,

Having small problem: Im inluding a config file for all widgets of the system and some of them use by user inputten info which is in database but is retrieved AFTER including the widgets config file. So it can't use this info as it is put into a variable ( using mysql_fetch_assoc ) AFTER the config file is included. So for exmaple:

$sys_widgets['html_text'] = $widget['customVal']; //custom val for widget should be given by user when widget is added to database

Is a widget that uses the customVal field which is inside database, and this function gets the widgets from database and uses the above widget if it's inside the database:

/* START GET SYS WIDGETS */
 
//HERE the config is included for all widgets
include($set['cms_absolutepath']."/modules/standard_widgets.php"); 
 
 
$select_widgets = mysql_query("SELECT * FROM widgets WHERE template = '".$set['cms_template']."' AND hook = '$hook' AND wType = 'sys' ORDER BY orderid")or die(mysql_error());
 
 
while($widget = mysql_fetch_assoc($select_widgets)) {
 
//HERE it sets the content of a widget found in database according to the config file
$widget['content'] = $sys_widgets[$widget['name']];
 
include($set['cms_absolutepath']."/templates/".$set['cms_template']."/standard_widget.php"); //the template for the widget
 
}
 
/* END GET SYS WIDGETS */

</SPAN>Can anyone help me out?
</SPAN>

EDIT: only options I see for now is either use macro-like words inside the config file and replace them when retrieving the results by the actual values from database or having each widget that uses custom values from database have its own file which is included at moment of retrieving ( when found at database ).

As for now I solved it like this but dunno if there's any 'better' way to do it:

if(!empty($widget['customVal'])) {
$sys_widgets[$widget['name']] = preg_replace("/\<widget\['customVal'\]\>/", $widget['customVal'], $sys_widgets[$widget['name']]);
}

Then used <widget['customVal']> inside config file which is then replaced by the actual customVal found from database.
</SPAN>




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users