MainelyDesign.com Blog

Example Tagged Blog Posts

Get All Active jQuery UI Dialog Windows, then Close 'Em

Posted on 03/21/2013 at 02:36 pm | Viewed 20,072 times | 0 comments

I had a need to close all active jQuery UI dialogs on the page (yes, I have more than 1 open at a time!).  You may think it's as easy as calling $('.ui-dialog').dialog('cose') but you'll throw an error.  The way I've figured out how to do it (jquery UI 1.10) is pretty simple, really:

Close all Active jQuery UI Dialog Windows

jQuery UI 1.10 Tabs - Getting Index of Current Tab

Posted on 03/18/2013 at 10:00 pm | Viewed 17,943 times | 0 comments

I remember being able to get the index of the current tab very easily from jQuery UI, something like ui.panel.index.  I couldn't find it in my code and figured out the way to do it with jQuery UI 1.10

Determining the Current Tab Index

Most of the documentation and examples for JQuery UI keep using the same basic code that doesn't really work if you have more than one tabbed-interface on any of your web pages.  The jQuery UI documentation tells you to do this:

jQuery UI 1.10 Tabs - Using Aria-Controls to Set the URL of a Tab

Posted on 03/18/2013 at 01:00 pm | Viewed 79,580 times | 0 comments

I continue to find things that I overlooked on my upgrade to using jQuery UI 1.10.  This time it was the tabs API changes that got me. 

No more show(); Now use activate();

The first change that really did me in ("why aren't any of my tabs executing my show callback function???") was the elimination of the show() callback.  This callback used to be fired-off each time a panel was displayed.  The change is easy, just rename your callback to activate:

Best Way To Get Transparent PNGs Without Any Hacks

Posted on 10/21/2012 at 10:27 am | Viewed 13,566 times | 0 comments

I avoided PNG images for quite a while, mainly because I could accomplish almost every task with transparent GIFs (if not, I could change the design ever so slightly).  Fast forward a few years and web designs are far too complex and textured to only use transparent GIFs, plus it's so much cooler to say "ping" than "gif".  Another reason I avoided using transparent PNGs was due to the ability to make IE (Internet Explorer) crash (suprise!).  Finally, I avoided using PNG images on my website because their filesize was ridiculous (what I could do in 10kb using a Gif, would take 71kb as a PNG).

Calling an Element from a Helper

Posted on 02/24/2012 at 02:07 pm | Viewed 12,298 times | 0 comments

This one caused me more than a little headache,  turned out it was easily solvable.

renderElement() can be used in a helper function.

The following example worked nicely for me.

In this case I am calling and element "order_form.ctp"

 

$theView = ClassRegistry::getObject('view');

Best PaginateCount for CakePHP - with Group By Support

Posted on 08/07/2011 at 05:03 pm | Viewed 19,547 times | 0 comments

I'm been muddling my way through pagination with multiple joins, and complex filtering.  I finally got it all working (more on that later, maybe....) when I noticed that I couldn't paginate my results.  Everything was working fine until I added a "group" parameter to the find call.  Instead of getting the right count, I got a count of 1!  A quick look at my sql log tables (at the bottom of the page) and I saw that I had actually returned all the mysql records that were needed!  If only there was a way to use them...

Sorting Paginated Results Using a Related Model Field in CakePHP

Posted on 02/06/2011 at 10:12 pm | Viewed 18,027 times | 0 comments

Time crunch, so this will be quick.  I didn't want to go hunting for how to sort paginated results in CakePHP using a related model field again.  I actually found my answer on Stack Overflow.  The original poster had it right, so I'm not sure if it was a CakePHP bug or what (I don't have an account or I would correct it... it's on the list of to-dos though).

Changing CakePHP's Model useTable on the Fly

Posted on 11/02/2010 at 05:12 pm | Viewed 18,180 times | 0 comments

I finally found an answer to/solution to something I've never been able to get around in CakePHP before: dynamically changing/setting the useTable value in a model.  You can't just say $this->CakePHPModel->useTable = 'cakephp_table_name';  Instead you have to use the following function:

Setting CakePHP Model useTable Dynamically

