【问题标题】:Codeigniter: Store and Load Style in PHPCodeigniter:在 PHP 中存储和加载样式
【发布时间】:2014-12-31 07:16:44
【问题描述】:

所以,我只是在玩 Codeigniter。

我制作了 5 个正方形,静态的。 我已经宣布了这 5 个方位。 但是当我删除其中一个方块时(例如:Square 1/#draggable1),另一个方块正在排序。

这是条件:

我有 5 个正方形/5 个#draggable

Sq1 Sq2 Sq3 Sq4 Sq5

当我删除 Sq2 时,会发生以下情况:

Sq1 Sq3 Sq4 Sq5

然后我删除 Sq4,结果是这样的:

Sq1 Sq3 Sq5 当我删除其中一个时,所有正方形都被排序。我想要做的就是当我删除其中一个方块时,另一个方块不需要排序。只是他们。像这样:

Sq1 Sq2 Sq3 Sq4 Sq5

当我删除 Sq2 时,应该是这样的:

Sq1 ___ Sq3 Sq4 Sq5 *无 Sq2 且 Sq1 和 Sq3 之间有空格

这是我的视图

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
    <link rel="stylesheet" href="<?php echo base_url("style/css/bootstrap.min.css"); ?>">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

    <style type='text/css'>
        body {
            font-family: Arial;
            font-size: 14px;
        }
        a {
            color: blue;
            text-decoration: none;
            font-size: 14px;
        }
        a:hover {
            text-decoration: underline;
        }
    </style>


    <style>
        #draggable1 { width: 90px; height: 90px; left:56px; top:35px; opacity:0; }
        #draggable2 { width: 90px; height: 90px; left:170px; top:-55px; opacity:0; }
        #draggable3 { width: 90px; height: 90px; left:285px; top:-145px; opacity:0; }
        #draggable4 { width: 90px; height: 90px; left:398px; top:-235px; opacity:0; }
        #draggable5 { width: 90px; height: 90px; left:512px; top:-325px; opacity:0; }
    </style>

    <script>
        $(function() {
            $( "#draggable1" ).draggable().delay(100).animate({"opacity": "1"}, 700);
            $( "#draggable2" ).draggable().delay(200).animate({"opacity": "1"}, 700);
            $( "#draggable3" ).draggable().delay(300).animate({"opacity": "1"}, 700);
            $( "#draggable4" ).draggable().delay(400).animate({"opacity": "1"}, 700);
            $( "#draggable5" ).draggable().delay(500).animate({"opacity": "1"}, 700);
        });
    </script>
</head>

<body>
    <?php
         if(is_array($databuku)){

             echo '<ol><br>';
             $i = 1;
             foreach($databuku as $key){
                 $judul = '<div id="draggable'.$i++.'" class="ui-widget-content"><center><strong>'.$key->tbl_name.'</strong>
                                 <br> <br>
                                 <a href="hall_a.html">' .$key->index_no. ' / ' .$key->id. '</a>
                                 <br>

                                 '.anchor('perpustakaan/koreksi_buku/'.$key->id, 'Edit').' |
                                 '.anchor('perpustakaan/konfirm_hapus_buku/'.$key->id, 'Delete').'

                                 </center></div>';
                     echo $judul;
                }
                echo '</ol>';
            }

        ?>

    </body>
</html>

现在我认为最简单的方法是在数据库中存储和加载 CSS 中的左侧和顶部位置。 问题是: 如何将样式 CSS 中的 lefttop 存储到/从数据库中加载? 例如: 我有 left:512px; 顶部:-325px;在我的表数据库中, 如何在我的正文代码中加载这些左侧和顶部的数量?

【问题讨论】:

    标签: php html css codeigniter


    【解决方案1】:

    我不知道您为什么要从数据库中读取样式,但方法如下:

    您应该首先看到CodeIngiter Documentation

    您创建一个加载数据的模型(例如:my_model.php):

    public function getSize(){
    
      //get the style from the DB
      $this->db->where('style', '10');
    
      return $this->db->get('my_table')->row();
    
    }
    

    您将模型加载到控制器中:

    public function controllerOne(){
    
      //get the model loaded
      $this->load->model('my_model');
    
      //Set your data from the model
      $data = array(
    
        'mySize' => $this->my_model->getSize();
    
      );
    
      //Load the view with the data
      $this->load->view('my_view', $data);
    
    }
    

    您现在可以在视图中看到一个名为mySize的变量:

    print_r($mySize);
    

    请注意,我会使用更快更快速的方式来加载动态尺寸,即进入application &gt; config &gt; config.php 并添加新的配置选项:

    $config['size_left'] = "321px";
    $config['size_right'] = "134px";
    

    然后在控制器或视图中读取它们:

    $this->config->item('size_left');
    

    【讨论】:

    • 嗨,如果我想在 config.php 中添加关于不透明度的新配置怎么办?我对这段代码是否正确? $config['不透明度'] = "0";然后我以这种方式在控制器中读取它 $this->config->item('opacity');
    • @yogieputra 是的,当然。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-26
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    • 2015-02-20
    相关资源
    最近更新 更多