Jess McKenzie
Jess McKenzie

Reputation: 8385

using fp open to write a file data

I am trying to write following $routeconfig below to a file however I am only getting the following result how can I make it so it writes the full $route[] = data?

Result:

screenings/details/$1/$2
page/load/2949/screenings

Code:

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);
            }
        }
    } 

Upvotes: 0

Views: 521

Answers (1)

Dave
Dave

Reputation: 14178

The $route[] part is being interpreted as a variable, which doesn't exist. You need to treat it as a string:

 $routeConfig[] = "\$route['screenings/details/(:any)/(:any)'] = \"screenings/details/\$1/\$2\"";
 $routeConfig[] = "\$route['screenings'] = \"page/load/$data['post_id']/$data['post_url_link']\"";

Upvotes: 1

Related Questions