Common SSH Commands (An Idiot's Guide)

Posted on 09/25/2010 at 09:25 am | Viewed 12,929 times | 2 comments

Well, I never thought I would be saying this, but I'm starting to love using SSH to manage certain elements of my server.  Now that I'm using ssh bash to make some updates to my server, I find myself constantly hunting for the simple commands.  I'm going to put all the commands I need below, because I'm the idiot and it's my guide.

Getting All ACL Permissions in One Lookup (CakePHP 1.3)

Posted on 09/19/2010 at 11:36 am | Viewed 20,710 times | 1 comment

The biggest hurdle I've had to overcome migrating my CakePHP application from 1.2 to the much improved 1.3 branch involves Plugins and the ACL component.  A while back I noticed that my backend was kind of sluggish due to all of the ACL lookups (that happen with each request) so I optimized my ACL database tables.  At that same time, I also discovered an incredible mysql query that would lookup all of the ACL permissions for a particular ARO.  This setup worked great... until I started upgrading to CakePHP 1.3. 

Global Mysql Find and Replace with CakePHP

Posted on 08/31/2010 at 09:03 am | Viewed 14,296 times | 0 comments

I'm moving my Content Management System over to CakePHP 1.3.  I'll post an article about my experiences later.  Today I will focus on one and only one issue with the migration from Cake 1.2 to 1.3: the change of webroot/theme/ to webroot/theme/ to serve static content.  At first I was a little disapointed/scared at the prospects of making this change, but have since come to see the absolute brilliance in this approach.

Best Approach to Dynamic Javascript in CakePHP Views

Posted on 05/29/2010 at 12:36 pm | Viewed 22,796 times | 5 comments

I always knew in the back of my mind that there was a better way of creating dynamic javascript than the method I was using.  CakePHP has a great function as part of the $View controller:  $View->addScript($jscript, false) will add a script block to your template header.  This is the command I use to send javascript created in a Cake view up to the header, which is where most javascript should live.  The best approach to adding dynamic javascript to your CakePHP views is to implement PHP's output buffering, combined with $View->addScript().

Speeding Up Cakephp's ACL Component

Posted on 05/28/2010 at 12:12 pm | Viewed 17,610 times | 1 comment

I came across a posting today that changed the performance of my application tremendously and reinforced a concept I had forgotten about- mysql indices. I didn't realize my app was running slow until I implemented the mysql indexes below- no formal benchmark testing, but I would say speed improved by about 300%.  The improvement was most noticeble when you are building your ACL using the CakePHP suggested method.

Controlling CakePHP Error Handling When Debug = 0

Posted on 04/19/2010 at 04:27 pm | Viewed 27,518 times | 1 comment

I finally had a client request a piece of functionality that required me to program CakePHP so I could better control the default error handling when the site is in production mode (i.e. debug is set to 0).  By default, CakePHP will throw a 404 page not found header whenever ANY errors occur on a production site with debug equal to zero.  This works great, most of the time.  But what about when you are having database connectivity issues?  Say when there are too many mysql connections to that overloaded shared hosting box?  Modifed CakePHP error handling to the rescue.

Cache Results from Query in CakePHP

Posted on 03/24/2010 at 11:18 am | Viewed 14,910 times | 0 comments

I have a HUGE query that I wanted to cache.  I love CakePHP's caching functionality out of the box, but one thing is missing- you can't cache the results of a query.  Let me clarify.  You can cache the reults of a query, but only for that instance of a page load.  Using $this->cacheQueries only caches the query to memory, which only lasts for the duration of the page load.  If you want to cache query results to the file system, listen to Miles.

Setting Envelope-From in CakePHP's Email Component

Posted on 03/22/2010 at 05:56 pm | Viewed 17,353 times | 1 comment

I've setup a form that allows customers to sign up for an email newsletter and receive a coupon. I wanted to be able to track the bounced messages in case a legitimate customer's coupon was bounced for whatever reason. As I've learned, setting up the "return-path" for an email message isn't as simple as setting $this->Email->return = 'email@domain.com';  You have to use an as yet undocumented feature... $this->Email->additionalParams;

2 Neat Little PHP Tricks

Posted on 03/16/2010 at 04:15 pm | Viewed 12,144 times | 0 comments

In writing a function to validate bank routing numbers, I came across two simple techniques, that I know I will need to use again:

PHP Trick 1: Remove All Characters Except Numbers from a String

A simple little regex does the trick:

$routingNumber = preg_replace('[\D]', '', $routingNumber);

PHP Function to Validate Bank Routing Numbers

Posted on 03/16/2010 at 04:10 pm | Viewed 21,687 times | 0 comments

I needed to validate that a Bank Routing Number was valid, much like the algorithms out there to check if a Credit Card number is valid.  I did a little searching and didn't find a PHP function that would do the trick.  I decided to write my own, based on this javascript function, and publish it for anyone who wants to use it:

Create a Checklist Group or Related Checkboxes in CakePHP

Posted on 03/05/2010 at 12:38 pm | Viewed 43,208 times | 1 comment

This is an interesting one.  I needed to create a group of checkboxes.  In my mind, it's just like a radio button group, except with checkboxes.  The only difference should be that with radio buttons you can only select one, while with a checkbox group you should be able to select as many as you want.  To achieve a checklist group in CakePHP is a little convoluted.

Export to PDF from Microsoft Publisher

Posted on 03/05/2010 at 10:54 am | Viewed 11,886 times | 0 comments

I have a client that sends me newsletters in Microsoft Publisher format.  I wanted to output the newsletter as a PDF, but wanted to keep the text for SEO and so users can copy and paste the text if needed.  Microsoft Publisher doesn't have an export to PDF function, so usually I would just do a File > Print and select Adobe PDF as the printer.  However, this would just be an "image" of the document, not the actual document with selectable text.  This is how you can get a PDF with rendered text out of Microsoft Publisher...

Which Submit Button was Clicked in CakePHP? Use Name.

Posted on 03/04/2010 at 12:01 pm | Viewed 25,721 times | 2 comments

If you want to have multiple submit buttons that make a form do different things there's a simple way to do this.  The name of the submit button that was clicked by the user will be sent (via POST) with all the other POSTed data.  This is very handy if you want to have a cancel button and continue button. In CakePHP the name of the button won't be in $this->data, but it's easy enough to get...

PHP Break Out of All Foreach or While Loops

Posted on 02/25/2010 at 02:44 pm | Viewed 22,941 times | 0 comments

Let's have some fun with PHP's break command... I didn't think it was possible.  I just learned (I've been programming PHP for like 7 years) that you can instruct break how many levels of nesting to break out of!  I'm not surprised that break in PHP allows you to specify the number of loops (or switch statements) to break out of, but I am surprised it took me this long to use it!

