[英]Load a page plus changing the URL
I've noticed that when $this->load->view('page.php)'
is used, the URL in the browser does not change, ie. 我注意到,当使用$this->load->view('page.php)'
,浏览器中的URL不会更改,即。 if we came from ../step_1.php
and loaded to ../step_2.php
, the url will still be ../step_1.php
. 如果我们来自../step_1.php
并加载到../step_2.php
,则网址仍将是../step_1.php
。
I am making a multi-step form wherein all steps are handled by one controller and I've learned that the best way to handle such situations is using load
. 我正在制作一个多步骤表单,其中所有步骤都由一个控制器处理,并且我了解到处理此类情况的最佳方法是使用load
。 The problem is that I do not want the past page's URL to be shown but the new page's. 问题是我不希望显示过去页面的URL,而希望显示新页面的URL。 I know redirect('page_controller')
can achieve this but it would be unpractical (redirecting within the controller). 我知道redirect('page_controller')
可以做到这一点,但这是不切实际的(在控制器内重定向)。
Does anyone have an idea why this happens? 有谁知道为什么会这样?
EDIT: 编辑:
I found an explanation regarding CI's view and redirect from this link . 我找到了关于CI视图的解释,并从此链接重定向。
views -> shows a page in the previous page's URL views->在前一页的URL中显示一个页面
redirect -> shows a page in its own URL 重定向->以其自己的URL显示页面
function step_1()
{
load_page($step_1);
}
Instead of calling load_page from your view build your pages out in the controller as above, then call the appropriate page. 与其从视图中调用load_page,不如上面那样在控制器中构建页面,然后调用适当的页面。 CI uses the controller method as the URL. CI使用控制器方法作为URL。 To my knowledge there is no way to change this behaviour. 据我所知,没有办法改变这种行为。
class test{
{
public function view()
{
switch($this->uri->segment(2))
{
case $this->uri->segment(2) == 'part1':
$this->load->view('part1');
break;
case $this->uri->segment(2) == 'part2':
$this->load->view('part2');
break;
}
}
}
OR 要么
class test{
{
public function view($page)
{
switch($page)
{
case $page == 'part1':
$this->load->view('part1');
break;
case $page == 'part2':
$this->load->view('part2');
break;
}
}
}
test/view/part1
will go to view part1
test/view/part2
will go to view part2
you could try something like this, this is not tested tell me if there are errors 你可以尝试这样的事情, 这是未经测试的告诉我是否有错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.