我想在codeigniter中做一些api工作,我是codeIgniter的初学者,我开始研究codeigniter.know我想知道从中获取值

时间:2014-10-25 11:26:36

标签: codeigniter

我想在codeigniter中做一些api工作,我是codeIgniter的初学者,我开始学习codeigniter。知道我想知道如何发送值来查看。

在View文件夹中,我写的是这样的:

<h1 align="center">Test Sample CI Framwork</h1>
<form name="f1" action="" method="post"/>
<input type="text" name="firstname" value="" size="100" />
<input type="text" name="lastname" value=""  size="100"/>
<div><input type="submit" value="Submit" name="submit"/></div>
</form>
<h1>The values from form:<?php echo $result; ?></h1>

IN控制器:

<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class add extends CI_Controller 
{
    public function index()
    {
        $this->load->view('add');
        $this->getvalue();
    }

    function getvalue()
 {
 if ($this->input->post('submit'))
 {

  $data=$this->input->post('firstname');
  $data=$this->input->post('lastname');
 //help me what i have to do here.
 }
    }
}
?>

1 个答案:

答案 0 :(得分:-1)

是的,基本上是为了向视图传输数据,请使用:

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

你的控制器应该是这样的:

class add extends CI_Controller {

    public function index() {
        $data = array();

        if ($this->input->post()) {
            $data['firstname'] = $this->input->post('firstname');
            $data['lastname'] = $this->input->post('lastname');
        }

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

}


////add.php////
<h1 align = "center">Test Sample CI Framwork</h1>
    <form name = "f1" action = "" method = "post"/>
        <input type = "text" name = "firstname" value = "" size = "100" />
        <input type = "text" name = "lastname" value = "" size = "100"/>
        <div>
             <input type = "submit" value = "Submit" name = "submit"/>
        </div>
    </form>

<h1>The values from form:<?=$firstname . '-' . $lastname?></h1>