Changing the Order Sequence of CakePHP Behaviors

Posted on 02/25/2010 at 07:20 am | Viewed 12,848 times | 0 comments

For reasons too long to explain in this post, I have two behaviors that are run on the same pieces of data (a translate behavior and a settings import/export behavior).  One behavior is attached to the model using var $actsAs, while the other behavior is attached dynamically, during runtime using $this->attachBehavior();.  I needed the "hardcoded" behavior to run after the dynamically attached behavior.  Here's what I did:

Best CSS Method for Using Image as Submit Button

Posted on 02/03/2010 at 12:17 pm | Viewed 21,131 times | 2 comments

I came across an interesting issue with web forms and CSS.  Surprisingly, the end result is much better than I expected.  I knew that using an image instead of a traditional form submit button (<input type="submit">; instead of <input type="image"> or <input type="button">) would be a little challenging.  I like a challenge, plus I wanted to use the submit button because it's the standard approach to forms and I remember reading somewhere that input's of type image or button do not submit when you press enter...a usability faux paus in my opionion.

Using Jquery for target="_blank" and strict xHTML

Posted on 12/28/2009 at 03:27 pm | Viewed 14,949 times | 0 comments

If you like to see the little green check mark that HTML Validator shows when your HTML is 100% valid, you'll love this little trick. Thanks to badlydrawntoy.com

CSS Min-Height Hack in Internet Explorer

Posted on 12/15/2009 at 10:18 am | Viewed 13,945 times | 0 comments

Another day of web developing with CSS and another day of needing a hack for IE6 and IE7.  This isn't really a hack so much as it's a method of ordering statements in your CSS declaration that yields a working min-height declaration in Internet Explorer.  Well, I guess it's a hack (but I hate using them).

CSS min-height will be used in browsers that support it

Viewing Rendered Email Messages in CakePHP

Posted on 12/09/2009 at 12:15 pm | Viewed 20,686 times | 1 comment

For a while it's bugged me that I wasn't able to see the rendered output of my email messages that are sent using the CakePHP email component. I would change my code to use a remote smtp server but I still had to send messages.  Well, I finally figured out how to "debug" my emails sent using CakePHP.  Thanks to this posting for finally putting all the pieces together...

Jquery Accordion Menu - Expanding UL Menu

Posted on 11/17/2009 at 01:25 pm | Viewed 32,867 times | 0 comments

I looked around and found some interesting examples and existing plugins for creating an accordion menu in Jquery.  What I was looking for was a nested unordered list (UL) that would collapse and expand based on which menu item was clicked.  If there wasn't a child UL, then the menu link should be clickable, instead of an accordion.  Sounds simple right?

Jquery Direct Descendant Selector (using the >)

Posted on 11/17/2009 at 01:08 pm | Viewed 14,387 times | 0 comments

I'd been struggling with a very simple accordion menu script.  The problem was that I couldn't stop all of the links from returning false, when I only wanted to top link to return false.  Let me show you my code:

$('div#sideNav li:has(ul) a').click(function() {
	return false;
});

Auto Columns with Columnizer - My New Favorite Jquery Plugin

Posted on 09/30/2009 at 10:37 am | Viewed 21,401 times | 2 comments

I was about to start coding a CakePHP helper that would analyze a bulleted list and split it into columns.  Starting to think about how I would approach this problem, my head began to hurt.  Then I found an awesome jQuery plugin- columnizer.

CSS Small-Caps Working in IE Not in Firefox

Posted on 09/24/2009 at 11:03 am | Viewed 14,792 times | 0 comments

Another IE/FF Inconsistancy?

I thought I had ran into an interesting (and new) CSS bug.  I was using Trebuchet MS as my font for my H2s.  It was rendering perfect in Internet Explorer but not in Firefox.  In Firefox, all caps.  In IE, small-caps.  What gives?

Small-caps only working in Internet Explorer?

A Really Good Implementation of Captcha

Posted on 09/22/2009 at 02:45 pm | Viewed 11,270 times | 0 comments

Awesome Captcha Implementation

I just experienced a version of Captcha that I actually like.  Instead of having to type in jumbled letters and phrases or answering simple questions, Service2Client actually asks you to identify the color of the letter in a certain position.  Not only does it fool spambots (I would assume anyway) but it's pretty easy to understand.

Full Tag List

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design