簡體   English   中英

如何使用codeigniter在controllar中編寫routes.php文件?

[英]how to write routes.php file in controllar using codeigniter?

我使用codeigniter嘗試在route.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);
}

知道如何解決我的問題嗎?

我同意Robin的評論,但是如果這是您要拒絕的路線,那么我建議向您的route.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);

希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM