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.
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.
CodeIgniter – Write a cookie
This will show you how easy it is to set a cookie using CI (CodeIgniter) the PHP framework.
First we need to include the helper into your controller.
1 | $this->load->helper('cookie'); |
Now we need to set the cookie
1 2 3 4 5 6 7 8 9 10 | $cookie = array( 'name' => 'The Cookie Name', 'value' => 'The Value', 'expire' => '86500', 'domain' => '.some-domain.com', 'path' => '/', 'prefix' => 'myprefix_', ); set_cookie($cookie); |
OR
1 | set_cookie($name, $value, $expire, $domain, $path, $prefix); |
Now that we have set the cookie lets get it!
1 | get_cookie('some_cookie'); |
Done, now you know how to set a cookie in CI!
Database Class
The latest version 1.1.2 of the database class is now available for download! Check out the project page for info on how to use and download this class.
I think i am in Stack Love…
I am talking about BitNami Open Source Stacks! This was something i found and started using right away! I dont get “jump up and down” happy too often but, this is one of the times! I have been using BitNami for about 3 weeks and i dont know how i got along without it! Trust me, if your a developer you will love this!!! Stop wasting your time with installing each item for testing, just use BitNami form now on. You will thank me later.
PHP framework comparison benchmarks
Found this thanks to a buddy Jim Mayes.
This post covers some great info for PHP developers along with PHP vs Ruby on Rails. I was a little shocked by the results, but read for your self!
Read the PHP framework comparison benchmarks from AVNet Labs.
Winn Tracker 1.0 beta
It’s time to start tracking everything! Now you can with Winn Tracker; track downloads, page views, how many times a link or image or anything was clicked and, keep track of incoming links.
Very easy to use and start implementing right now! The system only takes one database table, and you can add this table to a current database so no need to make a whole new database for this. Developer friendly, the system is object orientated using one class. Once the class is called it will send the information provided to the database, after that it’s all yours!
Lets start go here to download the latest Winn Tracker.
WinnScriptatype:PHP v1.5 Available
Call two effects for two different elements with one call. This option is now working in version 1.5! Simply make the call “checkbox_do” then add your effects like so:
[php]
checkbox_do_fade_and_appear(‘div1′, ‘div2′, ‘***’, array(‘userName’ => ‘Bob’));
[/php]
Only change you will have to observe is the second element id input. In this case “div2″ is the second element that will receive the effect “appear”. Note that if your going to make the standard call for one effect it’s all still the same from version 1.0.
Check out the details and download WinnScriptatype:PHP v1.5
Winn Scriptatype for PHP
Thats right, i have converted the rails plugin to PHP. Now you can use the same functions in your next php application. This php class works the same way by creating a checkbox and on click it will call a script with Ajax that will update your database. On success it will return an effect based on the “checkbox_do_” call you make.
Visit the Winn Scriptatype:PHP page, after that you can take a look at the latest nightly dump for the next version of this great script at our SourceForge project page.
New Product: Winn Tracker
Something i have been working on for about three or four weeks now is something called “Winn Tracker”. This new product will have the ability to track page views, downloads and user information in your own custom application or website. Winn Tracker will allow you to make a call to the database to track info 3 ways.
1. Direct Link (http://your domain.tld/pathto/tracker…)
2. PHP Class link ($a->hit(‘info to send’,['userName' => 'Bob']);)
3. Ajax link, out of the three this is the preferred method of communication. I have build a new Javascript function on top of prototype to build the call and then use the Ajax.Request function. (Winnjs.Hit(’send info’,['username:Bob']))
The first launch of this will be in just a few short days and then the full release will be in about a month. The first release of this will not have a backend tool for the admin area. Version 2 will have a full admin area where you can create the three above calls with options, with little programing experience.
This system will come light with only about 1.5 megs of files and only 3 tables to install to your mysql database. Version 2 will come with a full install script along with many more options for non developers to use.
I will keep you posted on new changes to this and when it will launch.
Categories
Pages
- contact
- Contact Form V1.8
- FlickrHelper
- Guestbook V1.01 ASP
- Guestbook V2.4.7
- iFrame Loader
- Scriptatype:PHP
- Winn Cal
- Winn Tracker
