【问题标题】:To redirect the url重定向网址
【发布时间】:2013-09-17 08:03:19
【问题描述】:

在下面的代码中,我在搜索之前搜索数据,我的 url 将在 coursemaster_site 中,当我搜索时,它将在 coursemaster_site/index1 中,当我关闭搜索结果时,url 将在 coursemaster_site /coursemaster_site 但我想要 url关闭搜索结果后进入 coursemaster_site。

控制器:coursemaster_site

function index1()
    {
        $data            = array();
        $keyword         = $this->input->post('keyword');
        if($keyword!=""){
            $data['results'] = $this->coursemaster_model->search($keyword);
        }
        $this->load->view('coursemaster_view', $data);

    }

view:coursemaster_view

<form action="<?php echo site_url('coursemaster_site/index1');?>" method = "post">
<br/><center>SEARCH:<input type="text" name = "keyword" required/>
<input type="submit" name="submit" id="opn" value = "Search"  onClick="hide1('hiddendiv')"  class="btn-success btn" /></center>
</form>

<?php
if (isset($_POST['submit'])) { // Here
  // Do the search here
        if($results){
         ?> <div id='hideme'>
         CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>
        <img  src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close"    onClick="hide('hideme')"/>
        </a><div style="background:#FFFFFF; width:1000px; height: 540px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -120px" id="modal"  >
       <table class="display2 table table-bordered table-striped" id='results'>
       <tr>
            <th>course_code</th>
            <th>course name</th>
       </tr>
       <tr><?php
             foreach ($results as $row) {
      ?>
       <td><?php echo $row->course_code;?></td>
       <td><?php echo $row->course_name;?></td>
       </tr>
            <?php
            } 
        }else{
        echo"<div id='hideme'>
         CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>";
        echo "<div id='modal' style='background:#FFFFFF; width:1000px; height: 525px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -110px'>";
        }
  echo"no results";
  echo'</div>';
echo '</div>';        }
 // If closing
?>
</table>
</div></div>
<script>
$('a.modal').bind('click', function(event) { 
        event.preventDefault();
        $('#modal').fadeIn(10);

    });
    function hide(obj) {
        var el = document.getElementById(obj);
        el.style.display = 'none';
    }
    function hide1(obj) {
        var el = document.getElementById(obj);
        el.style.display = 'none';
    }
    </script>

【问题讨论】:

  • 您能详细说明一下吗?我没听懂。
  • 何时搜索以及何时关闭。我没听懂。
  • 当我关闭搜索结果时,我的网址是 coursemaster_site/coursemaster_site。
  • 我认为我的问题出在此处,因为当我关闭搜索结果时回显"
  • 试试&lt;a href='/coursemaster_site'(注意斜线)

标签: php html forms codeigniter


【解决方案1】:

改为:

<div id='hideme'>CLOSE
 <a href='/coursemaster_site' class='close_notification' title='Click to Close'> 
...

在这两个地方。前导斜杠使 href 从根目录开始。

【讨论】:

【解决方案2】:

进行以下更改并检查它是否有效:

<div id='hideme'>
     CLOSE<a href='javascript:void(0);' class='close_notification' title='Click to Close'>";

【讨论】:

  • 输入href='javascript:void(0);' 不会重定向。将href='javascript:void(0);' 放入两个链接,然后检查一次。或者只是给这个href='&lt;?=base_url('coursemaster_site')?&gt;' 并检查,这将重定向到控制器的索引函数。
猜你喜欢
相关资源
最近更新 更多
热门标签