We are using Zend framework. We are creating module from Admin Panel or during Run time, but its layout is not working because we need to define following code in the application.ini
pizzahut.resources.layout.layout = "layout"
pizzahut.resources.layout.layoutPath = APPLICATION_PATH "/modules/pizzahut/layouts/scripts/"
Is this possible that we can edit our application.ini during run time using PHP, or could we add new layout configuration in application.ini using PHP?
After doing some googling, I have found that we can edit our application.ini
with PHP.
Here is the code:
$config = parse_ini_file(
APPLICATION_PATH . "/configs/application.ini",
TRUE,
INI_SCANNER_RAW
);
$config["production"]["$store.resources.layout.layout"] = "layout";
$layoutPath = 'APPLICATION_PATH "/modules/' . $store . '/layouts/scripts/"';
$config["production"]["$store.resources.layout.layoutPath"] = $layoutPath;
$result = Helper_common::write_ini_file(
$config,
APPLICATION_PATH . "/configs/application.ini",
TRUE
);
Here parse_ini_file
is used to retrieve content from the application.ini
file with constants .
write_ini_file
is the function that I am calling to rewrite the application.ini
file.
Here is the write_ini_file
function:
public static function write_ini_file($assoc_arr, $path, $has_sections=FALSE) {
$content = "";
if ($has_sections) {
foreach ($assoc_arr as $key=>$elem) {
$content .= "[".$key."]\n";
foreach ($elem as $key2=>$elem2) {
if(is_array($elem2))
{
for($i=0;$i<count($elem2);$i++)
{
$content .= $key2."[] = ".$elem2[$i]."\n";
}
}
else if($elem2=="") $content .= $key2." = \n";
else $content .= $key2." = ".$elem2."\n";
}
}
}
else {
foreach ($assoc_arr as $key=>$elem) {
if(is_array($elem))
{
for($i=0;$i<count($elem);$i++)
{
$content .= $key2."[] = ".$elem[$i]."\n";
}
}
else if($elem=="") $content .= $key2." = \n";
else $content .= $key2." = ".$elem."\n";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
if (!fwrite($handle, $content)) {
return false;
}
fclose($handle);
return true;
}
ini files are loaded when the application starts running, before bootstrap , so no you can't.
check these out to see how to change layout dynamically at run-time:
http://vandenbos.org/zend-framework-module-specific-layout/
http://forums.zend.com/viewtopic.php?f=69&t=2466&start=0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.