更改config文件夹中的routes.php后,如何修复这些php错误


How can I fix these php errors after altering routes.php in config folder?

我正在从数据库中动态更新我的路由文件。不幸的是,我狡猾的计划造成了一些问题。

我在配置文件的routes.php末尾添加了这一行:

include_once APPPATH . "cache/routes.php";

缓存文件夹中的routes.php文件正在自动更新,这很好。目前,它看起来像这样:

$route["index"] = "pages/index/1";

$route["About Us/suppgetest"]="pages/index/4";$route["关于我们"]="pages/index/3";

问题是,我在每一页的顶部都会收到这些错误:

遇到PHP错误严重性:警告

消息:无法修改标头信息-标头已由发送(输出开始于/home/jshultz/public_html/application/cache/routes.php:3)

文件名:core/Security.php

行号:188

遇到PHP错误严重性:警告

消息:无法修改标头信息-标头已由发送(输出开始于/home/jshultz/public_html/application/cache/routes.php:3)

文件名:libraries/Session.php

行号:672

我以为这可能是权限错误,但我不知道?我已尝试更改该文件的权限,但没有更改任何内容。有什么想法吗?

编辑:

好的,所以application/cache文件夹中的routes.php需要打开

以下是在缓存文件夹中创建routes.php文件的更正代码:

public function save_routes()
        {
            // this simply returns all the pages from my database
            $routes = $this->Pages_model->get_all($this->siteid);
            // write out the PHP array to the file with help from the file helper
            if ( !empty( $routes ) )
            {
                // for every page in the database, get the route using the recursive function - _get_route()
                foreach( $routes->result_array() as $route )
                {
                    $data[] = '$route["' . $this->_get_route($route['pageid']) . '"] = "' . "pages/index/{$route['pageid']}" . '";';
                }
                $output = "<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');'n";
                $output .= implode("'n", $data);
                $this->load->helper('file');
                write_file(APPPATH . "cache/routes.php", $output);
            }

您可能需要在文件开头添加<?php并从中删除Byte Order Mark

/home/jshultz/public_html/application/cache/routes.php

并且不使用PHP结束标记?>在该文件中。使用?>将强制解释器将标记后面的字符视为文本输出。