If your concrete5 block form won't save..

Make sure that the form itself is valid(double and triple check your opening and closing divs and all other html tags. Sometimes in more complex blocks with multiple ifs on say if($this->controller->getTask() == "edit") /* if you are using one form for add and edit via $this->inc on add.php and edit.php as I'd recommend */  then you can inadvertenly end up with invalid html. When you try to save the block edit or add, it seems like nothing happens, you'll watch it in firebug and see the request doesn't fire.  So always double check that before looking at anything else :)

 

Concrete5 CollectionAttributeValues

Here's a relatively minor thing I came across. For a client I had a project where they needed multiple dropdown sortable lists of pages based on CollectionAttributeValues that have controller of: "SelectAttributeTypeController", you know the ones that allow multiple or single select dropdowns.

So the issue we came across was that if you had a CollectionAttributeKey with an attribute type of select, when it is associated with that collection's collection type, by default this is set to NULL.  The specifications for this app at the time were that they wanted to select everything that didn't have a value, which could by default be accomplished by:

$pl->filterByAttribute($attributeKeyFilter->getAttributeKeyHandle(), NULL,'IS NOT'); 

This will work if something never had the particular attribute(in this case $attributeKeyFilter) set at all. If this filter was set, then it was changed to or back to none, then you would think that the column/value would be set back to NULL, or ''.  Actually, in this particular instance, it was set to "\n", which required either looking at it through the command line or checking out the actual value of the field in phpmyadmin using firebug or similar.

So

$pl->filterByAttribute($attributeKeyFilter->getAttributeKeyHandle(),"\n",'!='); 

//you might want to experiment with other filters

is also needed(at least in my case) if you are trying to filter by something that isn't "blank", even after the CollectionAttributeKey has been changed for a particular collection.

Mysterious numbers while using PHP printf? here's what causes it.

About a week ago, I had this number coming up randomly, and I had no idea what was causing it. The code looked ok, it didn't throw an error or anything..so I didn't know where in the heck the number was coming from






<?php echo printf('An awesome %s %s','developer?..really?','http://scottconrad.posterous.com','Scott Conrad'); ?>


Some people don't like printf, but I seem to find it nice when you don't want to concat a bunch of strings together, this is just an example.

the code above produced the following text

An awesome developer?..really?Scott Conrad90

So where's the 90 coming from?  

I don't know exactly, but it is caused by combination of echo and printf.



 


<?php printf('A little wiser %s %s','developer?..really?','http://scottconrad.posterous.com','Scott Conrad'); ?>


I can't believe it took years for that to come up :)

Hope that helps someone.

 

New Concrete5 app, start to finish(1.0) 20 hours, need to cut down on that debugging time, jeez

Things I learned,

1.) Use active record. Seriously, go learn it right now.  I had some issues here with $activeRecordClass->load('id = ?',array($id);  it only returned 1?

So I had to use the parent class getByID i inherited from(in my next app) using $activeRecordClass->find('id = ?,array($id); 

this returns an array, which kind of stinks, so you just return if($byID && $byID[0] instanceOf activerecordOrSomething) return $byID[0];

2.) Don't copy and paste. I spent a bit of time getting a tools request to load up an abandoned order.  I copied and pasted some of the coreCommerce code into the tools folder, got that looking good.  Then I realized that there is no way that would fly, and while I've seen my code and coreCommerce code in other apps, I don't want to do that.  So instead I am loading up using jquery load method into a hidden div, then passing that over to the ccm-dialog.  It is the right thing to do, but more importantly I was able to leverage any changes that the concrete5 team does to spruce that stuff up by loading it in that way, AND since i wasn't duplicating code it was win win. If they do some wicked javascript or css stuff as long as they load it from the controller i can always extend that controller and call the parent to make sure their stuff gets loaded correctly.

3.) I finally feel like I am getting pretty good at this stuff :)

Screen_shot_2011-01-27_at_10
So if you need something like this created(well if you need this, buy it here)  or you have some interesting concrete5 development work you want me to guesstimate and work on(budget $800+ only please), feel free to contact me at scott.conrads gmail

 

 

 

SPL LimitIterator when you don't need to

So, if you have some items and you only want the first 10, in this case we have an $feeds array. if($feeds) Some use if(is_array($feeds) && count($feeds)) but if($feeds) returns false if the array is empty, so you can save yourself some typing. One can also use !empty($feeds) which I think is easier to read, but everyone has their own style.

if($feeds && $this->itemCount) $feeds = new LimitIterator(new ArrayIterator($feeds), 0, $this->itemCount);
return $feeds;

Looks cool, will get you some street cred, etc etc.

return array_slice($feeds, 0, $this->itemCount);

Not nearly as cool looking, but does the job much better and is surely more optimized(and you aren't slinging objects around :)