HOME     WEB DESIGN     WEB DEVELOPMENT     PORTFOLIO     ABOUT JS     CONTACT     BLOG
 

It's Blog...It's Blog...
...it's big, it's heavy, it's "good". For all of you who remember the Ren and Stimpy days, that was probably a flashback. For everyone else, sit back and enjoy our blog from the wide world of web development and design.


Getting the CRUD out in your code
<< January, 2009 >>
SMTWTFS
123
45678910
11121314151617
18192021222324
25262728293031
Search Blog

Categories
Archives
RSS

 

21 February 2008
Doug
Getting the CRUD out in your code
How some free online tools makes development easier



Ok, it's Thursday Tips Day, and I wanted to show you a very handy tool you can be using to speed along your development time, or help your web department speed their development time along at your own company.

The tool is called an Object Generator or an O/R Mapper.  Some also like to call them "CRUD" Tools.  CRUD is an acronym we geeky coders like to use that stands for:  Create, Read, Update, Delete.  In almost every basic web application out there today, we are asked to interface with some type of database or datasource.  And in almost every instance of that interfacing we (the coders) are doing some type of call to the database.  It could be reading one record, getting several records, updating a record, or even deleting one. 

Writing these calls can be very mundane.  Ones I usually save for my new coders to do <insert evil laugh here>.  However, these CRUD or Object Generator tools can help things along tremendously in development time, which then allows us or your web developers, time to focus on things that are usually overlooked or zipped through at the end of a project such as field validation, styles, SEO, etc.

For ASP.net we personally like to use O/R Mapper (www.ornetmapper.com).  The thing I personally like about this open source tool is the simple fact that the developer continues to really improve this tool with newer and more awesome releases than its prior.  As of this updated blog, the latest version is version 6, and it's come a long way and really could be the easiest most comprehensive way to develop the business logic for your next .NET project.


A Screen Shot of O/R Mapper (the ASP.NET Object Mapper Tool)
O/R Mapper Screen Shot

And using the code is even easier than using the tool itself in .NET.  So here's a quick example.  Let's say you have a table called Users and in your datagrid you have your typical select button which triggers your onSelect event in your code behind.  So now you want to populate a few text boxes in your form for editing.  Here it goes....in C#.net

          Users u = new Users();
          UsersAssembler a = new UsersAssembler();
          UsersCriteria c = new UsersCriteria();
          c.Set_Username(CriteriaBase.AVAILABLE_STRING_OPERATORS.EQUALS, "doug");
          u.ReadSingle(c);
         
Now that you have the information loaded into the "u" object...you just assign your textboxes accordingly....

          tbUsername.Text = u.Username;
          tbPassword.Text = u.Password;
          tbFirst.Text = u.FirstName;
          tbLast.Text = u.LastName;
      
          etc.

Did you blink and missed it?  Yes it's that quick.  You can also retrieve lists of results and do things like auto-bind it to your gridview, etc.  Really really cool.


For PHP, we personally like to use POG.  (www.phpobjectgenerator.com) This nifty little online tool will allow you to not only create the code classes you'll need to interface easily with your web application, but also build your tables for you.

      
A Screen Shot of POG (the PHP Object Generator Tool)
POG Screen Shot

Once all of your code and tables are built, its a snap to interface with them.  Let's say you have a table which has your user's vital information in it and you want to retrieve a list of users that have signed up in the past week.

       <?PHP
                  
                   // Create a new instance of our POG class for Users
                   $u = new users();

                   // Call the GetList Function to bring us back a list of users meeting our criteria
                   $userList = $u->GetList(array(array("signupdate",">=","2008-02-16 00:00:00")));

                   // Now loop through the results and display them for the end user to view
                   foreach($userList as $user)
                   {
                         echo '<p>User Name: ' . $user->username . ' <br />Name: ' . $user->first . ' ' . $user->last . '<br />Signup: ' . $user->signupdate . '</p>';
                   }
          ?>

Pretty simple huh?  And you can send as many criteria you want in additional arrays all in that same GetList() function.  So the speed at which you get results and have the ability to update them are fast and easy.

So take some time to check out POG or send this blog link to your favorite PHP coder.  They very well may thank you for it, however knowing most coders they'll probably say they already knew about it, thanks for the link, and then when people aren't looking will start to use it all the time.  Ha!!  Happy coding!

Doug.




                  
Posted by dougjustice at 8:44 AM | Link | 0 comments
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

No comments found.

Post a comment (login required)