Welcome Guest, Not a member yet? Register   Sign In
  Getting validated data into the database
Posted by: El Forum - 06-06-2008, 02:12 PM - Replies (2)

[eluser]Bob Sawyer[/eluser]
I've read the docs, searched through a ton of posts here, etc., but haven't found what I'm looking for, so here goes.

Using CI's validation class, I'm validating the $_POST data from a form. All's hunky-dory, and now I'm ready to insert it. But I'm not exactly sure what I'm supposed to supply to the model: the $_POST data (has it been cleaned?), the $rules array, or will CI just know what I'm asking it to do?

Here's my function for adding a new user:

Code:
class Users extends Controller {

    function Users() {
        parent::Controller();
        $this->load->model('User_sql');
    }
    
    function index() {
        $x['users'] = $this->User_sql->get_users();
        $this->load->view('admin_users_v',$x);
        
    }
    
    function newuser() {
        // load our libs and helpers
        $this->load->helper('form','url');
        $this->load->library('validation');

        // set the error delims
        $this->validation->set_error_delimiters('<div class="error">', '</div>');
        
        // set the validation rules
        $rules['username'] = "trim|required|valid_email|xss_clean";
        $rules['pass1'] = "trim|required|matches[pass2]|xss_clean|sha1";
        $rules['pass2'] = "trim|required|xss_clean";
        $rules['level'] = "required";
        
        // set the field rules
        $fields['username'] = "User name";
        $fields['pass1'] = "Password";
        $fields['pass2'] = "Password confirmation";
        $fields['level'] = "Level";
        
        $this->validation->set_rules($rules);
        $this->validation->set_fields($fields);

        // $x['error'] is checked in the view; if $error == 1 then display
        // the errors generated here
        $x['error'] = 0;
        if ($this->validation->run() == FALSE) {
            $x['error'] == 1;
        } else {

            // HERE IS WHERE MY CONFUSION BEGINS
            // What do I need to pass to the model?
            // $_POST? $rules? Anything?

            $this->User_sql->insert_user();
        }
        
        // OK, we're done, just grab the levels for the lvl select
        // and show the view

        $x['levels'] = $this->User_sql->get_levels();
        $this->load->view('admin_adduser_v',$x);
        
    }
    
    function edit($uid) {
        $this->load->view('admin_edituser_v');
    }
}

The real question is, I suppose, what becomes of the individual fields once they've been prepped for db insertion by the validator class?

Thanks for any assistance!


  CodeIgniter Community Voice
Posted by: El Forum - 06-06-2008, 01:53 PM - No Replies

[eluser]Derek Allard[/eluser]
OK guys and gals. I'm constantly bragging about how we have the best and brightest, and now its time to put up! Wink

As a way of giving the CI community an even louder voice, I'd like to once a week or two publish something from a community member to the CodeIgniter blog. Its a chance to write about whatever you want, and speak your voice. The idea isn't to gather posts on a specific topic, its to let you share with the communtiy. Has CodeIgniter given you something? Please give back!

I've got 3 posts so far from a few early adopters (the first will appear on Monday) and I'm looking for more. You don't need to have 250 posts you just need to have something to say.

So, let's turn to content. Want to write a tutorial? Cool. Want to talk about email? Cool! Want to discuss how use use CI? Really, anything goes. So far I've got audio recordings, video recordings, "formal" tutorials, ad hoc content. The sky is the limit. If you think other CodeIgniter-ers would want to hear it, then I want to publish it.

You could do a 1 paragraph haiku, or a 12 page tutorial. You could do video, audio. Heck, Micheal Wales gave me a slideshow, Elliot Haughan an mp3. I hope you get the point - it should be fun, it should be interesting, and it should be your voice.

Want to submit something? I can be reached at [email protected]


  Issue with URL's
Posted by: El Forum - 06-06-2008, 01:33 PM - Replies (2)

