Browsing articles in "Development"

Configure Imagemagick with PHP on Windows

Since you can’t simply get Imagemagick from a respository and have the legwork done for you, this is a great guide to follow. Once I’ve got a spare minute I will revise this for Zend Server (CE) as you can skip a few steps with that.

http://www.elxsy.com/2009/07/installing-imagemagick-on-windows-and-using-with-php-imagick/

Get column names from a Zend_Db_Table object

If you need to get access to the column names of a Zend_Db_Table object (filtering a list of column names so that you discard any that don’t match up, for example) then as found on StackOverflow you can do the following:

$table->info(Zend_Db_Table_Abstract::COLS);

Which of course works from within the object itself, so you could write a method such as:

public function getCols() {
        return $this->info(Zend_Db_Table_Abstract::COLS);
}

However unlike the documentation says, this does not appear to work…

//return $this->_cols;

Mac OS X Apache not starting properly

Whilst trying to figure out why Zend Server CE wasn’t working properly on my Mac (again…) I realised that something was wrong with the version of Apache shipped with OS X. Luckily Chris Oliver found the problem in the Apache control script.

http://excid3.com/blog/2010/12/usrsbinapachectl-line-82-ulimit-open-files-cannot-modify-limit-invalid-argument/

It’d be nice if web stacks were as simple as on Linux (or even Windows) but you can but dream…

Drupal migration SQL fixes

If you are migrating from a single instance of Drupal to a multi-site installation, you may encounter a problem or two along the way in terms of certain things breaking as they aren’t where they used to be. Since Drupal is almost solely reliant upon the database during it’s bootstrap process, more often than not if something is misconfigured you can end up with the white screen of death (which neither PHP or Apache will be able to pick up)

Theme fixing… (http://drupal.org/node/200774)

UPDATE system SET status=1 WHERE name = ‘garland’;

UPDATE variable SET value=’s:7:”garland”‘ WHERE name = ‘theme_default’;
TRUNCATE cache;

Files fixing… (http://flevour.net/blog/drupal-changing-files-directory-configuration-setting)

UPDATE `files` SET `filepath` = REPLACE(`filepath`, “files/”, “sites/SITEDOMAIN/files/”);

Duplicate records in SQL (duplicating user accounts/privilidges with unique keys and usernames)

INSERT
INTO
users
SELECT
‘newUsername’
,somecolumn
,someothercolumn
,yetanothercolumn
FROM
users
WHERE
username = ‘oldUsername’

Lack of PHP default timezone

It is not safe to rely on the system's timezone settings.

If you see this thrown at the E_STRICT level by PHP, then you need to let PHP know which timezone the server is currently running in, by either running the following function in PHP:

date_default_timezone_set('Europe/London');

… where Europe/London is a supported timezone or setting it in php.ini:

date.timezone = "Europe/London"

Lazy Number manipulation (such as decimal places or precision)

If you want to manipulate a Number Object (variable) to a specific precision or to fixed decimal places, instead of manipulating the Number itself you can use the Number Class conversion Methods such as toFixed and toPrecision and cast the String Objects they return back to Number Objects:

pi = Number(Math.PI.toFixed(2));
trace(pi); // 3.14

Not a replacement for a dedicated rounding function for mathematical formulae, but a handy shortcut to output rounded Numbers in a DataProvider for example.

p.s. Math.round rounds to Integer Objects, as do Math.floor and Math.ceil which is why this can be useful

Variable assignment by value rather than by reference in ActionScript 3 for Arrays

Something that has bugged me a few times, but I needed to figure out this time, as a Flash beginner, is that because everything is an object (and thus an instance of a class, including primatives) you more often than not (unless using primitives/statics) bind everything because you’re always passing variables by reference.

Coming from a Basic/C/Perl/PHP background where you can pass things by either value or reference it took a while for me to figure out how to just copy an array! Since $array2 = $array1; in PHP for example would copy array 1 to array 2, in ActionScript it will bind array 2 to array 1, and weirdly there seems to way (I can find yet) to pass objects by value. But having found the concat function:

array2 = array1.concat();

http://www.kirupa.com/forum/showpost.php?p=2230759&postcount=4

… you can create a copy of array 1 by returning a new Array object with identical contents. Having seen some deep copy examples I’m assuming that most objects come supplied with copy methods so I don’t think it will be a problem in future, but something that newbies to the language may need to be aware of.

Expecting leftParen before something where there is nothing?

An ActionScript Compiler bug that I discovered today (that has been open for 5 years according to Adobe! http://bugs.adobe.com/jira/browse/ASC-2555;jsessionid=0DF58E72CC5A07E2AF4CAC97C7A22005?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel) whereby a compliation error caused in one timeline script will cascade to another without an appropriate warning as to where it was generated.

In other words you may get a compilation error that states you are missing a parenthesis or similar before the first line of code in a layer of your timeline script, which of course makes no sense. However since all layers are compiled into a single pseudo-document class at compile-time (even if you have a Document Class) as far as it’s concerned the preceeding frame containing a script is glued onto it, so the error will have been generated from a timeline script in a layer higher up.

Call to a possibly undefined method addFrameScript

I decided that I should start posting some of the little niggles that I come across everyday, and the solutions that I’ve found, so that other people can find them somewhat easier than I may have (although that means years of PHP problems have been lost in the mists of time!)

addFrameScript is an undocumented method (does not appear in the ActionScript Language Reference) that allows you to *something *something as explained well at troyworks, AS3: MovieClip.addFrameScript

Essentially if you have a Document Class (if using external ActionScript files as opposed to Timeline scripting) that extends Sprite instead of MovieClip, you won’t be able to use Timeline scripting if *something *something

(I will figure this out properly later, but I’m at work now!)

Pages:«123