Welcome Guest, Not a member yet? Register   Sign In
Passing a view as a variable.
#21

[eluser]ellipsis[/eluser]
[quote author="Dam1an" date="1245456827"]First of all, the encrypt function
1) You're declaring it as a function within the constructor :-S
2) When calling a function, use $this->_encrypt instead of just _encrypt
3) It's setting the value in a local array called $fields, either make it return the encrypted value, or use a class variable for the array
[/quote]
I declared it up there because I thought that would help with my current error, but your suggestion did the trick ^_^
[quote author="Dam1an" date="1245456827"]
As for the model, do you get any sort of errors with that? Or it just doesn't do anything?
I just noticed, you don't ever seem to actually set the variabes you use in the formdata array?[/quote]
I do get the errors now, because all the variables seem to be null. I wanted to set the values received from doing the form_validation in the array $formdata, but it seems it was the wrong way to go about doing that. Help?
#22

[eluser]Dam1an[/eluser]
I think someone need to read up on the form validation library Tongue

To get the values, you need to use set_value
Code:
$email = set_value('email);
etc
#23

[eluser]ellipsis[/eluser]
Well that's embarrassing, considering I've had the form validation page open for the past two days :lol:
Anyway, that fixed that problem, now the only field that isn't going through to the db insert seems to be the password field...

Here are the significant changes I've made:
Code:
function _encrypt($password)    
    {
        $toenc='bigstring'.$password.'biggerstring';
        $shapassalt=$this->encrypt->sha1($toenc);
    }

Code:
$this->form_validation->set_rules('fn', 'First Name', 'trim|xss_clean');
            $this->form_validation->set_rules('ln', 'Last Name', 'trim|xss_clean');
            $this->form_validation->set_rules('username', 'Username', 'trim|xss_clean');
            $this->form_validation->set_rules('password', 'Password', 'trim|xss_clean');
            $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean');
            $this->form_validation->set_rules('site', 'Website', 'trim|xss_clean');
            $this->form_validation->set_rules('country', 'Country', 'trim|xss_clean');
            $this->form_validation->set_rules('city', 'City', 'trim|xss_clean');
            $this->form_validation->set_rules('zipcode', 'Zipcode', 'trim|xss_clean');
            $this->form_validation->run();
            $password=set_value('password');
            $this->_encrypt($password);    
            $formdata=array('username'=>set_value('username'), 'password'=>$shapassalt, 'email'=>set_value('email'), 'first_name'=>set_value('fn'), 'last_name'=>set_value('ln'), 'website'=>set_value('site'), 'country'=>set_value('country'), 'city'=>set_value('city'), 'zipcode'=>set_value('zipcode'));
            $this->Reg_model->add_to_db($formdata);
#24

[eluser]Dam1an[/eluser]
You still need to either return a value from the encrypt function and assign it to a variable which you then feed into the database, or class method
#25

[eluser]ellipsis[/eluser]
That was incredibly stupid of me :lol: Thanks for that.
I've successfully added my first user to the database Big Grin
Now on to the login script and dealing with sessions...
#26

[eluser]Dam1an[/eluser]
Well done (and we all have stupid moments every now and again)
Good luck with the login Smile
#27

[eluser]ellipsis[/eluser]
Now... I built a new controller Login for logging in, although the login will be done directly on the page you're on (i.e. you don't have to go to a log in page) and the user verification works, but I'm using redirect() to send the user to the home page. I was actually thinking of using a login function in the controller, but then I'd have to write it in each and every controller. Would it be better to write the function in, say, a model and then call it from every controller? Also, can I somehow tell redirect to go back to the current page?
#28

[eluser]Dam1an[/eluser]
you could put the login code in a MY_Controller, that way it can be called from any page with no extra effort (you can either do the processing there, or call a library if you're prefer to wrap up all the authentication stuff in a library)
#29

[eluser]ellipsis[/eluser]
[quote author="Dam1an" date="1245505980"]you could put the login code in a MY_Controller, that way it can be called from any page with no extra effort (you can either do the processing there, or call a library if you're prefer to wrap up all the authentication stuff in a library)[/quote]
Is it possible to call a controller? like $this-controller_name->index()
As far as I know, I have php 5 and method chaining should work, but the following fuction

Code:
function get_id($logindata)
    {
        $this->db->select('id')->from('users')->where->('username', $username);
        $id=this->db->get();
        return $id;
    }

gives me the following error

Quote:Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' in C:\xampp\htdocs\site\frontend\models\login_model.php on line 18
#30

[eluser]Dam1an[/eluser]
are you rrefering to calling the controller from within MY_Controller? You don't need to
It still calls the controller function as it would normally, but calls MY_Controller and it's constructor first

Or you on about something completely differant?

As for the second part, you have an extra -> after where and missing the $ in from of this on the next line, it should be

Code:
function get_id($logindata) {
    $this->db->select('id')->from('users')->where('username', $username);
    $id=$this->db->get();
    return $id;
}

Also, you pass in $logindata and don;t use it, but get a $username variable from nowhere :-S

Oh, and a decent IDE (I pasted it in Eclipse for it to tell me the syntax error) will save lots of time




Theme © iAndrew 2016 - Forum software by © MyBB