CodeIgniter Forums

Full Version: Controller Called Twice?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I do not understand and error message I am getting in the Codeigniter logs. I sure hope someone can point me in the right direction to get rid of this irritant.

I have this controller function:
Code:
public function showresultsNoDB($year, $id) {
       $file = "$year/$id";
       if (file_exists($file)) {
           $data['scoreSheet'] = file_get_contents($file);

       } else {
           $data['scoreSheet'] = "The report for the game ($file) is not available.";
           log_message('error', "The report for the game ($file) is not available.");
       }
       $dateObj = DateTime::createFromFormat('ymd', substr($id, '0', '6'));
       $currentGameDateFormatted = $dateObj->format('l, F j, Y');

       $data['date'] = "$currentGameDateFormatted";
       $data['club'] = "";
       $data['title'] = "CCBC Results";

       $this->load->view('scores/header2', $data);
       $this->load->view('scores/showResults', $data);
       $this->load->view('templates/footer');
   }

I call the function with:

Code:
http://ccbridgeclub.org/scores.php/showresultsNoDB/2015/150106E.HTM
with the first argument being the $year and the second being the $id which is a file name.

The function is triggered and the desired page loads.  All is well.  Except the log file error message is triggered and reports:

ERROR - 2015-01-12 12:39:41 --> The report for the game (2015/css) is not available.
ERROR - 2015-01-12 12:39:41 --> The report for the game (2015/images) is not available.
ERROR - 2015-01-12 12:39:41 --> The report for the game (2015/images) is not available.

The words in the paretheses come from the $file variable and show that the $file has been changed from what was passed into the function.

Sometimes the error is only reported once and sometimes, as above, three times.  I cannot see any pattern to how many times the error message is logged. Clearly, the load->views are not triggered with the incorrect file name since no page would load.

The route for the function is:

Code:
$route['showresultsNoDB/(:any)'] = "scores/showresultsNoDB/$1";

I have tried a number of different routes which either do not work or have no effect on the logging of the error message.

Help please!

Bill
What is the controller's class name?
Try this route:

PHP Code:
$route['showresultsNoDB/(:any)/(:any)'] = "scores/showresultsNoDB/$1/$2"
It looks like your asset (CSS/image) requests are being routed to your controller (probably via relative URLs in link/img tags).

You might see some js requests in there, too, but it looks like you have an error in your footer template which is causing the opening script tags to be closed before outputting the src attribute.
(01-13-2015, 09:32 AM)Rufnex Wrote: [ -> ]Try this route:


PHP Code:
$route['showresultsNoDB/(:any)/(:any)'] = "scores/showresultsNoDB/$1/$2"

Thanks, I was pretty sure I had tried that before and when I made your change I got the same result as before--reporting an error for a file that was not requested.

For awhile, I thought it had something to do with my php error reporting level, but that does not appear to be the case.

Other suggestions?

Bill
(01-13-2015, 09:39 AM)mwhitney Wrote: [ -> ]It looks like your asset (CSS/image) requests are being routed to your controller (probably via relative URLs in link/img tags).

You might see some js requests in there, too, but it looks like you have an error in your footer template which is causing the opening script tags to be closed before outputting the src attribute.

Thank you!

I had a relative link to the favicon.ico file and when I put in a full path the errors stopped.

Please have a virtual beer on me.  Big Grin  Big Grin

Bill