2016-10-11 8 views
0

私はcodeigniter 3.1を使用しています。別の機能から投稿された価値を取得するには?

別の機能からデータを送信した後に投稿したメールを返却または取得する方法は?

HTML

<form action="settings/valid" class="form-horizontal" enctype="multipart/form-data" method="post" accept-charset="utf-8"> 
    <input type="email" name="email" value="<?php echo $email ?>" /> 
    <input type="submit"/> 
</form> 

PHPルーティングと呼ばれる何がやっている

public function index() { 
    // how to get post email ? 
    $email = $this->input->post("email")); 

    $this->template->loadContent("settings/index.php", array(
    "email" => $email 
    ) 
    ); 

} 

public function valid() { 
    $email = $this->input->post("email")); 

    $this->user->add($this->user->ID, array(
     "email" => $email 
    )); 

    redirect(site_url("index.php")); 

} 
+0

まず、基本を学ぶ必要があります。チュートリアルを実行すると、このすべてがはるかに明確になります - http://www.codeigniter.com/user_guide/tutorial/index.html – cartalot

答えて

1

にこれは、より良いあなたの質問に答えることがあります。

public function index() { 
    // how to get post email ? 
    $email = $this->session->flashdata("email"); 

    $this->template->loadContent("settings/index.php", array(
    "email" => $email 
    ) 
    ); 

} 

public function valid() { 
    $email = $this->input->post("email")); 

    $this->user->add($this->user->ID, array(
     "email" => $email 
    )); 

    $this->session->set_flashdata("email",$email); 

    redirect(site_url("index.php")); 

} 
+0

を追加しました。ありがとうございました:) – Mehur

+1

よろしくお願いします! –

+0

ありがとうございます。これに答えることはできますかhttp://stackoverflow.com/questions/40238671/ajax-upload-not-working-codeigniter? – Mehur

1

。つまり、索引にデータが送信されていないため、電子メールを索引に入れるのは意味がありません。あなたができることは、ユーザーをインデックスにリダイレクトして、post引数をindexに渡すことです。

別の言い方をすると。ウェブページを開いて名前を付けたとします。他のページもあなたの名前を知っていると期待することはできません。なぜなら、そのページはまだ存在しないからです(まだPHPによって生成されていない)。

しかし、あなたは別のページにユーザーを送り、そのページにユーザーの名前を伝えることができます。例えば

、あなたのケースで:valid()

redirect(site_url("index.php?email=".$email)); 

index()

$email = $this->input->get("email") 
+0

私は試しましたが、うまくいきませんでした。 – Mehur

+0

インデックスはいつ呼び出されますか? –

+0

'http:// localhost/settings/index'と投稿URLは' http:// localhost/settings/valid'です。投稿後にインデックスに戻る。 – Mehur

関連する問題