public function evolve($id) { if ($this->isLogged()) { RouteService::redirect('users', 'buildings', true); } if (isset($id)) { try { $buildingModel = new Building(); if ($buildingModel->evolve($id)) { RouteService::redirect('users', 'buildings', true); } else { RouteService::redirect('users', 'buildings', true); } } catch (\Exception $e) { //return $e->getMessage(); RouteService::redirect('users', 'buildings', true); } } else { RouteService::redirect('users', 'buildings', true); } }
public function buildings() { if (!$this->isLogged()) { RouteService::redirect('users', 'login', true); } $viewModel = new BuildingsInformation(); $userModel = new User(); $buildings = $userModel->getBuildings(); $userInfo = $userModel->getInfo(Session::get('id')); $viewModel->user = new UserInformation($userInfo['username'], $userInfo['id'], $userInfo['gold'], $userInfo['food']); $viewModel->buildings = $buildings; return new View($viewModel); }
<?php require_once 'Autoloader.php'; \SoftUni\Autoloader::register(); \SoftUni\Helpers\Session::start(); $phpSelf = $_SERVER['PHP_SELF']; $index = basename($phpSelf); \SoftUni\Helpers\RouteService::init(str_replace($index, '', $phpSelf)); $requestParams = []; $controller = "users"; $action = "login"; if (isset($_GET['uri'])) { $requestParams = explode('/', $_GET['uri']); $controller = ucfirst(array_shift($requestParams)); $action = ucfirst(array_shift($requestParams)); } \SoftUni\Core\Database::setInstance(\SoftUni\Config\DatabaseConfig::DB_INSTANCE, \SoftUni\Config\DatabaseConfig::DB_DRIVER, \SoftUni\Config\DatabaseConfig::DB_USER, \SoftUni\Config\DatabaseConfig::DB_PASSWORD, \SoftUni\Config\DatabaseConfig::DB_NAME, \SoftUni\Config\DatabaseConfig::DB_HOST); $app = new \SoftUni\Application($controller, $action, $requestParams); $app->start();
<td>Gold</td> <td>Food</td> </tr> <?php foreach ($model->buildings as $building) { ?> <tr> <td><?php echo $building['name']; ?> </td> <td><?php echo $building['level']; ?> </td> <td><?php echo $building['gold']; ?> </td> <td><?php echo $building['food']; ?> </td> <td><a href="<? \SoftUni\Helpers\RouteService::getUri('buildings', 'evolve', [$building['id']]); ?>">Evolve</a></td> </tr> <?php } ?> </table>