Example #1
0
})->bind('b_catalog');
$silex_app->get('/catalog/{page}', function ($page) use($silex_app, $products, $categories, $images) {
    //пагинация
    $pagination = new Pagination($products, 9, $page);
    $products_on_page = $pagination->getProductsOnPage();
    $pages_info = $pagination->getPagesInfo();
    return $silex_app['twig']->render('catalog/main.twig', ['twig_products' => $products_on_page, 'twig_categories' => $categories, 'twig_images' => $images, 'twig_pages_info' => $pages_info]);
});
$silex_app->get('/catalog/category/{cat_slug}/{page}', function ($cat_slug, $page) use($silex_app, $categories, $images) {
    $sql = "SELECT `id` FROM `categories` WHERE `slug` = :cat_slug";
    $cat_id = $silex_app['db']->fetchAssoc($sql, ['cat_slug' => $cat_slug])['id'];
    $sql = "SELECT * FROM `products` WHERE `category_id` = :cat_id";
    $products = $silex_app['db']->fetchAll($sql, ['cat_id' => $cat_id]);
    //пагинация
    $pagination = new Pagination($products, 9, $page, $cat_id);
    $products_on_page = $pagination->getProductsOnPage();
    $pages_info = $pagination->getPagesInfo();
    return $silex_app['twig']->render('catalog/category.twig', ['twig_products' => $products_on_page, 'twig_categories' => $categories, 'twig_images' => $images, 'twig_pages_info' => $pages_info]);
})->bind('b_category');
$silex_app->get('/catalog/product/{product_id}', function ($product_id) use($silex_app, $categories, $images) {
    $sql = "SELECT * FROM `products` WHERE `id` = :product_id";
    $product = $silex_app['db']->fetchAssoc($sql, ['product_id' => $product_id]);
    $sql = "SELECT * FROM `images` WHERE `product_id` = :product_id";
    $product_images = $silex_app['db']->fetchAll($sql, ['product_id' => $product_id]);
    return $silex_app['twig']->render('product/main.twig', ['twig_product' => $product, 'twig_product_images' => $product_images, 'twig_categories' => $categories]);
})->bind('b_product');
//админочка
//авторизация
$silex_app->get('/admin', function () use($silex_app) {
    $login = $silex_app['request']->server->get('PHP_AUTH_USER', false);
    $password = $silex_app['request']->server->get('PHP_AUTH_PW');