Welcome Guest, Not a member yet? Register   Sign In
Set custom variable from controller to view
#1

[eluser]nws123[/eluser]
Hello, i am newbie in CI
I need help!

Controller:
Code:
function email()
    {
        $old_email_error = false;
        
        $this->load->library('auth');

        $this->auth->checkNotLoggedIn();        
        $this->_setup_email_validation();
        
        if ($this->validation->run())
        {

            if (@$_POST['email'])
            {

                $userId = $this->auth->getUser()->userId;
                $old_email = @$_POST['old_email'];
                $query = $this->db->get_where('user', array('email' => $old_emai));
                if($query)
                {
                    $data = array(
                        'email'=>$milo,                
                    );
                    $this->db->update('user', $data, array('id' => $userId));        
                }
                else
                {
                    $old_email_error = "Wrong Old e-mail";                
                }
                

            }
        }
        
        $this->load->library('design');

        $this->design->header('account');

        $data['javascript'] = $this->validation->javascript();
        $this->load->view('change_mail',$data);

        $this->design->footer();        
    }

view:
Code:
<h1>
        <a href="/settings">Account settings </a> :: Change e-mail
    </h1>

    &lt;?php echo $javascript; ?&gt;

    &lt;?php echo form_errors(); ?&gt;
&lt;?php
$old_milo = @htmlspecialchars($_POST['old_email']);
$milo = @htmlspecialchars($_POST['email']);
$milo2 = @htmlspecialchars($_POST['email2']);

?&gt;
&lt;!--form begin--&gt;
    &lt;form action="/settings/email" method="post" class="base sys"&gt;

    <fieldset class="group">
        <label for="email" &lt;?php echo field_error('old_email'); if($old_email_error) echo $old_email_error;?&gt;>

            <span>Old e-mail address</span>

            &lt;input id="old_email" name="old_email" type="text" value="" /&gt;

        </label>

        <label for="email"&lt;?php echo field_error('email');?&gt;>

            <span>New e-mail address</span>

            &lt;input id="email" name="email" type="text" value="&lt;?php echo $milo; ?&gt;" /&gt;

        </label>

        <label for="email2"&lt;?php echo field_error('email2');?&gt;>

            <span>Re-type new e-mail address</span>

            &lt;input id="email2" name="email2" type="text" value="&lt;?php echo $milo2; ?&gt;" /&gt;

        </label>

    </fieldset>

    

    <fieldset>

        &lt;input type="submit" name="email" value="Change e-mail" class="b3s register"/&gt;

    </fieldset>

&lt;/form&gt;
&lt;!--end form--&gt;

How set variable $old_email_error into view ?
(ex. CakePhp $this->set('variable','value'); )
#2

[eluser]drewbee[/eluser]
Hi,

You pass it along with the load->view method as you did with the javascript variable. Set is as an array.

Code:
$data['javascript'] = $this->validation->javascript();
$data['old_email_error'] = 'value';
$this->load->view('change_mail',$data);




Theme © iAndrew 2016 - Forum software by © MyBB