【问题标题】:JQuery Noty with Codeigniter带有 Codeigniter 的 JQuery Noty
【发布时间】:2020-02-28 10:03:33
【问题描述】:

我正在尝试在我的 CodeIgniter 项目中使用 JQuery、Noty 获取通知。

我使用了以下脚本代码

<script type="text/javascript">
$(document).ready(function() { 
<?php
 if (!empty($noti)) {
    foreach ($noti as $ns) {
        $date = new DateTime($ns->increment_date);

    }
 }

?>
noty({text: 'The Increment Date of', layout: 'center', closeWith: ['click', 'hover'], type: 'success'});
     });

</script>

型号

<?php

class Welcome_Model extends CI_Model {

    function __construct() {

        parent::__construct();
    }


    function increment_date(){

        $this->db->select('title, initials, last_name, increment_date');
        $this->db->from('tbl_officer');
        $this->db->where('tbl_officer.status=1 and  str_to_date(concat(increment_date,'-',year(curdate())),"%d-%b-%Y")
           between curdate() and curdate() + interval 30 day');
        $query=  $this->db->get();

        if($query->num_rows()>0){
            return $query->result();
        }
    }    

}

代码运行良好,并发出通知“增量日期”。但我想在本文末尾排除$ns-&gt;increment_date 的值。当我在文本中将$ns-&gt;increment_date 添加为'The Increment Date of &lt;?=$ns-&gt;increment_date?&gt;' 时,通知不起作用。

可能出了什么问题?任何人都可以帮忙吗?

【问题讨论】:

  • php 块移到 JS 块之前。
  • @ascsoftw。但是没用
  • 检查控制台查看错误。检查视图源的外观。
  • @ascsoftw。如果我使用 'The Increment Date of increment_date ?>',代码会输出 increment_date 的增量日期?>
  • 请看下面的答案。

标签: jquery mysql codeigniter


【解决方案1】:

请重新格式化如下代码:

<?php
    $date = ''; //Define an empty value
    if (!empty($noti)) {
        foreach ($noti as $ns) {
            $date = new DateTime($ns->increment_date);
        }
    }

?>


<script type="text/javascript">
$(document).ready(function() { 

var date = '<?php echo $date; ?>';//Pass the value from PHP to JS and pass below.

noty({text: 'The Increment Date of ' + date , layout: 'center', closeWith: ['click', 'hover'], type: 'success'});
     });

</script>

【讨论】:

  • 但是 increment_date 没有年份。例如:- 11 月 10 日、11 月 20 日
  • 请指定$ns-&gt;increment_date的格式和你想要的输出。
  • 我的意思是这个变量的实际值是什么,你希望它如何显示。
  • @ascsoftw。这个变量的实际值为 11 月 10 日、11 月 20 日,我想显示“11 月 10 日的增量日期”和“11 月 20 日的增量日期”等...
  • @mcode 那么这应该可以工作。请检查控制台是否有任何错误,并检查视图源的外观。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-23
  • 2011-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多