Bonfire’s base user system is based on a Entity-Attribute-Value based system where you store the user’s meta in a seperate table, very similar to how wordpress is setup.
This has a lot of benefits but can also cause a lot of confusion when it comes down to extending the user system, as with extending anything you want the end product to be maintainable but still be powerful and do everything you needed.
Bonfire’s default user system is setup with a main user table and a meta table, kinda something like this
So basically the meta values are stored in a seperate table and added to the current_user object as needed with $this->user_model->load_meta, this does a good job for
most systems I’ develop but every so often a piece of the user data that isn’t important enough to alter the entire system but I needed to be able to display this data like it was in the same table, so instead of 2 tables it would look like
To generate the joined table as above I personally found joining the tables worked very well and did not cause to much server load, any suggestions will be taken if you have a different method but anyway to join the tables what I personally did was add a new method to the user model something like this.
/** * Loads user and meta data in one query. * * @param int $user_id user_id or blank for all. * @param bool $show_deleted [show deleted users] * * @return mixed */ function load_user_meta($user_id = 0, $show_deleted == FALSE) { $this->db->select('users.*, roles.role_name'); $this->db->select('m1.meta_value AS first_name'); // Just keep adding these and alias as you need! $this->db->select('m2.meta_value AS last_name'); // $this->db->select('m2.meta_value AS alias'); $this->db->join('user_meta', 'user_meta.user_id = users.id', 'left'); // Here is the magic baby! $this->db->join('user_meta as m1', "m1.user_id = users.id AND m1.meta_key = 'first_name' ", 'left'); $this->db->join('user_meta as m2', "m2.user_id = users.id AND m2.meta_key = 'last_name' ", 'left'); // ! Change me $this->db->join('user_meta as m2', "m2.user_id = users.id AND m2.meta_key = 'alias' ", 'left'); if ($show_deleted === FALSE) { $this->db->where('users.deleted', 0); } $this->db->where('users.banned =', 0); $this->db->group_by('users.id'); if (is_numeric($user_id) && $user_id > 0) { return parent::find($user_id); } return parent::find_all(); }
As always I take no responsibility for any typos misspelling, cats that commited suicide or anything else that hurt your eyes or sanitiy but that should get you started I hope,
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
As I’ve grown to love GIT and decided that life is much better with it, and life would be a whole lot
better if you could manage yours using GIT (I donnu git clone me or git fork me lol) anyway over the
few years I have been using GIT now, I’ve found and collected a bunch of various helpers that improve my
daily work flow with it.
Since I suffer from Short term memory loss apparently and I also like to share what I find useful to me
, I’ve decided maybe some of my readers might find a few of these tools helpful to you, I normally use
Debian or Mac for a OS so I’m not sure if much of this will be useful to my windows readers, but for us
Command Line Junkies then a lot of this will be very helpful, There’s some aliases, some config changes,
and then there’s the real hard-core packages and gem’s that I just can’t live without anymore.
O, if you haven’t watched Tech Talk: Linus Torvalds on git then I highly suggest it.
Aliases and my Global Config file Template.
I lost most of my aliases in my last hard-drive crash, so I have to rebuild them! I will add my aliases file from my office CPU when I go into the office though.
This is probably one of the best branching model’s I’ve used, it did have a little bit of a learning curve, so I’ll give you some links that I read to help me understand it better.
Makes managing of Gists through the command line easy, create them, delete them, etc.
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
For those that use Bonfire and Sublime Text Editor, I have released my collection Snippet’s collection of just Bonfire snippets. Since there is already a CodeIgniter Snippet package out there, I’m only including Bonfire specfic snippet’s in the Package.
Currently you have to install the packages manually with git
Debugging snippets I use some are not fully Bonfire related.
Tab Trigger
Output
cplog
ChromePhp::log($1);
cperror
ChromePhp::error($1);
console
Console::log($1);
enable_profiler
$this->output->enable_profiler(FALSE);
bflog
parent::logit($1, ‘${2:error]’);
log
logit($1, ‘${2:error]’);
dad
$dump()die;
If you have any snippet’s you use for Bonfire please fork and add them.
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
One thing that I require a lot in building Bonfire based Websites is to modify mostly views in some of the Core Modules, namely the User Module since that has Public facing View files and not all my Websites are built using Twitter Bootstrap’s framework depending on the Front-end Developer I’m working with on the project with.
This is a really simple trick I learned not to long ago but makes upgrading very easy later on which with a constantly changing software like Bonfire then Over-riding my Core modules and keeping track of the changes gets hard namely when you build as many website’s as I do in a year. This is a very very very simple trick and you’ll probably have a Facepalm Moment for not thinking of this yourself after seeing what it involves!
Basically modules in Bonfire exist in 2 locations
bonfire/application/core_modules
bonfire/modules
Which the Core Bonfire related modules live in core_modules and custom modules belong in the modules directory. So the simple trick here is just copy your core_module into the modules directory like this.
Or you can drag and drop it using Finder or whatever you do to copy a folder to a new location. So now yoo have 2 copys of the same module, you can actually delete the one your over-riding but I perfer to just leave it there myself.
So what have we learned here, the order modules are loaded is first “core_modules”, then “modules” so anything in the modules directory will over-ride the “core_modules” directory. Simple enough?
Hope this helps someone. Enjoy and Cheers!
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
Well Ready or Not Here We Are! Incase you noticed it, yes we have moved Domains back to ShawnC dot ORG! for a little history lesson, in around 2006 I started this blog on shawnc.org’s domain mostly to blog about linux then web development, the reason I bought the .org domain instead of a .com was someone already owned it go figure, well around 2008 or so if memory serves me the domain at .com was owned by another Web Programming Free Lancer, and not only that he lived about a hour from me so confusion was certain, I moved away from the name mostly due to that. Apparently since then he ripped off abunch of clients and vanished, off course the domain name is still for sale, some recently tried to sell it to me for 3k USD which seemed abit high for a domain I make no money off of.
Anyway this time around, I got sick of WordPress again or the server load that a PHP script or any dynamically generated content produces, so I’ve moved to a Static Content Generator called Ocotopress which is a Ruby based script that I’m having quite a lot of fun modifyin to my needs.
Now I know there are still some bugs left in the website and probably some broken links from the migration, sorry but if you find them it’d be mighty white of you to let me know about them would ya! You’d even get the Chuck Norris badge of well anyway if you see something broke then tell me will you, there’s comments and twitter’s and all kind of communication forms, use one!
And since we’re off to a new start, I’m gonna try and see if some of my friend (yes I do have them honestly really yep) will make some guest posts, might include some new topics, and last but not least Mor Cowbells my friends, yes Mor Cowbells!
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
Earlier this year a extension and PHP class were released that allowed logging PHP messages to Chrome’s Console, similar to FirePHP for FireBug but well for Google’s Chrome Browser instead yay!. Anyway I’ve grown quite fond of both Chrome and the Console logging of my debug messages recently and decided maybe some of the other Bonfire users might find some use in this.
Basically Bonfire has 2 helper methods called logit one as a application helper and one in the model, these handy helper’s make a log entry in CodeIgniter’s system log, and use the Console class already included in Bonfire to output any message. The only problem with this is normally when you have a error the page doesn’t finish rendering and the stock Bonfire Console library doesn’t display any data since it’s not rendered. So I just made a few quick changes to the logit methods and added the helper. And now I have better debugging ability!
First get the helper and the extension, my friend Marco Monterio has already explained on his blog how to install the extension and the helper, so check his blog out on installing the ChromePhp library to CodeIgniter. Once you have it installed, then you can make these changes and you’ll be debugging like a kingpin while your off getting your ChromePhp on, I’ll gonna drink that beer you bought me :beer:
Ok, so we only need additions to 2 files and 2 methods, this is easy! Let’s start with MY_Model. So open up “/bonfire/application/core/MY_Model.php”, do a quick search for “logit” and add the code I have below for ChromePhp
<?php/** * Logs an error to the Console (if loaded) and to the log files. * * @param string $message The string to write to the logs. * @param string $level The log level, as per CI log_message method. * * @access protected * * @return mixed */protectedfunctionlogit($message='',$level='debug'){if(empty($message)){returnFALSE;}if(class_exists('Console')){Console::log($message);}// Just add from hereif(class_exists('ChromePhp')){if($level=='error'){ChromePhp::error($message);}else{ChromePhp::log($message);}}// Just to here.log_message($level,$message);}//end logit()//--------------------------------------------------------------------?>
Ok so there’s the Model changes, now open up “bonfire/application/helpers/application_helper.php” and once again find the “logit” function
<?php/** * Logs an error to the Console (if loaded) and to the log files. * * @param $message string The string to write to the logs. * @param $level string The log level, as per CI log_message method. * * @return void */functionlogit($message='',$level='debug'){if(empty($message)){return;}if(class_exists('Console')){Console::log($message);}if(class_exists('ChromePhp')){if($level=='error'){ChromePhp::error($message);}else{ChromePhp::log($message);}}log_message($level,$message);}//--------------------------------------------------------------------?>
And there ya go, now everytime logit is called, you can see what the message was inside of your Chrome Web Inspector Console just like you would a JavaScript console.log method would give. Amazing stuff!
Cheers and Free beers again!
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
Something I’ve noticed in recent days is using Bonfire without Bootstrap in the front end, for the most part it works fine with just changes to the User Module view files, but one thing that will cause issues is the Form helper since it has been converted to use Bootstrap.
It’s a easy fix thou, imagine that! Since the Form helper is a Helper and a Library you just need to rename to files and then in the Admin Base Controller (MY_Controller.php) load those files so that any Admin modules will still work properly.
So rename the following to bootstrap-form_helper.php and bootstrap-form.php
Once those are renamed, open up MY_Controller, find the Admin_Controller and load the helper.
$this->load->helper('bootstrap-form');
And that is all. Over and Out!
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
Like most of you, I’ve given up on Ubuntu it had a great run but it’s all over baby-blue, it’s turned into a Mac wanna be. Granted yes it’s super easy to learn, and I highly suggest it to Winblows users as a easy linux start.
But coming from the days of Fiesty and before, I don’t like Unity bla and some of the other junk out there. So I’ve moved back to Debian and kind of forgot a lot of Debian since I’ve been so used to Ubuntu.
The First thing I needed as a PHP development envirment on the ASAP, so that’s a LAMP stack, we already have the L so we just need the AMP! for those not in the know, LAMP stands for Linux, Apache, MySql and PHP, all of which are easy to install in Synaptics.
Now one thing I’ve grown pretty used to was PPA packages. So let’s get them started and hopefully some Ubuntu packages can be installed easily.
Debian is different then Ubuntu in that you need the old school keys for packages, what security in place? OMG! No this is easy stuff on the Terminal and if you don’t wanna be in the Terminal, get a Mac or Ubuntu.
I like the launchpad PPA’s namely for Sublime and some other goodie’s, so without drum roles, 21 gun sallutes ( yea I know I cant spell, I’m sure you know what I’m saying or get me a Gizoo to fix these things! Google it hint Flintstones)
Let’s break that down, for once I’m gonna explaign! Apt is short for aptitude yep remember that? Now, the XXXXXX thing, that’s your key. When you goto your Launchpad PPA, there’s a key kinda looks like 1024 / XXXXXXX, take the / XXXXX and put it there.
After that, let’s add our sources, update and get jiggy wit it.
Run these in bash (commands.sh)
1
sudo /etc/apt/sources.list.d/something.list
In there just grab the “deb *****” junk, ( yes I will show a install soon ) drop them in and run
Run these in bash (commands.sh)
1
sudo apt-get update
That updates are apt sources, then install something. Now since I’m setting up a Dev env, I want Sublime text editor to start. Which looks like this.
Another thing I needed was Mod Rewrite enabled ib Apache so just enable it.
Run these in bash (commands.sh)
1
sudo a2enmod rewrite
One more thing I always need is Virtual Hosts since the days of FTPing are almost over, I work local then gitpush it the servers mostly cloud based nowadays so, lets go through and make one easy like. This assumes you’ve done this before.
Go inside there change what you need, make sure Allowoverride is set to All, and then enable it
Run these in bash (commands.sh)
12
sudo a2ensite new
sudo service apache2 restart
And that’s a virtual host.
NodeJS and Ruby like the Hipsters Do!
Ok ok, what Dev envirment would I be creating with out NodeJS and Ruby, I know so let’s get started shall we, hopefully you won’t be growing a beard and calling everyone Braj after this……Right on Braj :P
One again pop open the terminal, which you should be living in anyway. And let’s toss some commands out there.
Step one, install the build essentals which you should already have.
After that, let’s clone Node and compile from source cuz we cool like that right Braj?
Run these in bash (commands.sh)
1234567891011121314151617
git clone https://github.com/joyent/node.git
cd node
# 'git tag' shows all available versions: select the latest stable.git checkout v0.6.8
# Configure seems not to find libssl by default so we give it an explicit pointer.# Optionally: you can isolate node by adding --prefix=/opt/node./configure --openssl-libpath=/usr/lib/ssl
make
make testsudo make install
node -v # it's alive!# Lucky us: NPM is packaged with Node.js source so this is now installed too# curl http://npmjs.org/install.sh | sudo shnpm -v # it's alive!
Now that we have NodeJS going, lets drop in what I use alot
Run these in bash (commands.sh)
1
npm install recess -g
Ok that’s Node, Ruby is even easier here.
First thing’s first, we need to install abunch of build-dependicy’s for Rails, otherwise you’ll get errors eventually.
Ok that’s the start of my Debian install. Stay Tuned for more Adventures in Linux land!
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
So the switch from clunky old wordpress is moving right along now and bam, I hit a snag. I decided to host all my photos on FlickR since they offer a decent photo service and there’s plenty of easy to use gems so hey why not right?
Well since I exported about 70% of my posts from Wordpress to Markdown and about 65% of those came out fairly decent,
but all my images were now stuck FlickR in weird numbers and I just wanted to say flickr phto but that would way to easy right? NAH! Let’s do this smart way please, I know u can find batch uploader and badbam there up there, just
stick them all in a photoset and let’s use FlickR’s own API for our own greedy time saving reasons.
I remember awhile ago I wrote a acouple gallerys based on FlickR and they had a great API and a API Explorer/Tester whatever the we want is flickr.photosets.getPhotos
This will give you all your photo ids and names and all kinda goodies that I didn’t need but, hey hey extra extra
info never hurt no one so lets what need.
O wow, just stick photoset ID inside the box, I’d set the per to like 1000 so u get them and personally I’d just get
a JSON output then from there it’s just finding the images and replacing them with the flickr tag .
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!
In a recent application, I needed the ability to add Help context’s to allow the admin to see instructions in general and by mdule, so I added a simple help controller and default view.
It’s easy really, just add a controller in your applications/controllers/help.php
then add in your application/views/admin/help/index.php
And to-da there’s the code for all the magic to happen just git clone it and have a field day with the ak!
From there, you can now add help.php controllers in your modules!
Who-rah! Help is on the Way my friends!
About Shawn Crigger
Free lance web developer who lives for programming and debugging server and code when not Geeking out on creating new web applications, servers, home media theaters, or whatever else comes to me, you might find him Surfing the waves in Myrtle Beach SC. Current daily skill set involves PHP, JavaScript, CodeIgniter, and CI Bonfire!