Memcache with Codeigniter
In one of my latest projects we are using memcache to store user data and other items that will improve user experience. The cache library i am using is one i found on the CI forms. The library offers two types of caching. One is file caching for static pages or static data like a query. Two is memcache much faster and for data that is needed on quickly, note that memcache is not intended for static page caching you will need to use file caching for that.
How to use this library.
Load the library.
$this->load->library('Cache');
Now, useMemcache
$this->cache->useMemcache(MEMCACHE_IP, MEMCACHE_PORT);
After that we can now save data to memcahce.
$data = array('name' => 'Greg', id => 190); $this->cache->save($data["id"].'_user',$data,NULL,3600); // --------- // $this->cache->save(KEY, DATA, GROUP, TTL);
If you plan on using file caching you do not need the “useMemcache()” file caching is on by default. But if you want to use both you can just call “useFile()” to switch back to files. Example below:
$this->cache->useMemcache(MEMCACHE_IP, MEMCACHE_PORT); $data = array('name' => 'Greg', id => 190); $this->cache->save($data["id"].'_user',$data,NULL,3600); // Data above saved to memcache $this->cache->useFile(); $data = array('name' => 'Greg', id => 190); $this->cache->save($data["id"].'_user',$data,NULL,3600); // Data above saved to file.
Now lets retrieve the data from the cache.
$this->cache->get(KEY); // In my case above... $user = $this->cache->get('190_user'); echo $user->id; // would be 190
Download Cache.php library for Codeigniter.
Wordboxes.com
This is a new project i am working on with a few friends. I have had this domain for some time but never had time to use it.
What do you do with a box?
Boxes are used for many things. We use them to stack, to move, and to store. But what if there was box that did more?.
What would you do if you had a box like that? Tell a friend where you have been with a picture, get that thought of your mind, or just let the world know how you feel. Wordboxes will revolutionize the way you communicate with one another.Whether it will be with a picture,a few words, or both. Wordboxes will be the one box you won’t want to be without!
I will post more details about this project soon, but the best way to find out more is to “Get Notified” at Wordboxes.com.
No launch date has been set for this project, but the target is December 2009.
Welcome to the future
A thorn in the side of many web developers is Internet Explorer 6. It’s an old browser that has many annoyances that cause those creating websites to have to add additional code just to have things render as they should. Google, being a company that develops a web browser, has taken it upon themselves to solve this problem somewhat. It has just released an early version of a project called Google Chrome Frame, which, when used, will cause Internet Explorers 6 through 8 to use Chrome’s rendering engine, not their default one. This allows stubborn users (or those in a workplace environment) to continue using the browser they want to, and no longer aggravate web developers.
Read more about Google’s Chrome Frame
Thanks Google!
CodeIgniter v1.7.2 Cart Class
As you make know I am a huge fan of CI and this update has been long over due! The cart class is something that really makes me happy as a developer. I no longer have to look to a shopping cart that only meets half my needs. I can now build and deploy one with ease!
The Cart Class permits items to be added to a session that stays active while a user is browsing your site. These items can be retrieved and displayed in a standard “shopping cart” format, allowing the user to update the quantity or remove items from the cart.
Please note that the Cart Class ONLY provides the core “cart” functionality. It does not provide shipping, credit card authorization, or other processing components.
Load the cart lib and start using!
$this->load->library('cart');
Adding an Item to The Cart
$data = array( 'id' => 'sku_123ABC', 'qty' => 1, 'price' => 39.95, 'name' => 'T-Shirt', 'options' => array('Size' => 'L', 'Color' => 'Red') ); $this->cart->insert($data);
Destroy the cart
$this->cart->destroy();
More info on this can be found in the users guide on the CI website.
Winn Guestbook 2.4.7
The latest version of the popular guest book, added some major bug fixes and new features. One of the new items is you can now view posts on the guest book in there own page by calling “http://yourDomain/post.php?p=[id]“, this is pre linked for you now next to the persons name.
The web install is now working correctly with no errors. To download the latest version hop on over to the Google project page and click download.
Basics of Codeigniter
Lets go over some basics of CI, we all know it’s a great php framework with a small learning curve. I am going to show you some session basics.
To use sessions make sure you have that in your auto load array. Then we can start using the session markup.
So for this example i want to add some user data that i have pulled from the database into the session. Below is how i will add custom session data.
1 2 3 4 5 6 | $SesArray = array( 'firstname' => $db_fname, 'lastname' => $db_lname ); $this->session->set_userdata($SesArray); |
Now lets say i want to retreve this data and display it. Below is how to recall this custom session data.
1 | echo $this->session->userdata('firstname'); |
The above code would display the ‘firstname’ var that was stored in the session.
Now lets remove the ‘firstname’.
1 | $this->session->unset_userdata('firstname'); |
Once that is removed from the session you will be unable to recall that again, so be sure you wish to unset it.
Loading content with JQuery
Loading content via Ajax is quick and easy with JQuery. If you have never used jQuery before you might think twice about it!
Below is my html where we will load the content.
1 | <div id="LoadContent"></div> |
Now lets look at the javascript needed to load a remote page in.
1 | $("#LoadContent").load("path/to/remote/file.php"); |
After that is called the contents of “file.php” would be loaded into the div above! Quick and easy way to include item into your app. You may also pass variables to the page like so:
1 | $("#LoadContent").load("path/to/remote/file.php", {id: 1, name: "Greg"}); |
Hope this small tool helps change your mind about JQuery!
BitNami can save your life.
This is my second post about BitNami but i have to say, BitNami can save your life! I almost had to ditch a project as the client servers could not be accessed until the work was done. The server setup was 100% crazy!! I did not know what i was going to do… Then like headlights in the night i could see how to save the contract!
I downloaded one of the pre-built infrastructures and duplicated the server setup in less then an hour! I was happy the client was happy, all is good with the world!
Don’t know what BitNami is? If your a developer you need to know, learn more at BitNamis offical site. If i was on an island and could only bring 3 things it would be BitNami, beer, and more beer.
Handling Web Forms Google App Engine
If we want users to be able to post their own greetings, we need a way to process information submitted by the user with a web form. The webapp framework makes processing form data easy.
1 2 3 4 5 6 7 8 9 10 11 | class MainPage(webapp.RequestHandler): def get(self): self.response.out.write(""" <html> <body> <form action="/sign" method="post"> <div><textarea name="content" rows="3" cols="60"></textarea></div> <div><input type="submit" value="Sign Guestbook"></div> </form> </body> </html>""") |
Now lets pull the data out of the post…
1 2 3 4 5 | class Guestbook(webapp.RequestHandler): def post(self): self.response.out.write('<html><body>You wrote:<em>') self.response.out.write(cgi.escape(self.request.get('content'))) self.response.out.write('</em></body></html>') |
By using self.request.get(‘content’) i can get the post data from the field “content”. Easy right?
Browser detection using jQuery
Browser sniffing is messy. There are a million ways to do it but none of them are particularly clean and most involve conditional statements such as “” for IE and various other CSS selector hacks for other browsers.
It get around this common issue i am now using jQuery to add a class to my body tag.
1 2 3 4 5 | if($.browser.msie){ $('body').addClass('browserIE'); // Add the version number $('body').addClass('browserIE' + $.browser.version.substring(0,1)); } |
If the user is using IE it will add a class to teh body tag like so:
1 | <body class="browserIE browserIE#"> |
The “#” stands for the version of IE the user is running.
You can now access elements on your page that neeed to be corrected for IE by calling:
1 2 3 | .browserIE6 #myDiv { display:block; } |
This will work much better then current hacks. Hope that helps someone!!
Categories
Pages
- contact
- Contact Form V1.8
- FlickrHelper
- Guestbook V1.01 ASP
- Guestbook V2.4.7
- iFrame Loader
- Scriptatype:PHP
- Winn Cal
- Winn Tracker
