CI Bonfire 用户模块 - 在用户帐户设置后将用户帐户传递到重定向页面

CI Bonfire User Module - Passing User Account to redirect page after User Account Setup

代码点火器 3 & CI 篝火 0.7

我正在尝试将用户注册帐户时在 bf_users 数据库 Table 中自动生成的用户 ID 发送到其他注册页面以便在 bf_user 数据库 Table 和课程注册数据库 Table 之间创建一对多关系(bf_courseregistrations) 以便能够识别用户帐户和课程注册之间的关系。

这样做的原因是允许用户注册帐户,注册课程,然后能够在 示例中看到他们的用户帐户和课程注册信息。com/users/profile

用户控制器 (Bonfire/modules/users/controllers/Users.php)

public function register()
{
    // Are users allowed to register?
    if (! $this->settings_lib->item('auth.allow_register')) {
        Template::set_message(lang('us_register_disabled'), 'error');
        Template::redirect('/');
    }

    $register_url = $this->input->post('register_url') ?: REGISTER_URL;
    $login_url    = $this->input->post('login_url') ?: LOGIN_URL;

    $this->load->model('roles/role_model');
    $this->load->helper('date');

    $this->load->config('address');
    $this->load->helper('address');

    $this->load->config('user_meta');
    $meta_fields = config_item('user_meta_fields');
    Template::set('meta_fields', $meta_fields);

    if (isset($_POST['register'])) {
        if ($userId = $this->saveUser('insert', 0, $meta_fields)) {
            // User Activation
            $activation = $this->user_model->set_activation($userId);
            $message = $activation['message'];
            $error   = $activation['error'];

            Template::set_message($message, $error ? 'error' : 'success');

            log_activity($userId, lang('us_log_register'), 'users');
            Template::redirect('/Course-Registration', $userId);

        }

        Template::set_message(lang('us_registration_fail'), 'error');
        // Don't redirect because validation errors will be lost.
    }

    if ($this->siteSettings['auth.password_show_labels'] == 1) {
        Assets::add_js(
            $this->load->view('users_js', array('settings' => $this->siteSettings), true),
            'inline'
        );
    }

    // Generate password hint messages.
    $this->user_model->password_hints();

    Template::set_view('users/register');
    Template::set('languages', unserialize($this->settings_lib->item('site.languages')));
    Template::set('page_title', 'Register for EMDR Instruction Courses');
    Template::render();
}

Users/views/user_fields.php

<?php /* /users/views/user_fields.php */

$currentMethod = $this->router->fetch_method();

$errorClass     = empty($errorClass) ? ' error' : $errorClass;
$controlClass   = empty($controlClass) ? 'span4' : $controlClass;
$myControlClass = 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
$registerClass  = $currentMethod == 'register' ? ' required' : '';
$editSettings   = $currentMethod == 'edit';


?>
<div class="control-group<?php echo form_error('email') ? $errorClass : ''; ?>">
    <label class="control-label required my-control-label" for="email"><?php echo lang('bf_email'); ?></label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="email" name="email" value="<?php echo set_value('email', isset($user) ? $user->email : ''); ?>" placeholder="Enter Your Email Address" />
        <span class="help-inline"><?php echo form_error('email'); ?></span>
    </div>
</div>
<?php if (settings_item('auth.login_type') !== 'email' || settings_item('auth.use_usernames')) : ?>
<div class="control-group<?php echo form_error('username') ? $errorClass : ''; ?>">
    <label class="control-label required my-control-label" for="username"><?php echo lang('bf_username'); ?></label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="username" name="username" value="<?php echo set_value('username', isset($user) ? $user->username : ''); ?>" placeholder="Enter Your Account Username" />
        <span class="help-inline"><?php echo form_error('username'); ?></span>
    </div>
</div>
<?php endif; ?>
<div class="control-group<?php echo form_error('password') ? $errorClass : ''; ?>">
    <label class="control-label<?php echo $registerClass; ?> my-control-label" for="password"><?php echo lang('bf_password'); ?></label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="password" id="password" name="password" value="" placeholder="Enter Your Password" />
        <span class="help-inline"><?php echo form_error('password'); ?></span>
    </div>
</div>
<p class="help-block"><?php echo isset($password_hints) ? $password_hints : ''; ?></p>
<div class="control-group<?php echo form_error('pass_confirm') ? $errorClass : ''; ?>">
    <label class="control-label<?php echo $registerClass; ?> my-control-label" for="pass_confirm"><?php echo lang('bf_password_confirm'); ?></label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="password" id="pass_confirm" name="pass_confirm" value="" placeholder="Enter Your Password Again"/>
        <span class="help-inline"><?php echo form_error('pass_confirm'); ?></span>
    </div>
