<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5740501090856820042</id><updated>2012-02-16T07:33:07.987-08:00</updated><category term='design pattern'/><category term='Plesk server configuration'/><category term='permissions'/><category term='access control lists'/><category term='magento'/><category term='Joomla'/><category term='javascript'/><category term='webserver administration'/><category term='Zend framework'/><category term='singleton'/><title type='text'>printelectric</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-3873771921130236466</id><published>2012-01-26T09:00:00.000-08:00</published><updated>2012-01-26T11:56:32.919-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Plesk server configuration'/><category scheme='http://www.blogger.com/atom/ns#' term='Zend framework'/><title type='text'>Installing Zend Framework on Plesk server</title><content type='html'>&lt;p&gt;I've been playing with Zend Framework recently, and have a small project that I think would be a good fit for it. So I'm going to try tossing Zend on my Plesk server and see if it's as simple to set up as they say it is.&lt;/p&gt;&lt;p&gt;Poking around my phpinfo output and my server, I'm opting to install to /usr/share/zend/ and update my PHP include path to reflect that. Looking at other posts on similar installations, I think I will also have to update php's open_basedir setting, which I should be able to do for each of the vhosts that will use Zend.&lt;/p&gt;&lt;p&gt;Crossing fingers now...&lt;/p&gt;&lt;p&gt;OK! A couple of adjustments required, but all things considered, pretty painless. First of all, the default application framework created by the zend command line tool (ie. zf create project projectname) will try to load the Zend libraries with an require_once("Zend/Application.php") and drill down from there. To make this work out, I moved the Zend libraries from /usr/share/zend to /usr/share/zend/Zend and then added :/usr/share/zend to the include_path in /etc/php.ini.&lt;/p&gt;&lt;p&gt;So download and uncompress Zend, and then put the contents of the Library folder here:&lt;br/&gt;&lt;pre&gt;/usr/share/zend/Zend&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;On the average Unix install, the php.ini file to edit is:&lt;Br/&gt;&lt;pre&gt;/etc/php.ini&lt;/pre&gt;Just search for "include_path" and add the following after whatever is already there, in between the quotes of course:&lt;pre&gt;:/usr/share/zend&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;You could opt to leave your files in /usr/share/zend or wherever, and add :/usr/share to your include path, but I don't want PHP to be able to include files from everywhere inside my /usr/share folder, which I think is the only other option.&lt;/p&gt;&lt;p&gt;In order for the virtual hosts under Plesk to be configured to work with a default Zend project, you'll need a vhost.conf file here: &lt;pre&gt;/var/www/vhosts/yourhostname/conf/vhost.conf&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;Here's the contents of my vhost.conf file:&lt;br/&gt;&lt;pre&gt;&lt;br /&gt;DocumentRoot /var/www/vhosts/yourdomain.com/httpdocs/public&lt;br /&gt;&amp;lt;Directory /var/www/vhosts/yourdomain.com/httpdocs&amp;gt;&lt;br /&gt;    &amp;lt;IfModule sapi_apache2.c&amp;gt;&lt;br /&gt;            php_admin_flag engine on&lt;br /&gt;            php_admin_flag safe_mode off&lt;br /&gt;            php_admin_value open_basedir "/var/www/vhosts/yourdomain.com/httpdocs:/tmp:/usr/share/zend"&lt;br /&gt;    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;    &amp;lt;IfModule mod_php5.c&amp;gt;&lt;br /&gt;            php_admin_flag engine on&lt;br /&gt;            php_admin_flag safe_mode off&lt;br /&gt;            php_admin_value open_basedir "/var/www/vhosts/yourdomain.com/httpdocs:/tmp:/usr/share/zend"&lt;br /&gt;    &amp;lt;/IfModule&amp;gt;&lt;br /&gt;&amp;lt;/Directory&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;This does a couple of things to override the default httpd.include file (which Plesk writes to configure Apache for your vhost).&lt;/p&gt;&lt;p&gt;First of all, it points the document root down to the public/ directory, which is where the Zend framework expects to find the contents of your web site (css, images, javascript files - &amp;nbsp;anything that needs to load into the browser and doesn't come from a database).&lt;/p&gt;&lt;p&gt;Secondly, it overrides the default value for open_basedir, which would otherwise restrict PHP from loading the Zend libraries (and anything else not under httpdocs). You can set this to "none" if you're brave, but I preferred to only punch a hole through to the Zend libraries. This should keep PHP from accessing any other files on the server that it shouldn't, which is good for security. Otherwise, a malicious (or just poorly built!) script could have access to your entire server. No thanks!&lt;/p&gt;&lt;p&gt;Following these adjustments, I was able to upload the project folders that the zf tool created on my local test server to the "httpdocs" folder, and get the blue-and-green Zend screen of happiness. Yeah!&lt;/p&gt;&lt;p&gt;Just to be completely clear about that last part, the Zend project goes in "httpdocs", not the "public" folder that you specified in the document root. If you've already been using Zend, this will make sense, if not, it will eventually.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-3873771921130236466?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/3873771921130236466/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=3873771921130236466' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/3873771921130236466'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/3873771921130236466'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2012/01/installing-zend-framework-on-plesk.html' title='Installing Zend Framework on Plesk server'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-7343575223173781233</id><published>2011-11-07T09:45:00.000-08:00</published><updated>2012-02-12T20:16:17.969-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='webserver administration'/><category scheme='http://www.blogger.com/atom/ns#' term='permissions'/><category scheme='http://www.blogger.com/atom/ns#' term='Joomla'/><category scheme='http://www.blogger.com/atom/ns#' term='access control lists'/><title type='text'>Permissions settings for Joomla</title><content type='html'>I'm working on a new installation of Joomla Version 1.7.1. For those of you who don't know this, Joomla needs access to several directories in order to read and write cache files, upload images, and install plugins and extensions. If Joomla does not have read and write privileges to those directories, certain functions (some of them vital) will fail. I'm going to give Joomla the access it needs on my Red Hat EL 5.6 server using access control lists.&lt;br /&gt;&lt;b&gt;IMPORTANT:&lt;/b&gt;Use at your own risk. I'm sort of a newbie when it comes to server admin issues. I'm running a RHEL 5.6 server hosted with Softlayer, so I have people to call if I happen to screw something up. My server is also running Plesk, and I'm not sure how that changes the specifics (user IDs, default permissions, whether or not ACLs are enabled). I am NOT covering how to enable and disable access control list support on your drive here. My understanding is that ACLs must be enabled on the drive when it is mounted, and that the drive must be unmounted and remounted in order to turn them on if necessary. Mine were already on, so I'm just covering how to add access control lists to individual files / folders within my Joomla installation.&lt;br /&gt;Step one is probably to find out whether or not you need this. I'm a big advocate of doing absolutely nothing that you don't have to do to your web server. So log in to Joomla as an admin or super admin. Then go to Site -&amp;gt; System Information -&amp;gt; Directory Permissions. You should see a long list of directories, each with a "Status" out to the right, which will either be Writable (good), or Unwritable (bad). For my particular installation, all of these directories ended up being Unwritable, so the commands that follow will add access control lists to enable Joomla (via PHP, via Apache) to read and write to all of these directories.&lt;br /&gt;&lt;b&gt;EXAMPLE&lt;/b&gt;&lt;br /&gt;&lt;pre&gt;setfacl -m u:apache:rwx administrator/components &lt;/pre&gt;The first directory on my list was administrator/components, so my first example should add read, write, and execute privileges to that directory. Breaking it down as follows:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;setfacl -- this calls the setfacl utility if it is available on your system&lt;/li&gt;&lt;li&gt;-m -- tells setfacl that we're going to modify an access control list (in this case we're adding, but -m seems to be the appropriate command for either modifying or adding, from my research)&lt;/li&gt;&lt;li&gt;u: -- we're going to add/modify permissions for a user. If you wished to add/modify permissions for a group instead, this would be 'g:'&lt;/li&gt;&lt;li&gt;apache: -- the name of the user that we're modifying permissions for (followed by a colon). This may be different on your system. I haven't been able to uncover the command to list process names, so you're on your own finding out the name of your apache process. Common values are apache, www, _www - depending on your system. My understanding is that you should be able to find this with &lt;pre&gt;ps -au | grep httpd&lt;/pre&gt;, but I haven't been able to get that to work on my system. Maybe some nice person will throw that in a comment for us.&lt;/li&gt;&lt;li&gt;rwx -- the permissions that we wish to enable. I think we could have gotten by with rw instead of rwx here, and this might be safer from a security standpoint. This probably calls for some more research...&lt;/li&gt;&lt;li&gt;administrator/components -- the name of the directory and or file that you're modifying permissions for&lt;/li&gt;&lt;/ul&gt;That about wraps it up. So without further beating around the bush:&lt;br /&gt;&lt;pre&gt;setfacl -m u:apache:rwx administrator/language&lt;br /&gt;setfacl -m u:apache:rwx administrator/language/en-GB&lt;br /&gt;setfacl -m u:apache:rwx administrator/language/overrides&lt;br /&gt;setfacl -m u:apache:rwx administrator/manifests/files&lt;br /&gt;setfacl -m u:apache:rwx administrator/manifests/libraries&lt;br /&gt;setfacl -m u:apache:rwx administrator/manifests/packages&lt;br /&gt;setfacl -m u:apache:rwx administrator/modules&lt;br /&gt;setfacl -m u:apache:rwx administrator/templates&lt;br /&gt;setfacl -m u:apache:rwx components&lt;br /&gt;setfacl -m u:apache:rwx images&lt;br /&gt;setfacl -m u:apache:rwx language&lt;br /&gt;setfacl -m u:apache:rwx language/en-GB&lt;br /&gt;setfacl -m u:apache:rwx language/overrides&lt;br /&gt;setfacl -m u:apache:rwx libraries&lt;br /&gt;setfacl -m u:apache:rwx media&lt;br /&gt;setfacl -m u:apache:rwx modules&lt;br /&gt;setfacl -m u:apache:rwx plugins&lt;br /&gt;setfacl -m u:apache:rwx plugins/authentication&lt;br /&gt;setfacl -m u:apache:rwx plugins/content&lt;br /&gt;setfacl -m u:apache:rwx plugins/editors&lt;br /&gt;setfacl -m u:apache:rwx plugins/editors-xtd&lt;br /&gt;setfacl -m u:apache:rwx plugins/extension&lt;br /&gt;setfacl -m u:apache:rwx plugins/search&lt;br /&gt;setfacl -m u:apache:rwx plugins/system&lt;br /&gt;setfacl -m u:apache:rwx plugins/user&lt;br /&gt;setfacl -m u:apache:rwx templates&lt;br /&gt;setfacl -m u:apache:rwx configuration.php&lt;br /&gt;setfacl -m u:apache:rwx administrator/cache&lt;br /&gt;&lt;/pre&gt;If you've done any editing at all on your new site, you will have multiple subdirectories in your 'cache' folder. So I'm going to run the ACL addition for the cache directory again with the -R flag for recursive:&lt;br /&gt;&lt;pre&gt;setfacl -R -m u:apache:rwx cache&lt;/pre&gt;This allowed me to clear the cache successfully from Site -&amp;gt; Maintenance -&amp;gt; Clear Cache, which I had been unable to do previously. If you still encounter errors, you might need to re-run additional entries here with the -R flag set.&lt;br /&gt;&lt;p&gt;&lt;b&gt;One last note:&lt;/b&gt; My local test server is a Mac, so their is no &lt;pre&gt;setfacl&lt;/pre&gt; command in the default installation (although I've heard that you can install some additional software to make that happen). The Mac implementation is just a set of options for chmod. So this is a very different command: &lt;pre&gt;chmod +a "userid permissionsToAdd" fileOrFolder&lt;/pre&gt;. For me, this turns out to be something like this: &lt;pre&gt;chmod +a "_www allow read,write,delete" configuration.php&lt;/pre&gt; for files, and &lt;pre&gt;chmod +a "_www allow read,write,delete,add_file,add_subdirectory" plugins&lt;/pre&gt; for directories. Notice the extra directory-specific commands add_file and add_subdirectory. Another thing to note about this command - it is whitespace sensitive, so make sure there are no spaces after your commas in the permission list. That screwed me up the first time around. Also, if you want to catch everything in a directory, you can add -R for recursion (chmod -R +a etc.)&lt;/p&gt;Good luck, and please comment if this helped you out, or if I screwed anything up here.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-7343575223173781233?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/7343575223173781233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=7343575223173781233' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/7343575223173781233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/7343575223173781233'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2011/11/permissions-settings-for-joomla.html' title='Permissions settings for Joomla'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-5943240016199554070</id><published>2011-10-14T21:15:00.000-07:00</published><updated>2011-11-07T10:39:40.890-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='webserver administration'/><category scheme='http://www.blogger.com/atom/ns#' term='permissions'/><category scheme='http://www.blogger.com/atom/ns#' term='magento'/><category scheme='http://www.blogger.com/atom/ns#' term='access control lists'/><title type='text'>Permissions Settings for Magento</title><content type='html'>&lt;p&gt;I'm working on a fresh install of Magento 1.6 to do some testing for a new site, and am reminded of one of the (few) annoying aspects of the Magento installation process. Magento needs write permission to certain files and directories within the installation. This is not a problem, but instead of telling you about all of these at once, Magento tries to access them one at a time, and halts the installation at each level within the directory structure. Anyone who has looked at Magento can tell you that it's not something that you want to monkey with one file at a time, but if you install via FTP and just follow the web installer instructions, that is exactly how Magento will lead you through.&lt;/p&gt;&lt;p&gt;&lt;b&gt;IMPORTANT NOTE:&lt;/b&gt;The commands below are specific to Mac OS X, and probably will not work in any other environment. These commands are being executed from the Magento root directory, so you would have to modify the paths at the end of each line if you want to run them from elsewhere. Finally, the "_www" is the user id of my local Apache server. Depending on your system, this might be different, but is probably something like www, _www, apache, etc. &lt;/p&gt;&lt;p&gt;&lt;b&gt;NEW AND IMPROVED:&lt;/b&gt;I've had to do some additional work on this issue, this time for Joomla, and this time working on a virtual dedicated server running Red Hat EL 5.6. So I'm going to do a separate post which will explain how to solve this same problem on Linux, which is a different set of commands. The basic command is:&lt;/br&gt;&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;br /&gt;setfacl -m u:apache:rwx cache&lt;br /&gt;&lt;/pre&gt;To apply this to your own solution, 'apache' is the user ID of your web server (or whatever user you need to change permissions for), 'rwx' is short for read, write, execute, and 'cache' is the directory or file for which you need to alter privileges. More on this in a few minutes!&lt;/p&gt;&lt;p&gt;&lt;pre&gt;&lt;br /&gt;chmod +a "_www allow read,write,delete,add_file,add_subdirectory" app/etc/&lt;br /&gt;chmod -R +a "_www allow read,write,delete,add_file,add_subdirectory" media/&lt;br /&gt;chmod -R +a "_www allow read,write,delete,add_file,add_subdirectory" var/&lt;br /&gt;&lt;/pre&gt;&lt;/p&gt;&lt;/p&gt;These three lines give Magento 1.6 access to everything that it needs to complete installation. But what did I just do, you might ask? These commands are adding access control lists to three folders in your Magento site. Access Control Lists offer slightly more fine-grained control over permissions than standard Unix permissions. If you think of Unix permissions as a wall, we just removed three bricks. The commands for adding access control lists on the Mac were implemented as options for chmod (which is the standard Unix utility for modifying file permissions. Here's how it breaks down:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The plus sign just after chmod in the first line indicates that we are adding an access control list. Similarly, if you need to remove an access control list entry, that is done with a minus sign (-a)&lt;/li&gt;&lt;li&gt;The quoted string is the actual access control entry, which includes 3 parts, each separated by a space. First is the user for which access is being altered, second is the type of alteration (allow or deny), finally is the list of actions that are being allowed or denied for that user. In this case, the specified user is _www (which is the user that owns the httpd process). The type of alteration is "allow", as we are trying to enable additional access. The included actions are read, write, delete, add_file, and add_subdirectory. Note that this list does NOT include spaces after the commas.&lt;/li&gt;&lt;li&gt;Last but not least, we have to supply the path for the file or directory that we are asking chmod to apply these changes to&lt;/li&gt;&lt;li&gt;Also, notice the addition of the standard -R flag for the second two lines. This applies the access control list recursively to all subdirectories and files within the specified directory. Magento needs access to everything within /var and /media to do its thing...&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The thing that I like about this is that it leaves the original file or folder's owner and group, and their permissions, unchanged. The access control list is an addendum to those permissions. So we don't have to worry about inadvertently enabling or denying access to any other users or groups. Additionally, if this rule doesn't work they way we expect, we can simply delete it, leaving all original ownership and permissions intact.&lt;/p&gt;&lt;p&gt;For more on Access Control Lists, &lt;a target="_blank" href="http://arstechnica.com/apple/reviews/2005/04/macosx-10-4.ars/8"&gt;start with this article&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Good luck!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-5943240016199554070?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/5943240016199554070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=5943240016199554070' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/5943240016199554070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/5943240016199554070'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2011/10/permissions-settings-for-magento.html' title='Permissions Settings for Magento'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-8741282931531166980</id><published>2011-06-20T21:16:00.000-07:00</published><updated>2011-10-18T11:12:17.308-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='magento'/><title type='text'>Magento installation issues</title><content type='html'>I had a few weeks hiatus from my Magento site, but I'm getting back into the swing of it now. Since Magento is relatively complex, and new to me, I got it up and running in my Subversion repos today - so I can back up when I break my Magento installation, which seems like it might happen frequently.&lt;br /&gt;&lt;br /&gt;The way I'm used to working on most sites that I develop is to do most of my major work on my laptop and post changes to the live site as necessary. I periodically back up databases from both locations, and sometimes make changes to data on live sites which I then dump back to my laptop, and vice-versa. Magento makes that process a little more complicated than what I'm used to. First of all, doing a full dump of Magento's database takes more than a few seconds. I did a dump after inputting my first few products, and ended up with 7500+ lines of SQL, or almost 800k. Most of that is table definitions and configuration defaults.&lt;br /&gt;&lt;br /&gt;Secondly, much of Magento's critical configuration data for PHP is stored in database tables. I'm fine with that, but I'm much more accustomed to systems which simply load a config file full of PHP variable declarations. That approach keeps configuration separate from the SQL data, which is nice if you're dumping said data back and forth between a test server and a live server.&lt;br /&gt;&lt;br /&gt;The most obvious issue is that my test and live servers are, of course, on different domains, and the domain names are stored in the SQL data. So dumping the database either direction breaks the configuration on the receiving end. After going through this process a few times, my solution is to do a full dump from my live server, search and replace the resulting SQL file to replace all references to mydomain.com with my local server address. Another side note, Magento does not like localhost, but is fine with 127.0.0.1. So for this operation, I'm searching and replacing mydomain.com with 127.0.0.1/mydomain.com. This works fine for the SQL data, and your local install should be up and serving pages for the front end of your site after you dump the updated SQL into your local database.&lt;br /&gt;&lt;br /&gt;Next up, as one would, I headed straight over to the admin side of the site, and was greeted with a 404 error. The 404 error is loading on Magento's template, so I know Magento is at least routing the request and generating the 404 page (as opposed to the alternative, in which case I might have gotten a 404 from my server, but it would not have ended up in a nice pretty Magento template).&lt;br /&gt;&lt;br /&gt;After googling several solutions to this problem, &lt;br /&gt;&lt;a href="http://blog.chapagain.com.np/magento-error-%E2%80%93-notice-undefined-index-0-appcodecoremagecoremodelmysql4config-php-on-line-92/"&gt;the one that worked for me was here&lt;/a&gt;. I'm not sure how the solution is even related to my 404 error, but luckily there are people out there much smarter than I am who have managed to figure these things out. So per the instructions in the link above, I ran this SQL query verbatim on my local database:&lt;br /&gt;SET FOREIGN_KEY_CHECKS=0;&lt;br /&gt;UPDATE `core_store` SET store_id = 0 WHERE code='admin';&lt;br /&gt;UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';&lt;br /&gt;UPDATE `core_website` SET website_id = 0 WHERE code='admin';&lt;br /&gt;UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';&lt;br /&gt;SET FOREIGN_KEY_CHECKS=1;&lt;br /&gt;&lt;br /&gt;Worked like a charm.&lt;br /&gt;&lt;br /&gt;So now I have my Magento install running well on both my local and remote servers, and at least a workable workflow for getting data from A to B. My next big project is to develop a custom module to create and edit a hierarchical menu for content pages. Full disclosure: &lt;a href="http://www.tsdesigns.de/en/tsdesigns-menubuilder.html"&gt;there's already a very nice hierarchical menu generator here&lt;/a&gt;, but I'm going to suck it up and write my own. I want the experience of digging down a little deeper into Magento, and the price for this is a little much for my current clients. I'll post again once I get into the nitty gritty on the module. Bye for now!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-8741282931531166980?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/8741282931531166980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=8741282931531166980' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/8741282931531166980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/8741282931531166980'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2011/06/magento-installation-issues.html' title='Magento installation issues'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-7711480633552548474</id><published>2011-05-10T21:22:00.000-07:00</published><updated>2011-10-18T11:12:17.303-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='magento'/><title type='text'>Building my first ecommerce site with Magento 1.5</title><content type='html'>&lt;b&gt;Baby Steps&lt;/b&gt;&lt;br /&gt;Hello again. I've been busy with print work for most of the last couple of months, built a small Joomla site as well, but now it's time to get serious. I have an old friend who needs a new ecommerce site, and after some research, I'm taking a crack at Magento.&lt;br /&gt;&lt;br /&gt;First of all, no I'm not crazy. I'm aware that Magento is the man eating shark of ecommerce platforms, and I ain't skeered. I'm diving in. Will it be worth the effort? I'll let you know in a bit. If not, you can read as the entire ugly saga unfolds here. I will be like one of those really awful action TV reality shows. Watched "Wipeout" in the hotel room on a business trip recently. Yeah, if I can't get this site built, it will be like that...&lt;br /&gt;&lt;br /&gt;On to some hopefully useful information. First of all, I will say plan on installing Magento at least &lt;strike&gt;twice&lt;/strike&gt; three times. There is a lot of configuration to do when you first get started, and it will take you a few trips through to get everything really buttoned up... maybe. Secondly, AFAIK there is no sample data for Magento 1.5. So what you get is a blank page once you're through the config. Get used to that feeling. Finally, I will reiterate the warnings from everything else that I've read. This is not going to be a quick, up in a week kind of venture. I've been hacking around in PHP for a good part of the last 6 years, and my first look at the Magento templating structure was pretty daunting. I'm starting to get the hang of it, after about 2 weeks of research and tweaking around on a couple of test sites. I'm hoping to have a working site up within 2-3 months.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Installation I: PHP upgrade&lt;/b&gt;&lt;br /&gt;I'm going to focus on Plesk here, because that's what I've been stuck with. Magento 1.5 requires the following (pulled from &lt;a href="http://www.magento.cn/8/magento-install/magento-system-requirements-following-software-needs/"&gt;Magento China&lt;/a&gt;) :&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;# Linux or another UNIX-compatible operating system (Windows is also supported, but see the Known Issues section below)&lt;br /&gt;# Apache Web Server (1.x or 2.x)&lt;br /&gt;# PHP 5.2.0 or newer, with the following extensions/addons:&lt;br /&gt;&lt;br /&gt;* PDO/MySQL&lt;br /&gt;* MySQLi&lt;br /&gt;* mcrypt&lt;br /&gt;* mhash&lt;br /&gt;* simplexml&lt;br /&gt;* DOM&lt;br /&gt;&lt;br /&gt;# MySQL 4.1.20 or newer&lt;br /&gt;# A Sendmail-compatible Mail Transfer Agent (MTA) – Magento will connect directly to an SMTP server if you don’t have an MTA&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;If you happen to be running Plesk 9.5.1, like me, you're in for some fun. After a failed attempt at upgrading PHP on my server, and a fun day of server down time, followed by an OS reload, I discovered the &lt;a href="http://www.atomicorp.com/wiki/index.php/PHP"&gt;PHP package upgrade for Plesk from Atomic Corp&lt;/a&gt;. This was an absolute lifesaver. After backing up EVERYTHING, I was able to complete this upgrade in a couple of hours, with almost no downtime (just time enough for a server boot). The only gotcha for me was that I didn't have mcrypt loaded. I was able to get that with "yum install php-mcrypt" after completing the rest of the install using the instructions linked above. You will get a warning about a conflict with Sitebuilder somewhere along the way, but can choose to disable sitebuilder. I can't remember exactly how that worked out, but I know that "Edit in Sitebuilder" is now grayed out in my Plesk control panel. Never used it, so I don't know what I'm missing. Everything else was already good to go on my server, so on to Magento.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Installation II: Magento&lt;/b&gt;&lt;br /&gt;If you have SSH access to your server and the right permissions, you can upload the Magento ZIp file and then unzip on the server. This will save some upload time. After it's extracted, you can either leave Magento in it's folder, or move all of the files / folders up one level to your document root. That is what I decided on, as I think Magento is enough to deal with on it's own without cluttering up the site with anything else.&lt;br /&gt;&lt;br /&gt;If you point your browser at http://your-domain.com/, you should now see the first page of the Magento install widget. If not, Magento will probably be telling you to install additional PHP modules. Good luck with that. If you've made it to the install widget, you're golden.&lt;br /&gt;&lt;br /&gt;At this point, you will need to install an empty database on your server, and create a user and grant some permissions for the new database. You'll need a database name, user name, and password to input so that Magento will be able to access your database and create tables. This should be very straightforward if you've ever installed Joomla / Wordpress / Mambo / etc.&lt;br /&gt;&lt;br /&gt;A quick word on the URL issue. Complete the installation on localhost is a bit tricky. Magento does not like localhost. If you substitute 127.0.0.1 for localhost, you're good to go. If you google this, you'll find a hack that will enable you to complete the install using a localhost/domain setup, but it looked kind of cheesy to me. So far I haven't had any issues related to using the IP address for this configuration.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Installation III: The Back End&lt;/b&gt;&lt;br /&gt;OK So I'm falling asleep now. I hope you're more entertained than me. I promise to finish this up in the next couple of days, and hopefully get to the fun part - a working store - pretty quickly. But I'm all done for tonight. Just have time for a beer and a little Medal of Honor ;)&lt;br /&gt;&lt;br /&gt;OK. I'm back again. If you've completed the Install Wizard, and click "Go to frontend", you should be looking at something about like this:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-IyVb9srPUUY/Tcqi8zI5UDI/AAAAAAAAAAg/3T0NUSeQiHY/s1600/home.png" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="255" width="320" src="http://1.bp.blogspot.com/-IyVb9srPUUY/Tcqi8zI5UDI/AAAAAAAAAAg/3T0NUSeQiHY/s320/home.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Yeah. Before you get too excited though, make sure you can log in to the back end. Go to your backend URL, which should be something like http://127.0.0.1/mydomain.com/admin/. Plug in the username and password that you created (and hopefully wrote down) for the installation wizard. If that works, you should see the following:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-cKTSYakh1xE/TcqkKtRidFI/AAAAAAAAAAo/fLOtMD5Ihj8/s1600/backend_home.png" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="252" width="320" src="http://1.bp.blogspot.com/-cKTSYakh1xE/TcqkKtRidFI/AAAAAAAAAAo/fLOtMD5Ihj8/s320/backend_home.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;There are some critical settings on the back end that you should fix before you really get rolling. Number one, make sure the base URLs are set. From the admin dashboard, go to System -&gt; Configuration. When the Configuration page loads, you'll see a menu labeled 'Configuration' at top-left. From there, click on 'Web'. This will bring up a ton of options more or less related to the way page requests are handled. There are two things which we need to edit here, or Magento will complain. Those are the two Base URL entries, one under each of the 'Unsecure' and 'Secure' headings. I don't have an SSL cert installed on my laptop, so I'm using the same URL for both: http://127.0.0.1/mydomain.com/. So far, this has worked just fine for testing purposes. Obviously in a production environment, you will want SSL to be up and running properly, and will need to set these paths to 'httpdocs' and 'httpsdocs' (or whatever your server layout requires).&lt;br /&gt;&lt;br /&gt;Next, I recommend that you disable Magento's caching while you're working to get your store up and running. I have not taken the time to crawl through the code and find out exactly what Magento caches and where, but with the caching enabled I found myself having to stop working and flush Magento's cache every few minutes to see my changes. Obviously, you'll want to revisit this when you migrate to a production server, but for development and testing, the cache is much more annoying than helpful.&lt;br /&gt;&lt;br /&gt;So from the admin dashboard, go to System -&gt; Cache Managment. Click on the "Select All" link at top left, select 'Disable' from the drop-down menu at top right, and then click 'Submit'. You should then see the following:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-KWLEZDG_fwE/Tcqre6Wpg9I/AAAAAAAAAAw/BGhc1GOifmc/s1600/cache_management_disabled.png" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="208" width="320" src="http://1.bp.blogspot.com/-KWLEZDG_fwE/Tcqre6Wpg9I/AAAAAAAAAAw/BGhc1GOifmc/s320/cache_management_disabled.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-7711480633552548474?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/7711480633552548474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=7711480633552548474' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/7711480633552548474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/7711480633552548474'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2011/05/building-my-first-ecommerce-site-with.html' title='Building my first ecommerce site with Magento 1.5'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-IyVb9srPUUY/Tcqi8zI5UDI/AAAAAAAAAAg/3T0NUSeQiHY/s72-c/home.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-738489333528271127</id><published>2010-08-23T20:46:00.000-07:00</published><updated>2011-10-18T11:12:36.075-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><title type='text'>Custom javascript events</title><content type='html'>Howdy. I know a million people have done these, but I never understand anything until I roll my own. So here is my Javascript custom event object. This actually uses the Singleton pattern that I posted previously, so it's a nice follow up. CAVEAT: I haven't tested with Exploder, but I'm more than 10% sure that it will work great...&lt;br /&gt;&lt;br /&gt;I'll come back with some comments here as soon as I'm sure this doesn't cause Exploder to hack and die ;)&lt;br /&gt;&lt;br /&gt;*** UPDATE ***&lt;br /&gt;&lt;br /&gt;IE8 still hacks and dies on the _fire method. Everything looks fine up until the actually apply() call, and IE throws "Object Expected". I am stumped.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;var __eventswitch = function() {&lt;br /&gt; return this.initialize();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;__eventswitch.prototype = {&lt;br /&gt;&lt;br /&gt; classname: &amp;quot;ES&amp;quot;,&lt;br /&gt; &lt;br /&gt; version: &amp;quot;0.8b&amp;quot;,&lt;br /&gt; &lt;br /&gt; count: undefined,&lt;br /&gt; &lt;br /&gt; subscribers: {},&lt;br /&gt; &lt;br /&gt; sub_id: 0,&lt;br /&gt;&lt;br /&gt; initialize: function() { &lt;br /&gt;  if (this.count) {&lt;br /&gt;   return this.instance;&lt;br /&gt;  } else {&lt;br /&gt;   __eventswitch.prototype.count = 1;&lt;br /&gt;   __eventswitch.prototype.instance = this;&lt;br /&gt;   return this;&lt;br /&gt;  }&lt;br /&gt; },&lt;br /&gt;  &lt;br /&gt; register: function() {&lt;br /&gt;  this.subscribers[this.sub_id] = {};&lt;br /&gt;  this.sub_id++;&lt;br /&gt;  return this.sub_id-1;&lt;br /&gt; },&lt;br /&gt;&lt;br /&gt; subscribe: function(id,el,ev,callback,scope) {&lt;br /&gt; &lt;br /&gt;  if (this.subscribers[id][el]==undefined) {&lt;br /&gt;   this.subscribers[id][el] = {};&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  if (this.subscribers[id][el][ev] == undefined) {&lt;br /&gt;   this.subscribers[id][el][ev] = {};&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  this.subscribers[id][el][ev][&amp;quot;callback&amp;quot;] = callback;&lt;br /&gt;&lt;br /&gt;  this.subscribers[id][el][ev][&amp;quot;scope&amp;quot;] = scope;&lt;br /&gt;&lt;br /&gt;  if (arguments.length &amp;gt; 5) {&lt;br /&gt;   this.subscribers[id][el][ev][&amp;quot;args&amp;quot;] = [];&lt;br /&gt;   for (var i=5; i&amp;lt;arguments.length;i  ) {&lt;br /&gt;    this.subscribers[id][el][ev][&amp;quot;args&amp;quot;].push(arguments[i]);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; },&lt;br /&gt;&lt;br /&gt; unsubscribe: function(id, el, ev) {&lt;br /&gt;  if (this.subscribers[id][el][ev]) {&lt;br /&gt;   this.subscribers[id][el][ev] = undefined;&lt;br /&gt;  }&lt;br /&gt;  if (this.subscribers[id][el]) {&lt;br /&gt;   this.subscribers[id][el] = undefined;&lt;br /&gt;  }&lt;br /&gt;  if (this.subscribers[id]) {&lt;br /&gt;   this.subscribers[id] = undefined;&lt;br /&gt;  }&lt;br /&gt; },&lt;br /&gt; &lt;br /&gt; _fire: function(el,ev) {&lt;br /&gt; &lt;br /&gt;  if (arguments.length &amp;gt; 2) {&lt;br /&gt;   var args = [];&lt;br /&gt;   for (var i=2; i&amp;lt;arguments.length;i  ) {&lt;br /&gt;    args.push(arguments[i]);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  this.subscriberLength=0;&lt;br /&gt;  for (key in this.subscribers) {&lt;br /&gt;   if (this.subscribers.hasOwnProperty(key)) {&lt;br /&gt;    this.subscriberLength  ;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  if (this.subscriberLength) {&lt;br /&gt;   for (var i=0; i&amp;lt;this.subscriberLength; i  ) {&lt;br /&gt;    if (this.subscribers[i][el]) {&lt;br /&gt;     if (this.subscribers[i][el][ev]) {&lt;br /&gt;      this.subscribers[i][el][ev][&amp;quot;callback&amp;quot;].apply(this.subscribers[i][el][ev][&amp;quot;scope&amp;quot;],args);&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-738489333528271127?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/738489333528271127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=738489333528271127' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/738489333528271127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/738489333528271127'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2010/08/custom-javascript-events.html' title='Custom javascript events'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-4982941762887917639</id><published>2010-07-26T08:18:00.000-07:00</published><updated>2011-10-18T11:12:36.068-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><title type='text'>Singleton constructor follow-up</title><content type='html'>Here is my Singleton constructor cleaned up for use. You should be able to drop this in, search and replace "ClassName" with the name of the class that you're creating (which, if you like things to be neat and pretty, should of course also match name of your js file). You should only be able to create 1 instance of the class using the constructor function call - new ClassName() - any additional calls will return the 1st instance, instead of creating an additional one.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;var ClassName = function() {&lt;br /&gt;   return this.initialize();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;ClassName.prototype = {&lt;br /&gt;&lt;br /&gt;   classname: &amp;quot;ClassName&amp;quot;,&lt;br /&gt;   &lt;br /&gt;   count: undefined,&lt;br /&gt;   &lt;br /&gt;   initialize: function() {   &lt;br /&gt;      if (this.count) {&lt;br /&gt;         return this.instance;&lt;br /&gt;      } else {&lt;br /&gt;         ClassName.prototype.count = 1;&lt;br /&gt;         ClassName.prototype.instance = this;&lt;br /&gt;         return this;&lt;br /&gt;      }&lt;br /&gt;   },&lt;br /&gt;   &lt;br /&gt;   toString: function() {&lt;br /&gt;      return &amp;quot;[object &amp;quot;   this.classname   &amp;quot;]&amp;quot;;&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Like everything, use at your own risk, no warranties express or implied, etc. But please let me know if you have any questions / concerns / problems.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-4982941762887917639?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/4982941762887917639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=4982941762887917639' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/4982941762887917639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/4982941762887917639'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2010/07/singleton-constructor-follow-up.html' title='Singleton constructor follow-up'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-1396156750320197286</id><published>2010-07-26T02:02:00.000-07:00</published><updated>2010-08-24T20:30:52.458-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='design pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='singleton'/><title type='text'>Playing with a Singleton constructor in javascript</title><content type='html'>Yeah, I know this has been done before, and probably better. But none of the other singleton examples that I'd looked at made sense to me. I'm going to try to break this down as best I can:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;/* this will output to console.log - I worked in Actionscript for a while,&lt;br /&gt;   so trace() works for me you can change this to alert() or whatever */&lt;br /&gt;function trace(arg) {&lt;br /&gt;   console.log(arg);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* this really just gives your &amp;quot;class&amp;quot; a name,&lt;br /&gt;   and allows it to return the output of initialize,&lt;br /&gt;   defined below on the prototype object */&lt;br /&gt;var Singleton = function() {&lt;br /&gt;   return this.initialize();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* defining the prototype object here */&lt;br /&gt;Singleton.prototype = {&lt;br /&gt;&lt;br /&gt;   /* sometimes it's nice to know what kind of object you're&lt;br /&gt;        dealing with, and this enables you to trace(this.classname) to&lt;br /&gt;        check that you're dealing with at least the right type of object ; ) */&lt;br /&gt;   classname: &amp;quot;Singleton&amp;quot;,&lt;br /&gt;&lt;br /&gt;   /* init a counter so that we can prevent multiple instances&lt;br /&gt;       of the class from being created */&lt;br /&gt;   count: 0,&lt;br /&gt; &lt;br /&gt;   /* this function is called with &amp;#39;new Singleton()&amp;#39; */&lt;br /&gt;   initialize: function() {&lt;br /&gt; &lt;br /&gt;       /* check to see if count is defined... */&lt;br /&gt;       if (this.count) {&lt;br /&gt;           /* if so, we return the single instance of the class, which was created in a previous call */&lt;br /&gt;           trace(&amp;quot;returning first instance&amp;quot;);&lt;br /&gt;           return this.instance;&lt;br /&gt;       } else {&lt;br /&gt;           /* if count is undefined, we will set it to 1 */&lt;br /&gt;           trace(&amp;quot;creating and returning first instance&amp;quot;);&lt;br /&gt;           Singleton.prototype.count = 1;&lt;br /&gt;         &lt;br /&gt;           /* if this branch of the initialize function is executing,&lt;br /&gt;               then this must be our first call to Singleton (as count was undefined)&lt;br /&gt;               So we need to save the current instantiation object (this) to Singleton.prototype.instance.&lt;br /&gt;               Future calls to &amp;#39;new Singleton()&amp;#39; will return this object */&lt;br /&gt;           Singleton.prototype.instance = this;&lt;br /&gt;           return this;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* prototype is required for this to work, but you can substitute whatever&lt;br /&gt;   event listener structure you use, or just stick onload=&amp;#39;new Singleton&amp;#39;;&lt;br /&gt;   in your body tag like this: &amp;amp;lt;body onload=&amp;#39;new Singleton&amp;#39;; &amp;amp;gt; */&lt;br /&gt;Event.observe(window,&amp;quot;load&amp;quot;, function() {&lt;br /&gt;&lt;br /&gt;       /* creating the first instance of the Singleton object */&lt;br /&gt;       singleton = new Singleton();&lt;br /&gt;&lt;br /&gt;       /* this should return a reference to the previously-created instance */&lt;br /&gt;       singleton2 = new Singleton();&lt;br /&gt;     &lt;br /&gt;       /* and according to the console the objects are the same... */&lt;br /&gt;       if (singleton == singleton2) {&lt;br /&gt;           trace(&amp;quot;they are the same&amp;quot;);&lt;br /&gt;       } else {&lt;br /&gt;           trace(&amp;quot;they are not the same object&amp;quot;);&lt;br /&gt;       }&lt;br /&gt;     &lt;br /&gt;       /* and furthermore they appear to be the identical object */&lt;br /&gt;       if (singleton === singleton2) {&lt;br /&gt;           trace(&amp;quot;they are identical&amp;quot;);&lt;br /&gt;       } else {&lt;br /&gt;           trace(&amp;quot;they are not identical&amp;quot;);&lt;br /&gt;       }&lt;br /&gt;     &lt;br /&gt;   }&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;UPDATE: Just ran a quick test with Internet Explorer 8, and got good results in IE8 running in all three browser modes (IE8 Standards, Compatibility, and IE7). One note, in my original code I had an extra comma after the initialize function definition. No problem in IE8, but IE7 mode threw an error. One thing I actually respect about Explorer is it's fussiness about proper syntax.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-1396156750320197286?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/1396156750320197286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=1396156750320197286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/1396156750320197286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/1396156750320197286'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2010/07/playing-with-singleton-constructor-in.html' title='Playing with a Singleton constructor in javascript'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5740501090856820042.post-9163326368168254725</id><published>2010-07-26T01:52:00.000-07:00</published><updated>2011-10-18T11:12:56.315-07:00</updated><title type='text'>Here we go...</title><content type='html'>Just getting started here. I guess a little about me. I'm a graphic designer and sometimes a programmer. My plan here is to post up some code, links, other things that I've found to be helpful or interesting - in the hope that I can help others figure out some of the same problems I've been working on. Also, I work alone, which I don't mind generally. But sometimes I feel like I'm reinventing the wheel badly... badly. So I'm hoping also to get some feedback to let me know whether I'm headed in the right or the wrong direction. Hope your ten seconds here is not a complete waste of time!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5740501090856820042-9163326368168254725?l=printelectric.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://printelectric.blogspot.com/feeds/9163326368168254725/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5740501090856820042&amp;postID=9163326368168254725' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/9163326368168254725'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5740501090856820042/posts/default/9163326368168254725'/><link rel='alternate' type='text/html' href='http://printelectric.blogspot.com/2010/07/here-we-go.html' title='Here we go...'/><author><name>printelectric</name><uri>http://www.blogger.com/profile/12762899723612382547</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
