<?php class Form extends CI_Controller{ function index(){ if($this->input->post('product') != null){ $str='<p>送信内容:'.$this->input->post('product').'</p>'; } else{ $str='<p>メッセージをどうぞ</p>'; } $data=array('msg'=>$str); $this->load->view('form_post',$data); } } ?>
<?=$msg;?>の部分を <?=$data;?>に変えると<html> <head> <title>formsend</title> </head> <body> <form action="http://localhost/ci/index.php/form" method="post"> <input type="text" name="product"/> <input type="submit" value="送信"/> </form> <p><?=$msg;?></p> </body> </html>
undefined variable:dataとエラーが出ます。
これは関数外の変数を呼んだからかなと思うのですが、
なぜ&msgではうまくいくのでしょうか。
回答3件
あなたの回答
tips
プレビュー