[eluser]evolve08[/eluser]
Hello all, new user of CI, but long time PHP programmer and web developer.

I'll jump right into it. I seem to be having some issues with links. The default action is index, however if the URL isn't set to <controller>/index URL's become messed up and I'm not really sure why (they point to the default route).

So, <controller>/ and <controller>/index are not acting the same way, and I think they should be.

I know I can avoid the problem by using the anchor helper, however I'm converting a pre-existing script with a lot of links and would rather not change them all within the view.

Hope I am explaining this correctly.


  Visitors Online?
Posted by: El Forum - 06-06-2008, 01:02 PM - Replies (18)

[eluser]EEssam[/eluser]
Hello,

Is their a feature in CI to display how many visitors are connected to the application?

Thanks.


  Sample application tutorial
Posted by: El Forum - 06-06-2008, 12:51 PM - Replies (3)

[eluser]Unknown[/eluser]
Hey guys,

Is there any (written) tutorial on building a sample app. other than that user guide?

Cheers


  URL
Posted by: El Forum - 06-06-2008, 12:42 PM - Replies (4)

[eluser]chinedubond[/eluser]
please i am trying get the present url am in.

also how can i get the history from the controller.
i know i can get from javascript. history(-1)
but how can i do that with CI from my controller.thank you.


  Testing
Posted by: El Forum - 06-06-2008, 12:42 PM - Replies (7)

[eluser]parrots[/eluser]
I have a fairly large application in CI right now, and I'm looking to improve our test procedures. And by "improve" I mean "put some in place". Looking to see how some other developers out there go about it.

I was thinking of leveraging the Unit Testing framework within CI for some of the more basic stuff -- making sure models do what they are supposed to, etc. But this only takes care of at best half(?) of what really needs to be tested since a lot of logic always resides in the controller. I was considering an automated web test suite (to record my actions through the site and be able to play them back and check conditions) but the products out there seem very lacking.

Aside from a massive set of test procedures that someone has to manually go through, how do you guys deal with regression testing and the likes on a large site?


  User routing
Posted by: El Forum - 06-06-2008, 12:38 PM - Replies (2)

[eluser]Nial[/eluser]
I have the following route rule:

Code:
$route['user/:any'] = "user/view";

Which makes domain.com/user/username possible.

However, I'd like to be able to do: domain.com/user/username/rss, for example. Where rss is a method within the user controller (just as view is).

How can I accomplish this?


  CI with Lighttpd
Posted by: El Forum - 06-06-2008, 12:36 PM - No Replies

[eluser]Matthew Lanham[/eluser]
Been hearing alot of stuff about Lighttpd, just wondered if anyone was using it at the moment, specifically with CI?


  xss_clean + strip_tags
Posted by: El Forum - 06-06-2008, 12:15 PM - Replies (6)

[eluser]Unknown[/eluser]
I think there should be an option which performs xss_clean and strip_tags for validation. This is useful to so that xss_clean and strip_tags don't need to be added to each item during validation.

Thoughts / Comments welcome!

Regards,
Jabra


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
shortcodes for ci4
by xsPurX
50 minutes ago
Array to HTML "Table"
by paulkd
9 hours ago
TypeError when trying to ...
by b126
10 hours ago
Webhooks and WebSockets
by InsiteFX
Yesterday, 10:39 AM
Retaining search variable...
by pchriley
Yesterday, 05:46 AM
Reading a session variabl...
by xanabobana
Yesterday, 05:05 AM
Update to v4.5.1, same us...
by kenjis
04-17-2024, 07:47 PM
Codeigniter 4 extend core...
by Semsion
04-17-2024, 05:08 AM
v4.5.1 Bug Fix Released
by lokman
04-16-2024, 02:12 PM
problem with textarea
by Nitin Arora
04-16-2024, 05:07 AM

Forum Statistics
» Members: 84,576
» Latest member: v9bettclub
» Forum threads: 77,558
» Forum posts: 375,897

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB