Codeigniter:PHP中的存储和加载样式

时间:2014-12-31 07:16:44

标签: php html css codeigniter

所以,我只是在玩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 * no 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样式数据库中存储和加载顶部? 例如: 我有:512px;的: - 325px;在我的表数据库中, 如何在我的身体代码中加载左边和上边的数量?

1 个答案:

答案 0 :(得分:0)

我不知道你为什么要从数据库中读取样式,但这是如何:

您应首先看到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 > config > config.php并添加新的配置选项:

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

然后在控制器中查看它们或通过以下方式查看:

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