</div>
<div class="control-group<?php echo form_error('country') ? $errorClass : ''; ?>">
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="hidden" id="country" name="country" value="<?php echo set_value('country', isset($user) ? $user->country : 'Null'); ?>" placeholder="Enter Your Email Address" />
        <span class="help-inline"><?php echo form_error('country'); ?></span>
    </div>
</div>
<br>
<div class="row">
    <div class="col-12">
        By clicking register, you accept the <a href="<?php echo base_url('assets/documents/EMDRInstruction-Terms-And-Conditions.pdf'); ?>">Terms &amp; Conditions Agreement</a> and <a href="<?php echo base_url('assets/documents/EMDRInstruction-Privacy-Policy.pdf'); ?>">Privacy Policy</a> at EMDR Instruction.
    </div>
</div>
<br>

课程注册控制器

public function CourseRegistration()
{
    // create the data object
    $data = new stdClass();
    $this->load->model('roles/role_model');
    $this->load->helper('date');

    $this->load->config('address');
    $this->load->helper('address');

    $this->load->config('user_meta');
    $meta_fields = config_item('user_meta_fields');
    Template::set('meta_fields', $meta_fields);

    // set validation rules
    $this->form_validation->set_rules('display_name', 'Display Name', 'trim|required');
    $this->form_validation->set_rules('phone', 'Phone', 'trim');
    $this->form_validation->set_rules('address', 'Address', 'trim');
    $this->form_validation->set_rules('city', 'City', 'trim');
    $this->form_validation->set_rules('state', 'State', 'trim');
    $this->form_validation->set_rules('country', 'Country', 'trim');
    $this->form_validation->set_rules('zipcode', 'Zipcode', 'trim');
    $this->form_validation->set_rules('timezone', 'Timezone', 'trim');
    $this->form_validation->set_rules('language', 'Language', 'trim');
    $this->form_validation->set_rules('referral', 'Referral', 'trim');
    $this->form_validation->set_rules('course', 'Course', 'trim');
    $this->form_validation->set_rules('license_number', 'License Number', 'trim');
    $this->form_validation->set_rules('license_type', 'License Type', 'trim');
    $this->form_validation->set_rules('service_type', 'Service Type', 'trim');

    //~ if (isset($_POST['register'])) {
        //~ if ($userId = $this->saveUser('insert', 0, $meta_fields)) {
            //~ // User Activation
            //~ $activation = $this->user_model->set_activation($userId);
            //~ $message = $activation['message'];
            //~ $error   = $activation['error'];

            //~ Template::set_message($message, $error ? 'error' : 'success');

            //~ log_activity($userId, lang('us_log_register'), 'users');
            //~ Template::redirect('/Course-Registration');

        //~ }

        //~ Template::set_message(lang('us_registration_fail'), 'error');
        //~ // Don't redirect because validation errors will be lost.
    //~ }

    if ($this->siteSettings['auth.password_show_labels'] == 1) {
        Assets::add_js(
            $this->load->view('users_js', array('settings' => $this->siteSettings), true),
            'inline'
        );
    }

    if ($this->form_validation->run() === false) {

        $this->load->view('BackPages/CourseRegistration');
        Template::render();

    } else {
        // set variables from the form
        $name               = $this->input->post('display_name');
        $phone              = $this->input->post('phone');
        $address            = $this->input->post('address');
        $city               = $this->input->post('city');
        $state              = $this->input->post('state');
        $country            = $this->input->post('country');
        $zipcode            = $this->input->post('zipcode');
        $timezone           = $this->input->post('timezone');
        $language           = $this->input->post('language');
        $referral           = $this->input->post('referral');
        $course             = $this->input->post('course');
        $license_number     = $this->input->post('license_number');
        $license_type       = $this->input->post('license_type');
        $service_type       = $this->input->post('service_type');

        if ($this->backpages_model->user_information($name, $phone, $address, $city, $state, $country, $zipcode, $timezone, $language, $referral, $course, $license_number, $license_type, $service_type)) {

            // user creation ok
            redirect('/Course-Fees', $data);

        } else {

            // user creation failed, this should never happen
            $data->error = 'There was a problem submitting your song. Please try again.';

            // send error to the view
            $this->load->view('BackPages/Course-Registration', $data);
            Template::render();
        }
    }   

}

课程注册模式

public function user_information($uid, $name, $phone, $address, $city, $state, $country, $zipcode, $timezone, $language, $referral, $course, $license_number, $license_type, $service_type) {

    $user = array(
        'uid'                   => $uid,
        'display_name'          => $name,
        'phone'                 => $phone,
        'address'               => $address,
        'city'                  => $city,
        'state'                 => $state,
        'country'               => $country,
        'zipcode'               => $zipcode,
        'timezone'              => $timezone,
        'language'              => $language,
        'referral'              => $referral,
        'course'                => $course,
        'license_number'        => $license_number,
        'license_type'          => $license_type,
        'service_type'          => $service_type,
    );

    return $this->db->insert('bf_courseregistration', $user);

}

课程注册用户字段

<?php /* /users/views/user_fields.php */

$currentMethod = $this->router->fetch_method();

$errorClass     = empty($errorClass) ? ' error' : $errorClass;
$controlClass   = empty($controlClass) ? 'span4' : $controlClass;
$myControlClass = 'col-lg-12 col-md-12 col-sm-12 col-xs-12';
$registerClass  = $currentMethod == 'register' ? ' required' : '';
$editSettings   = $currentMethod == 'edit';

//$session_data = $this->session->userdata('sessiondata');
$user_id = $this->session->userdata('id');;
//$userId = $this->current->user(); 
?>
<?php echo 'This is your ID: ' . $user_id; ?>
<div class="control-group<?php echo form_error('uid') ? $errorClass : ''; ?> hidden">
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" uid="uid" name="uid" value="<?php echo set_value('uid', isset($user) ? $user->id : $user_id); ?>" />
        <span class="help-inline"><?php echo form_error('uid'); ?></span>
    </div>
</div>
<div class="control-group<?php echo form_error('display_name') ? $errorClass : ''; ?>">
    <label class="control-label" for="display_name">First &amp; Last Name</label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="display_name" name="display_name" value="<?php echo set_value('display_name', isset($user) ? $user->display_name : ''); ?>" placeholder="Enter Your First & Last Name" />
        <span class="help-inline"><?php echo form_error('display_name'); ?></span>
    </div>
</div>
<div class="control-group<?php echo form_error('phone') ? $errorClass : ''; ?>">
    <label class="control-label" for="phone">Phone</label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="phone" name="phone" value="<?php echo set_value('phone', isset($user) ? $user->phone : ''); ?>" placeholder="Enter Your Phone Number" />
        <span class="help-inline"><?php echo form_error('phone'); ?></span>
    </div>
</div>
<div class="control-group<?php echo form_error('address') ? $errorClass : ''; ?>">
    <label class="control-label" for="address">Address</label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="address" name="address" value="<?php echo set_value('address', isset($user) ? $user->address : ''); ?>" placeholder="Enter Your Address" />
        <span class="help-inline"><?php echo form_error('address'); ?></span>
    </div>
</div>
<div class="control-group<?php echo form_error('city') ? $errorClass : ''; ?>">
    <label class="control-label" for="city">City</label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="city" name="city" value="<?php echo set_value('city', isset($user) ? $user->city : ''); ?>" placeholder="Enter Your City" />
        <span class="help-inline"><?php echo form_error('city'); ?></span>
    </div>
</div>
<!--
<div class="control-group<?php echo form_error('state') ? $errorClass : ''; ?>">
    <label class="control-label" for="state">State</label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="state" name="state" value="<?php echo set_value('state', isset($user) ? $user->state : ''); ?>" placeholder="Enter Your First & Last Name" />
        <span class="help-inline"><?php echo form_error('state'); ?></span>
    </div>
</div>
<div class="control-group<?php echo form_error('country') ? $errorClass : ''; ?>">
    <label class="control-label" for="country">Country</label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="country" name="country" value="<?php echo set_value('country', isset($user) ? $user->country : ''); ?>" placeholder="Enter Your First & Last Name" />
        <span class="help-inline"><?php echo form_error('country'); ?></span>
    </div>
</div>
<div class="control-group<?php echo form_error('zipcode') ? $errorClass : ''; ?>">
    <label class="control-label" for="zipcode">Zipcode</label>
    <div class="controls">
        <input class="<?php echo $myControlClass; ?>" type="text" id="zipcode" name="zipcode" value="<?php echo set_value('zipcode', isset($user) ? $user->zipcode : ''); ?>" placeholder="Enter Your First & Last Name" />
        <span class="help-inline"><?php echo form_error('zipcode'); ?></span>
    </div>
</div>
-->

我自己想出来了。

在控制器中,

只需在控制器中设置 Template::set('variable、'passingData');`。

在您看来,只需使用 Template::get('variable'); 即可检索传递的数据。