如何使用codeigniter在控制器中编写routes.php文件?

时间:2012-10-10 10:38:30

标签: php file codeigniter

我使用codeigniter尝试在routes.php中添加文本,我想要做的是在config / routes.php中添加文本,我已经将route.php文件更新为777权限,但它无效。

这是我的代码

$file_path = "var/www/html/staging/oscar/anthola/application/config/routes.php";
$file_exists = read_file($file_path);
$slug ="123";
if ( ! write_file($file_path, $slug))
{
     echo 'Unable to write the file';
    echo write_file('./config/routes.php', $slug);
}
else
{
     echo 'File written!';
      echo write_file('./config/routes.php', $slug);
}

知道如何解决我的问题吗?

1 个答案:

答案 0 :(得分:1)

我同意Robin的评论,但如果这是你想要关闭的路线,那么我建议在routes.php文件的底部添加以下行:

include_once APPPATH . "cache/routes.php";

这样,您不会覆盖default_controller404_override路由,但仍可以向Codeigniter应用程序添加其他路由。

在您的控制器中,您可以添加以下几行

$this->load->helper('file');
$output = '$route["route"] = "controller/action";';
write_file(APPPATH . "cache/routes.php", $output);

希望有所帮助。