简体   繁体   English

从视图到控制器的代码点火器数据

[英]Codeigniter data from view to controller

Each User has multi profiles. 每个用户都有多个配置文件。 once they logged in, they are asked to select a profile, 登录后,系统会要求他们选择个人资料,

here is the code for Form to select profile. 这是表单选择配置文件的代码。

        <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-default">
                <div class="panel-heading">
                    <h3 align ="center" class="panel-title">Select Profiles</h3>
                </div>
                <div class="panel-body">
                    <?php
                        foreach($resJacs->{'details'} as $key) {
                            echo form_open('selectaccess', array(
                                'class' => 'form-group',
                                'role' => 'form'
                            ));
                            echo form_submit(array(
                                'value' => $key->profile_name,
                                'name' => $key->profile_type,
                                'class' => 'btn btn-lg btn-default btn-block'
                            ));
                            echo form_close();
                        }
                    ?>
                </div>
            </div>
        </div>
    </div>

when user selects the profile profile id is passed to session for later use. 当用户选择配置文件时,配置文件ID将传递给会话以供以后使用。 here is the code for "selectaccess", 这是“ selectaccess”的代码,

    public function SelectAccess() {
    $sess_data = array(
        'id' => $this->session->userdata['is_logged_in']['id'],
        'prfid' => $this->input->post('')
    );

    print_r($sess_data);
}

how can i prfid as mentioned in selectaccess method. 我怎么能像selectaccess方法中提到的那样。

I just want to give an example, maybe this can help u : 我只想举一个例子,也许这可以帮助你:

I am use pure html . 我使用纯html。

<form action="SelectAccess/<?php echo $id; ?>">
<input type="text" name="name">
<button type="submit">Submit</button>
</form>

Controller 控制者

function SelectAccess($val='') {
$input = $this->input->post('name');
$_SESSION['whatever'] = $val;
}

Normally you need to know the name of the field in order to get the value at the controller. 通常,您需要知道字段名称才能在控制器上获取该值。 But you are dynamically creating the field names so that gets tricky. 但是您正在动态创建字段名称,因此变得很棘手。

Fortunately you are only posting one input so $_POST should have only one item. 幸运的是,您只发布了一项输入,因此$_POST应该只有一项。 The way your view is written the value of $_POST[0] will be provided by $key->profile_name . $_POST[0]的值将由$key->profile_name Hopefully, that value is what you are looking for. 希望您正在寻找该价值。

public function SelectAccess() {
{
    $sess_data = array(
        'id' => $this->session->userdata['is_logged_in']['id'],
        'prfid' => isset($_POST[0])) ? $_POST[0] : NULL;
    );
}

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

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