简体   繁体   English

在Codeigniter中将数据从视图传递到控制器

[英]Issue passing data from view to controller in codeigniter

I am using the CodeIgniter framework to build a site. 我正在使用CodeIgniter框架来构建网站。

I currently have a view which prints all the unverified members into a table and also puts a button for each member which can be clicked to Verify that account. 我目前有一个视图,该视图将所有未验证的成员打印到表中,并且还为每个成员放置一个按钮,可以单击该按钮以验证该帐户。

Here is the code for the view 这是视图的代码

<h2>Admin Control Panel</h2>
<?php
/*
 * First Output Members to be verified in tables
 */

//check if there is actually any data to print first.
    echo ("<h3> Members to be Verified</h3>");
    if(empty($unverified_members))
    {
        echo "<h4>There are currently no members to be verified </h4>";

    }
    else
    {
    $count_unverified_members=count($unverified_members);

    echo "<table border='1'>";

    //print table headers
    echo <<<HTML
    <th><div align ="center">ID Number</div></th>
    <th><div align ="center">Username</div></th>
    <th><div align ="center">E-Mail Address</div></th>
    <th><div align ="center">Verify Account</div></th>
HTML;

    for($arr_counter=0;$arr_counter<$count_unverified_members;$arr_counter++)
        {
            $current_member_id=$unverified_members[$arr_counter]->member_id;
            $current_username=$unverified_members[$arr_counter]->username;
            $current_email=$unverified_members[$arr_counter]->email;

            //now print values
            echo<<< HTML
            <tr>
            <td><div align ="center">$current_member_id</div></td>
            <td><div align ="center">$current_username</div></td>
            <td><div align ="center">$current_email</div></td>
            <td><form action="Verify" method="post"><div align ="center"><input type="submit" value="Verify" /></div></form></td>
            </tr>

HTML;
        }
    echo "</table><br><br>";

    }
?>

I am trying to pass to my controller the user to be verified. 我正在尝试将要验证的用户传递给我的控制器。

In the second heredoc I have this bit of code 在第二个heredoc中,我有这段代码

<td><form action="Verify" method="post"><div align ="center"><input type="submit" value="Verify" /></div></form></td>

I want to for that user submit the member_id of that user and also a flag of some description which would mean that the user with that member_id needs to be verified. 我要为该用户提交该用户的member_id以及一些描述的标志,这将意味着具有该member_id的用户需要进行验证。

So in essence 所以本质上

Print users needing verfication into table->click verify for particular user to be verified->pass to controller the user selected and a flag to indicate that user can be verified-> controller passes info to model-> model sets flag in the Database saying that user can be verified->model moves all users with that flag set to the verified_users table. 将需要验证的用户打印到表格中->单击要验证的特定用户的验证->将选择的用户传递给控制器​​,并显示一个指示用户可以被验证的标志->控制器将信息传递给模型->数据库中的模型集标志该用户可以被验证->模型将设置了该标志的所有用户移动到authenticated_users表中。

I can do all the controller/model bits myself. 我可以自己做所有的控制器/模型位。 It's just getting the data from the view to the controller I am struggling with. 只是将数据从视图中获取到我所苦苦挣扎的控制器。

Any help would me much appreciated! 任何帮助我将不胜感激! If any of it makes sense! 如果有任何道理!

you just need a hidden form field to send the ID -- using your code 您只需要一个隐藏的表单字段即可发送ID-使用您的代码

<td><form action="members/verify" method="post">
<input type="hidden" name="memberid" value="<?php echo $current_member_id ?>" />
<div align ="center"><input type="submit" value="Verify" /></div>
</form>
</td>

in your controller you can then get the value of member id from the form like 在您的控制器中,您可以从以下形式获取成员ID的值:

$memberid = $this->input->post( 'memberid', TRUE ) ; 

important point -- note that for this example i wrote the form action as "members/verify" . 要点 -请注意,在此示例中,我将表单动作写为“ members / verify”。 that means it will go to a controller named members, and the method named verify. 这意味着它将转到名为members的控制器以及名为verify的方法。

when you have time check out codeigniters table class - it can really help http://ellislab.com/codeigniter/user-guide/libraries/table.html 当您有时间检查codeigniters表类时-它确实可以帮助http://ellislab.com/codeigniter/user-guide/libraries/table.html

and the tutorial is a good reference for common tasks http://ellislab.com/codeigniter/user-guide/tutorial/index.html 该教程是常见任务的很好参考http://ellislab.com/codeigniter/user-guide/tutorial/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM