Welcome Guest, Not a member yet? Register   Sign In
Updating config/routes.php using mysql
#5

[eluser]robert.fulcher[/eluser]
mattnewark,

From looking at the code, you are looping, and the blow code
Code:
$data = '$route["' . $r['link'] . '"] = "' . $r['route'] . '";';
will reassign $data to the most recent information that is in the string to the right of the equals. Resulting in just the last line only being written to the file.

So what you need to do is build your full $data string and then write it once to the file. I think the reason you got the undefined variable is because you did not define $data outside the for each.

Give this a try

Code:
function update_routes()
    {
            $this->db->select("*");
            $query = $this->db->get("articles");
            $data = '';
            foreach ($query->result() as $r)
                {
                    $data = $data.'$route["' . $r['link'] . '"] = "' . $r['route'] . '";';
                }
            write_file(APPPATH . 'cache/routes.php', $data);                
    }

Basically you initialize the $data outside the foreach and it should be ok.

Thanks


Messages In This Thread
Updating config/routes.php using mysql - by El Forum - 07-14-2014, 04:44 AM
Updating config/routes.php using mysql - by El Forum - 07-14-2014, 09:03 AM
Updating config/routes.php using mysql - by El Forum - 07-14-2014, 09:55 AM
Updating config/routes.php using mysql - by El Forum - 07-14-2014, 12:14 PM
Updating config/routes.php using mysql - by El Forum - 07-14-2014, 12:27 PM
Updating config/routes.php using mysql - by El Forum - 07-14-2014, 12:51 PM
Updating config/routes.php using mysql - by El Forum - 07-14-2014, 12:53 PM
Updating config/routes.php using mysql - by El Forum - 08-20-2014, 01:51 PM
Updating config/routes.php using mysql - by El Forum - 08-20-2014, 03:12 PM
Updating config/routes.php using mysql - by El Forum - 08-21-2014, 01:46 AM
Updating config/routes.php using mysql - by El Forum - 08-21-2014, 07:34 AM
Updating config/routes.php using mysql - by El Forum - 08-21-2014, 08:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB