【发布时间】:2010-12-30 09:40:53
【问题描述】:
我是初学者 codeigniter。 我的目的是从 example_view.php 视图的表单中获取值,然后在我提交时在 result.php 视图中显示此结果。
- 我该如何解决这个问题?
- 如果我想将此值传递给会话,我该怎么做?
example_view.php(视图)
<html>
<head><title>Test Example View</title></head>
<body>
<h1 align="center">Test Sample CI Framwork</h1>
<?php echo form_open('example/getvalue'); ?>
<input type="text" name="username" value="" size="50" />
<div><input type="submit" value="Submit" name="submit"/></div>
<?php echo form_close(); ?>
</body>
</html>
result.php(查看)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php echo 'Your new value is '.$value;?>
</body>
</html>
example.php(控制器)
<?php
class Example extends Controller {
function Example()
{
parent::Controller();
$this->load->helper('form');
$this->load->helper('url');
}
function index() {
$this->load->view('example_view');
$this->getvalue();
}
function getvalue()
{
if ($this->input->post('submit')==true) {
$data['value']=$this->input->post('username');
$this->load->view('result',$data);
}
}
}
?>
感谢您的帮助。
【问题讨论】:
标签: codeigniter