如何在codeigniter中使用跳转到当前页面的特定div
如何将其转换为codeigniter 我调用链接的php代码如下如何在codeigniter中使用跳转到当前页面的特定div,codeigniter,Codeigniter,如何将其转换为codeigniter 我调用链接的php代码如下 <ul> <li><a href="index.php?option=register">Register Here</a> <li><a href="index.php?option=login">Login</a> </ul> 当我调用此链接时,将调用此特定链接 <?php @$opt = $_GET['opti
<ul>
<li><a href="index.php?option=register">Register Here</a>
<li><a href="index.php?option=login">Login</a>
</ul>
-
-
当我调用此链接时,将调用此特定链接
<?php
@$opt = $_GET['option'];
if($opt=="") {
include('register.php');
error_reporting(1);
} else {
switch($opt) {
case 'register':
include('register.php');
break;
case 'login':
include('login.php');
break;
}
}
尝试使用诸如Welcome.php之类的控制器
<?php
class Welcome extends CI_Controller {
public function index() {
// Load other data stuff.
// You should autoload the url helper.
$this->load->helper('url');
$opt = $this->input->get('option');
if($opt == "") {
$data['title'] = 'Register';
$this->load->view('header', $data);
$this->load->view('register');
$this->load->view('footer');
error_reporting(1);
} else {
switch($opt) {
case 'register':
$data['title'] = 'Register';
$this->load->view('header', $data);
$this->load->view('register');
$this->load->view('footer');
break;
case 'login':
$data['title'] = 'Login';
$this->load->view('header', $data);
$this->load->view('login');
$this->load->view('footer');
break;
}
}
}
URI
对此
$config['uri_protocol'] = 'QUERY_STRING';
然后您可以启用
$config['enable_query_strings'] = TRUE;
并使用内置的codeigniter查询字符串
然后你会使用这样的链接
<li><?php echo anchor('c=welcome&option=register', 'Register');?></li>
字母c表示codeigniter查询字符串中的控制器,但您可以在config.php中更改它
<?php
class Welcome extends CI_Controller {
public function index() {
// Load other data stuff.
// You should autoload the url helper.
$this->load->helper('url');
$opt = $this->input->get('option');
if($opt == "") {
$data['title'] = 'Register';
$this->load->view('header', $data);
$this->load->view('register');
$this->load->view('footer');
error_reporting(1);
} else {
switch($opt) {
case 'register':
$data['title'] = 'Register';
$this->load->view('header', $data);
$this->load->view('register');
$this->load->view('footer');
break;
case 'login':
$data['title'] = 'Login';
$this->load->view('header', $data);
$this->load->view('login');
$this->load->view('footer');
break;
}
}
}
URI
对此
$config['uri_protocol'] = 'QUERY_STRING';
然后您可以启用
$config['enable_query_strings'] = TRUE;
并使用内置的codeigniter查询字符串
然后你会使用这样的链接
<li><?php echo anchor('c=welcome&option=register', 'Register');?></li>
字母c表示codeigniter查询字符串中的控制器,但您可以在config.php中更改它我的建议请学习如何在codeigniter中加载视图文件我知道如何加载视图而不是包含我使用的“$this->load->view('login');”但只有默认页面打开。下一个代码不起作用注意:下一次请在接受答案之前进行检查,因为@Anvar Pk看起来像是复制了我的代码。我是第一个给出答案的人。对不起,先生,我弄错了。下一次我会检查的。我建议请学习如何在代码中加载视图文件。我知道如何加载视图,而不是包括我使用的“$this->load->view('login');”但只有默认页面打开。下一个代码不起作用注意:下一次请在接受答案之前进行检查,因为@Anvar Pk看起来像是复制了我的代码。我是第一个给出答案的人。对不起,先生,我弄错了。我下次再查,谢谢你response@RemyaR$config['allowed_uri_chars']
如果(比如说)重复性没有得到很好的考虑,则不应更改。查询字符串将起作用,或者保留默认值。阅读URI中的字符。由于仍然有不好的建议,我投了d票。这是一种不好的做法,尤其是没有提供给CI的新手。我试图通过编辑来修复它,但人们并不认为安全问题不重要。在他(或你)的价值观中,系统安全应该是最重要的(尤其是在降低安全级别没有任何好处的情况下)。类似的事情我已经解释过试图编辑答案。另外,我很好奇为什么它被认为是一个好主意,尽管没有任何默认值,也可以应用更改查询字符串。@Tpojka我现在修改了答案谢谢您的帮助response@RemyaR$config['allowed_uri_chars']
如果(比如说)重复性没有得到很好的考虑,则不应更改。查询字符串将起作用,或者保留默认值。阅读URI中的字符。由于仍然有不好的建议,我投了d票。这是一种不好的做法,尤其是没有提供给CI的新手。我试图通过编辑来修复它,但人们并不认为安全问题不重要。在他(或你)的价值观中,系统安全应该是最重要的(尤其是在降低安全级别没有任何好处的情况下)。类似的事情我已经解释过试图编辑答案。另外,我很好奇为什么它被认为是一个好主意,尽管没有任何默认值,也可以应用更改查询字符串。@Tpojka我现在修改了答案