Can't figure out why my "routes" array isn't working (using Ninja framework from "PHP & MySQL Novice to Ninja"

I recently ported a site over from XAMPP on a MacBook Air to the Sites folder on a MacBook Pro. PHP works MySQL works. But my site is no longer functions due to some problem with the “routes” array that creates file paths. I’m using the Ninja framework set out in Butler and Yank’s PHP & MYSQL Novice to Ninja. It all worked great before! But now I get an error, “Method name must be a string in /Users/…/EntryPoint.php:56.” The “run()” method isn’t working, and I suspect the problem may be somewhere in my “routes” array. When I print_r the array, it looks okay, except for the very beginning:

Array ( [] => Array ( [GET] => Array ( [controller] => ...

The first item is empty. Shouldn’t it contain the name of my site, so that the run() method can piece together the file path? If so, why doesn’t it? How can I fix it?

The lines in EntryPoint.php that aren’t working seem to be these:

$controller = $routes[$this->route][$this->method]['controller'];
$action = $routes[$this->route][$this->method]['action'];
$page = $controller->$action();
$title = $page['title'];

If I var_dump $action or $controller, I get “NULL.” I don’t think the problem is with the code, exactly, because it did work before. But I’m not sure what’s causing the problem. Can anyone help?

So, standard caveman debugging time.
print_r or echo (not var_dump) out the following:

1 Like

as m_hutley says, run through the code and see what it’s doing. Compare the variables to your routes array and see what values are being looked up. It sounds like the keys in your $routes array do not match the value for $this->route.

Yes, that’s correct. They don’t. Index.php loads at localhost, but nothing else, so maybe the problem is somewhere with the url rewriting. I’ll keep tinkering away.

If you’re not using the preconfigured vagrant box you’ll need to set the server up to forward all requests to index.php, there’s instructions on how to do it in the book.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.