Codeigniter PHP - 在锚点加载视图 [英] Codeigniter PHP - loading a view at an anchor point

查看:164
本文介绍了Codeigniter PHP - 在锚点加载视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在长页面底部有一个表单,如果用户填写表单,但不能验证该网页是否按照典型的codeigniter方式重新加载:



$ this-> load-> view('template',$ data);



但是因为表单是在页面的底部,我需要的页面加载下来像你做的HTML锚点。有谁知道如何在codeigniter这样做?



我无法使用codeigniter



redirect();



函数,因为它丢失了对象,验证错误消失了。其他框架我使用像Yii你可以调用重定向函数像:



$ this-> redirect();



这解决了问题,因为你保留了对象。我已尝试使用:



$ this-> index()



在控制器中工作正常作为重定向,但验证错误是在另一种方法,其中当前页面加载从:



$ this-> item($ labs)



但是当我使用它会陷入循环

任何想法?我已经看到这个问题很多在网上,但没有明确的答案。我正在研究使用codeigniter的闪存数据,但认为这有点过分。



干杯。

我不能亲自证明这一点,但根据这个线程,如果你将锚点附加到窗体的 action ,它会工作。



CodeIgniter helper:

 <?php echo form_open('controller / function#anchor'); > 

或香草HTML:

 < form method ='post'action ='controller / function#anchor' 

如果你开放使用Javascript,你可以很容易地检测到 $ validation_failed 变量并适当滚动。



另一种选择是将表单放在页面顶部附近?


I have a form at the bottom of a long page, if a user fills out the form but it doesn't validate the page is reloaded in the typical codeigniter fashion:

$this->load->view('template',$data);

however because the form is way down at the bottom of the page I need the page to load down there like you do with HTML anchors. Does anyone know how to do this in codeigniter?

I can't use the codeigniter

redirect();

function because it loses the object and the validation errors are gone. Other frameworks I've used like Yii you can call the redirect function like:

$this->redirect();

which solves the problem because you keep the object. I've tried using:

$this->index()

within the controller which works fine as a redirect but the validation errors are in another method which is where the current page is loaded from:

$this->item($labs)

but when I use this it get stuck in a loop

Any ideas? I've seen this question a lot on the net but no clear answers. I'm researching using codeigniter "flash data" but think it's a bit overkill.

cheers.

解决方案

I can't personally vouch for this, but according to this thread if you append the anchor to the form's action, it will work.

CodeIgniter helper:

<?php echo form_open('controller/function#anchor'); ?>

Or vanilla HTML:

<form method='post' action='controller/function#anchor'>

If you were open to using Javascript, you could easily detect a $validation_failed variable and appropriately scroll. Or, even better, use AJAX.

Another option is to put the form near the top of the page?

这篇关于Codeigniter PHP - 在锚点加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