Christopher Shennan's Blog

A day in the life of…

Browsing Posts in PHP

You have probably come across this already but I have tripped up over this problem a few times.

If you have fields in the db like address_1, address_2, address_3 then the _ is not removed when using getter/setter methods

continue reading…

I was trying to assist someone with the difference between backtics, apostrophes and quotation marks. The three are used in different circumstances and the the basic rules I use with ‘, ` and " are:-

I only use ` in MySQL and only where the field or table name is a reserved word i.e. you have a field called date so the query ends up like

SELECT title, `date` FROM sometable

continue reading…

Today a client was reporting issues with uploading an image via the media section of the diem project administration pages. The error was:-

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘Logo.JPG’ for key 2

I recall having issues with this whilst developing a previous diem based site and the issue turned out to be something rather simple.
continue reading…

I have been working on these 2 projects on and off for a couple of weeks and although it has taken me much longer to package up and write the documentation for these 2 projects, I have finally managed to get them finished to a reasonable state and both projects are available for download.

lineTwit - A PHP Twitter Reader – Original developed at my work (Line Digital) and is based on myTwit by Ralph Slooten

wpTwit -  A WordPress Plugin build using lineTwit to show how it can be incorporated into proper projects.  This site is live example of this plugin in action as I am using wpTwit for the twitter feed in the sidebar.

Many thanks to both Line Digital and Ralph Slooten for allowing me to make these available for everyone to use.

Enjoy!

A week or so I got an unexpected email from Ludek Vodicka asking me to have a look at ORM Designer for creating and maintaining my database schemas for the Symfony projects I have been working on.  Up until now I have been using MySQL Workbench to create my ER-diagrams and maintain my database structure but I’ve come up against a few obstacles when trying to use it with projects using doctrine so I thought why now.

I fully expected ORM Designer to be a MySQL Workbench clone (and it’s obviously been a question that has been raised before – ORM Designer and MySQL Workbench comparison) but I must admit I was pleasantly surprised to find out is was not.  To try and break myself into it easily I opted to start working on the database schema for the re-build of Manage My Alerts which I have intended to re-build using Symfony for quite a while.
continue reading…

Over the last few months I have been working with Symfony and have got used to passing values to methods via an options array but I have recently had to pick up an older project in which the values are passed to the methods by individual parameters.

This has given me a good opportunity to evaluate both techniques and determine my personal preference for working.

The more traditional technique is to pass values to methods using individual parameters as in the example below:-

public function someMethod($name, $age = null)
{
  // do something
}

The benefit I have found with this method is that you can clearly identify what needs to be passed to the method, however, if you need to change the method to include an additional parameter it means that you have to update every call to this method so that every parameter is specified.
continue reading…

Over the last few weeks I have been working on my first wordpress plugin and I am quickly getting to grips with how it all pieces together but I ran into a problem with a rather basic piece of functionality that pretty much rendered the plugin useless until I figured out the issue.

The section I was working on was a form submission (within the wordpress administation) which saved the form values into the database and then redirected the user upon success to another page (using wp_redirect) but this resulted in a blank content pane.

This seems very strange to me as it showed some of the page contents i.e. the header and left navigation but the content pane was completely blank.
continue reading…

A few months ago I posted an article taking about how to get the raw SQL from a Doctrine Query Object but with the release of Symfony 1.3 and Symfony 1.4 it would appear that the code no longer works.  As a result I’ve updated the code to work with Symfony 1.2 – 1.4 and you can find the updated source below:-
continue reading…

csNews Pro

No comments

It’s taken me a while but I’ve finally managed to create the “My Projects” section started although in all likelyhood I’ll not have much time to devote to my projects.

I’ve started off by resurrection an old project that I worked on while I was self employed as Design2Host Ltd.  csNews Pro (formerly V-Desk Newsletter System Pro) has had a few cosmetic details changed (changed the name, removed the licence key limitions) but it’s exactly the same project and it is compatible with the paid version that was original available so you can easily convert from the previous paid version across to the free version when any updates become available.

Feel free to download and play with csNews Pro and feel free to give my any feedback on it.

I am often importing data into a symfony project from an existing site or a CSV file and re-writing this data into the fixtures.yml is usually too complicated or time consuming so I end up writing bespoke import actions.

While I am writing these actions I often find that I have to delete the contents of the MySQL tables as you can never write the routine complete and accurate in one go so as you build it up in smaller steps you find that you have to get rid of the previously old data.

This presented me with 2 problems:-

  • Using DELETE FROM [TABLENAME] does not reset the auto-incrementing fields so if you have anything that is based on the id during the rest of the import then you’re going to have issues.
  • There is a lot of clicking in phpMyAdmin to empty the tables, especially if you forget about the foreign key relationships.

continue reading…