За последние 24 часа нас посетили 22279 программистов и 1021 робот. Сейчас ищут 624 программиста ...

Помогите пожалуста необходимо написать пару строк кода

Тема в разделе "Сделайте за меня", создана пользователем Samir1204, 8 дек 2022.

  1. Samir1204

    Samir1204 Новичок

    С нами с:
    8 дек 2022
    Сообщения:
    5
    Симпатии:
    0
    Есть страница в админке
    Код (Text):
    1. <!-- Content Header (Page header) -->
    2. <section class="content-header">
    3.     <h1>
    4.         Список товаров
    5.     </h1>
    6.     <ol class="breadcrumb">
    7.         <li><a href="<?=ADMIN;?>"><i class="fa fa-dashboard"></i> Главная</a></li>
    8.         <li class="active">Список товаров</li>
    9.     </ol>
    10. </section>
    11.  
    12. <!-- Main content -->
    13. <section class="content">
    14.     <div class="row">
    15.         <div class="col-md-12">
    16.             <div class="box">
    17.                 <div class="box-body">
    18.                     <div class="text-center">
    19.                         <?php if($pagination->countPages > 1): ?>
    20.                         <?=$pagination;?>
    21.                         <?php endif; ?>
    22.                         <p>(<?=count($products);?> məhsul <?=$count;?>)</p>
    23.                     </div>
    24.                     <div class="table-responsive">
    25.                         <table class="table table-bordered table-hover">
    26.                             <thead>
    27.                             <tr>
    28.                                 <th><a href="<?=ADMIN;?>/product/id">ID</a><a href="<?=ADMIN;?>/product/idb">&nbsp; &nbsp;<i class="fa fa-fw fa-unsorted"></i></a></th>
    29.                                 <th><a href="<?=ADMIN;?>/product/cat">Категория</a></th>
    30.                                 <th><a href="<?=ADMIN;?>/product/index" class="active">Наименование</a></th>
    31.                                 <th><a href="<?=ADMIN;?>/product/market">Маркет</a></th>
    32.                                 <th><a href="<?=ADMIN;?>/product/aksiya">Срок Акции</a></th>
    33.                                 <th>Фото</th>
    34.                                 <th>Цена</th>
    35.                                 <th><a href="<?=ADMIN;?>/product/status">Статус</a></th>
    36.                                 <th>Действия</th>
    37.                             </tr>
    38.                             </thead>
    39.                             <tbody>
    40.                             <?php foreach($products as $product): ?>
    41.                                 <tr>
    42.                                     <td><?=$product['id'];?></td>
    43.                                     <td><?=$product['cat'];?></td>
    44.                                     <td><?=$product['title'];?></td>
    45.                                     <td><?=$product['description'];?></td>
    46.                                     <td><?=$product['keywords'];?></td>
    47.                                     <td><img class="img-responsive zoom-img" width="60px" src="/images/<?=$product['img'];?>"</td>
    48.                                     <td><?=$product['price'];?></td>
    49.                                     <td><?=$product['status'] ? 'On' : 'Off';?> &nbsp; &nbsp;<input type="checkbox" name="status"<?=$product['status'] ? ' checked' : null;?>></td>
    50.                                     <td><a href="<?=ADMIN;?>/product/edit?id=<?=$product['id'];?>" target="_blank"><i class="fa fa-fw fa-eye"></i></a> <a class="delete" href="<?=ADMIN;?>/product/delete?id=<?=$product['id'];?>"><i class="fa fa-fw fa-close text-danger"></i></a></td>
    51.                                 </tr>
    52.                             <?php endforeach; ?>
    53.                             </tbody>
    54.                         </table>
    55.                     </div>
    56.                     <div class="text-right">
    57.                         <form action="<?=ADMIN;?>/product/check?id=<?=$product['id'];?>" method="post">
    58.                         <button type="submit" class="btn btn-success">Сохранить</button>
    59.                     </div>
    60.                     <div class="text-center">
    61.                         <p>(<?=count($products);?> məhsul <?=$count;?>)</p>
    62.                         <?php if($pagination->countPages > 1): ?>
    63.                             <?=$pagination;?>
    64.                         <?php endif; ?>
    65.                     </div>
    66.                 </div>
    67.             </div>
    68.         </div>
    69.     </div>
    70.  
    71. </section>
    72. <!-- /.content -->
    выглядит так
    [​IMG]

    я добавил чекбоксы и кнопку сохранить
    А вот что написать в контроллере я не знаю

    Код контроллера

    Код (Text):
    1. <?php
    2.  
    3. namespace app\controllers\admin;
    4.  
    5. use app\models\admin\Product;
    6. use app\models\AppModel;
    7. use ishop\App;
    8. use ishop\libs\Pagination;
    9.  
    10. class ProductController extends AppController {
    11.  
    12.     public function indexAction(){
    13.         $page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
    14.         $perpage = 1000;
    15.         $count = \R::count('product');
    16.         $pagination = new Pagination($page, $perpage, $count);
    17.         $start = $pagination->getStart();
    18.         $products = \R::getAll("SELECT product.*, category.title AS cat FROM product JOIN category ON category.id = product.category_id ORDER BY product.title LIMIT $start, $perpage");
    19.         $this->setMeta('Список товаров');
    20.         $this->set(compact('products', 'pagination', 'count'));
    21.     }
    22.  
    23.     public function addImageAction(){
    24.         if(isset($_GET['upload'])){
    25.             if($_POST['name'] == 'single'){
    26.                 $wmax = App::$app->getProperty('img_width');
    27.                 $hmax = App::$app->getProperty('img_height');
    28.             }else{
    29.                 $wmax = App::$app->getProperty('gallery_width');
    30.                 $hmax = App::$app->getProperty('gallery_height');
    31.             }
    32.             $name = $_POST['name'];
    33.             $product = new Product();
    34.             $product->uploadImg($name, $wmax, $hmax);
    35.         }
    36.     }
    37.  
    38.     public function editAction(){
    39.         if(!empty($_POST)){
    40.             $id = $this->getRequestID(false);
    41.             $product = new Product();
    42.             $data = $_POST;
    43.             $product->load($data);
    44.             $product->attributes['status'] = $product->attributes['status'] ? '1' : '0';
    45.             $product->attributes['hit'] = $product->attributes['hit'] ? '1' : '0';
    46.             $product->getImg();
    47.             if(!$product->validate($data)){
    48.                 $product->getErrors();
    49.                 redirect();
    50.             }
    51.             if($product->update('product', $id)){
    52.                 $product->editFilter($id, $data);
    53.                 $product->editRelatedProduct($id, $data);
    54.                 $product->saveGallery($id);
    55.                 $alias = AppModel::createAlias('product', 'alias', $data['title'], $id);
    56.                 $product = \R::load('product', $id);
    57.                 $product->alias = $alias;
    58.                 \R::store($product);
    59.                 $_SESSION['success'] = 'Изменения сохранены';
    60.                 redirect();
    61.             }
    62.         }
    63.  
    64.         $id = $this->getRequestID();
    65.         $product = \R::load('product', $id);
    66.         App::$app->setProperty('parent_id', $product->category_id);
    67.         $filter = \R::getCol('SELECT attr_id FROM attribute_product WHERE product_id = ?', [$id]);
    68.         $related_product = \R::getAll("SELECT related_product.related_id, product.title FROM related_product JOIN product ON product.id = related_product.related_id WHERE related_product.product_id = ?", [$id]);
    69.         $gallery = \R::getCol('SELECT img FROM gallery WHERE product_id = ?', [$id]);
    70.         $this->setMeta("Редактирование товара {$product->title}");
    71.         $this->set(compact('product', 'filter', 'related_product', 'gallery'));
    72.     }
    73.  
    74.     public function addAction(){
    75.         if(!empty($_POST)){
    76.             $product = new Product();
    77.             $data = $_POST;
    78.             $product->load($data);
    79.             $product->attributes['status'] = $product->attributes['status'] ? '1' : '0';
    80.             $product->attributes['hit'] = $product->attributes['hit'] ? '1' : '0';
    81.             $product->getImg();
    82.  
    83.             if(!$product->validate($data)){
    84.                 $product->getErrors();
    85.                 $_SESSION['form_data'] = $data;
    86.                 redirect();
    87.             }
    88.  
    89.             if($id = $product->save('product')){
    90.                 $product->saveGallery($id);
    91.                 $alias = AppModel::createAlias('product', 'alias', $data['title'], $id);
    92.                 $p = \R::load('product', $id);
    93.                 $p->alias = $alias;
    94.                 \R::store($p);
    95.                 $product->editFilter($id, $data);
    96.                 $product->editRelatedProduct($id, $data);
    97.                 $_SESSION['success'] = 'Товар добавлен';
    98.             }
    99.             redirect();
    100.         }
    101.  
    102.         $this->setMeta('Новый товар');
    103.     }
    104.  
    105.         public function deleteAction(){
    106.             $id = $this->getRequestID();
    107.             $product = \R::load('product', $id);
    108.             \R::trash($product);
    109.             $_SESSION['success'] = 'Товар удален';
    110.             redirect();
    111.         }
    112.        
    113.     public function relatedProductAction(){
    114.         /*$data = [
    115.             'items' => [
    116.                 [
    117.                     'id' => 1,
    118.                     'text' => 'Товар 1',
    119.                 ],
    120.                 [
    121.                     'id' => 2,
    122.                     'text' => 'Товар 2',
    123.                 ],
    124.             ]
    125.         ];*/
    126.  
    127.         $q = isset($_GET['q']) ? $_GET['q'] : '';
    128.         $data['items'] = [];
    129.         $products = \R::getAssoc('SELECT id, title FROM product WHERE title LIKE ? LIMIT 10', ["%{$q}%"]);
    130.         if($products){
    131.             $i = 0;
    132.             foreach($products as $id => $title){
    133.                 $data['items'][$i]['id'] = $id;
    134.                 $data['items'][$i]['text'] = $title;
    135.                 $i++;
    136.             }
    137.         }
    138.         echo json_encode($data);
    139.         die;
    140.     }
    141.  
    142.     public function deleteGalleryAction(){
    143.         $id = isset($_POST['id']) ? $_POST['id'] : null;
    144.         $src = isset($_POST['src']) ? $_POST['src'] : null;
    145.         if(!$id || !$src){
    146.             return;
    147.         }
    148.         if(\R::exec("DELETE FROM gallery WHERE product_id = ? AND img = ?", [$id, $src])){
    149.             @unlink(WWW . "/images/$src");
    150.             exit('1');
    151.         }
    152.         return;
    153.     }
    154.    
    155.  
    156. }