0

我正在尝试将以下内容写入$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);
            }
        }
    } 
4

1 回答 1

1

$route[] 部分被解释为一个不存在的变量。您需要将其视为字符串:

 $routeConfig[] = "\$route['screenings/details/(:any)/(:any)'] = \"screenings/details/\$1/\$2\"";
 $routeConfig[] = "\$route['screenings'] = \"page/load/$data['post_id']/$data['post_url_link']\"";
于 2013-11-07T03:04:03.973 回答