Passing a view as a variable. |
[eluser]ellipsis[/eluser]
[quote author="jedd" date="1245372022"]Close your eyes and learn how to [url="http://uk3.php.net/ternary"]use the ternary force[/url]. You'll never look back. But you will start looking sideways more often.[/quote] Tried doing it your way, but I ended up taking a nap... So, the second time around I decided to keep my eyes open and read that wonderful page. Honestly, I feel like I just struck gold. :lol: Now to go read some more about models and create that get_shit_from_db() function you so eagerly wanted to see.
[eluser]Dam1an[/eluser]
Firstly, +1 for the ternary operator ![]() When I first came accross it I was like wtf! But it's so awesome now 9although don't try to replace every if/else with it, cause I've seen people try that, it just doesn't work) Secondly, I'll step up and defend vars(), it can be very useful if like me, you prefer to use 2 level views (or more). Before I found out about it, I was nesting data arrays just so I would have them at the right level, but using vars() all my data is available to all views. Although I prefer to pass the data as a parameter to the view() function if it's just a single depth view And ellipses, I beat you to writing the get_shit_from_db function ![]()
[eluser]ellipsis[/eluser]
[quote author="Dam1an" date="1245374794"]Firstly, +1 for the ternary operator ![]() When I first came accross it I was like wtf! But it's so awesome now 9although don't try to replace every if/else with it, cause I've seen people try that, it just doesn't work) Secondly, I'll step up and defend vars(), it can be very useful if like me, you prefer to use 2 level views (or more). Before I found out about it, I was nesting data arrays just so I would have them at the right level, but using vars() all my data is available to all views. Although I prefer to pass the data as a parameter to the view() function if it's just a single depth view And ellipses, I beat you to writing the get_shit_from_db function ![]() Yes, that was also my understanding of what vars() is supposed to do, but what I did NOT understand - and maybe you can clear this up - is why when adding $fields to vars(), the variables did not get passed to the registration view, whereas if I provided $fields as a second argument to view('registration'), the variables were accessible just fine. Also, while working on the page just now I realized that my username_check() and email_check() functions were botched. Apprently they return "username/email taken" for whatever I input. Now, that probably has something to do with the fact that I forgot the second part of the condition in the if statement, but even after modifying it it still doesn't work. Any thoughts? Code: // MODIFIED VERSION - see first post for the original version
[eluser]Dam1an[/eluser]
In the code in you're first post, the view you're refering to is called before the call to load vars, hence those vars not yet being available Also, I just noticed, when you do load the vars, you pass in 2 arrays, thats not going to work as when you pass it to args, it expects 2 strings (key and value) (see line 339 in oader.php to see how/why it works) If you want to pass in 2 arrays, you need to merge them using array_merge As for the second problem, try something like Code: // Disclaimer: Not tested :P Yours wasn't working, because the where clause returns an object, which is not null, so it passes the first condition Hopefully my suggestion works and makes sense, if not just say so, and I'll get back to you ![]()
[eluser]ellipsis[/eluser]
I really thought I tried putting the vars($fields) before the if statement... oh well, it's almost 1 a.m. over here so I'll just blame it on that :lol: As for the second part, I was just reading the db page in the user guide and tried that thing you suggested, but I get a MySQL error, unfortunately. Quote:A Database Error Occurred
[eluser]jedd[/eluser]
I use raw SQL calls, so I'm not much good here. Two things, though. Turn on the [url="http://ellislab.com/codeigniter/user-guide/general/profiling.html"]profiler[/url] to see what your exact calls to the database are. It's often very enlightening in these situations. And swap the order of your tests - an array / string search is much faster than doing a database lookup, so you should do it first. ADDENDA - Third thing - I'd suggest you report a generic 'this account name is already in use', as a different error message ('this account is reserved') will hint to the user that the account is special in some way, and consequently a more attractive target. The user at this point (ie. when they are not known to you at all) does not need to know that there are special accounts, let alone what they are.
[eluser]tonanbarbarian[/eluser]
try the following, you are not specifying which table to get the data from Code: $this->db->where('username', $username); Code: $this->db->where('username', $username);
[eluser]ellipsis[/eluser]
@tonanbarbarian - That solved it. I was really wondering how it was supposed to magically know what table to extract the info from and have been trying manual SQL queries, as per jedd's suggestion. Thanks for that and thank you jedd for the profiler hint; it's providing some pretty interesting info. Here's the final code and it works flawlessly Code: //checking the username against a predefined set of rules
[eluser]ellipsis[/eluser]
Another day, another problem. I'm getting close to finalizing my registration form and database insertion, but I'm not quite there yet. Here's what I've come up with so far and aside from _encrypt() and add_to_db(), everything seems to be just fine. Any ideas what I'm doing wrong here? controllers/registration.php Code: <?php model/reg_model.php Code: <?php Edit: I've moved _encrypt() inside the constructor, but then I get the following errors: Quote:A PHP Error was encounteredIf I leave it outside the constructor and index(), I get Quote:Fatal error: Call to undefined function _encrypt() in C:\xampp\htdocs\site\frontend\controllers\registration.php on line 111
[eluser]Dam1an[/eluser]
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 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? |
Welcome Guest, Not a member yet? Register Sign In |