php - Codeigniter:在 PHP 中存储和加载样式

标签 php html css codeigniter

所以,我只是在玩弄 Codeigniter。

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

This is the condition:

I Have 5 Square/ 5 #draggable

Sq1 Sq2 Sq3 Sq4 Sq5

When I delete Sq2, this is what happen:

Sq1 Sq3 Sq4 Sq5

Then I delete Sq4, this is what happen:

Sq1 Sq3 Sq5 All the square being sorted when I delete one of them. All I want to do is when I delete one of those square, the other square doesn't need to sorted. Just the they were. Like this:

Sq1 Sq2 Sq3 Sq4 Sq5

When I delete Sq2, it should be like this:

Sq1 ___ Sq3 Sq4 Sq5 *no Sq2 and there is space between Sq1 and Sq3

这是我的 View :

<!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 存储到数据库或从数据库加载? 例如: 我离开:512px; 顶部:-325px;在我的表数据库中, 如何在我的 body 代码中加载这些左和上的数量?

最佳答案

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

您应该看到 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();

}

将模型加载到 Controller 中:

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);

}

您现在将在您的 View 中有一个名为 mySize 的变量,您可以阅读它:

print_r($mySize);

请注意,我会使用一种更快的方法来加载动态大小,即进入 application > config > config.php 并添加新的配置选项:

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

然后在 Controller 中读取它们或通过以下方式查看:

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

关于php - Codeigniter:在 PHP 中存储和加载样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27717627/

相关文章:

javascript - 使用 Javascript 单击 div 时向标题添加样式

javascript - 双击使表格单元格可编辑-Angularjs

css - 奇怪的谷歌浏览器 float 错误 - 在其他浏览器中正常

jquery - 如何添加jquery进度条的颜色变化

PHP MYSQL 连接错误

javascript - 在 JavaScript 中将 .PNG 图像拖放到另一个图像之上

java - 使用 Java 应用程序连接到 PHP 脚本时出现问题

html - 让 <li> 元素并排在页面底部

php - 按天生成结果

php - 自动执行PHP脚本