我正在尝试将下面的$routeconfig
写入文件但是我只得到以下结果如何才能创建它以便写出完整的$route[] = data
?
结果:
screenings/details/$1/$2
page/load/2949/screenings
代码:
public function hook_process()
{
if (!file_exists('../cache/'.DOMAIN_NAME.'-routes.php'))
{
$modelData = $this->CI->routes_hook->getData();
foreach($modelData as $data)
{
if($data['post_url_link'] == 'screenings')
{
$routeConfig[] = $route['screenings/details/(:any)/(:any)'] = 'screenings/details/$1/$2';
$routeConfig[] = $route['screenings'] = 'page/load/'.$data['post_id'].'/'.$data['post_url_link'].'';
}
$output = implode("\n", $routeConfig);
$fp = fopen(''.$_SERVER['DOCUMENT_ROOT'].'/cache/'.DOMAIN_NAME.'-routes.php', 'w+');
fwrite($fp, $output);
fclose($fp);
}
}
}
答案 0 :(得分:1)
$ route []部分被解释为一个不存在的变量。您需要将其视为字符串:
$routeConfig[] = "\$route['screenings/details/(:any)/(:any)'] = \"screenings/details/\$1/\$2\"";
$routeConfig[] = "\$route['screenings'] = \"page/load/$data['post_id']/$data['post_url_link']\"";