I've got the following code snippet from http://requiremind.com/a-most-simple-php-mvc-beginners-tutorial/, however it throws an error:
Parse error: syntax error, unexpected '[' in /usr/home/domains/xyz.pl/public_html/my-soft/routes.php on line 20
on my hosting which has 5.2.17 PHP version.
I searched stackoverflow for a corresponding topic about 5.2 vs 5.4 array differences, but i coudldn't find anything meaningful so I can solve this particulat error (both tables are named), and final resolution should comply with this fact -> table names ('pages', 'posts') are used in conditional statement below the table intitialization.
Could you please advise me on how to solve this without changing the PHP version?
<?php
function call($controller, $action) {
require_once('controllers/' . $controller . '_controller.php');
switch($controller) {
case 'pages':
$controller = new PagesController();
break;
case 'posts':
// we need the model to query the database later in the controller
require_once('models/post.php');
$controller = new PostsController();
break;
}
$controller->{ $action }();
}
// we're adding an entry for the new controller and its actions
$controllers = array('pages' => ['home', 'error'],
'posts' => ['index', 'show']);
if (array_key_exists($controller, $controllers)) {
if (in_array($action, $controllers[$controller])) {
call($controller, $action);
} else {
call('pages', 'error');
}
} else {
call('pages', 'error');
}
?>