Cakephp .htaccess

Saturday, July 11th, 2009

After using my own framework for over a year, I finally gave in to using Cake as my new job needed it. When I installed Cake to my local system and then later to my shared hosting platform it wouldn’t use the default CSS and wouldn’t display pretty URLs correctly. For example I had to write localhost/cake_test/index.php/todos instead of localhost/cake_test/todos. This was a .htaccess issue and I couldnt find them coz OS X hides files starting with a dot thinking its a system file. I found a terminal command that could be run and then reboot to view files starting with a dot but I was not very keen on using that.

I could access the .htaccess files from the File>Open command of an IDE and learnt that one of the three .htaccess files was missing. I extracted these again from the downloaded zip and renamed them

root.htacess (from the parent cake folder)
app.htacess (from the app folder)
webroot.htacess (from the webroot folder :P )

Then I uploaded (using FireFTP) to the correct folders online and renamed them by removing the part before the dot. The files obviously vanished on renaming. Now when I refreshed the browser window,  I could get pretty URLs + default CSS!

Here is a downloadable version of the .htaccess files
htaccess

Just a passing thought, TextMate text highlights .ctp files pretty nicely!

PHP Rich text editor for Flash

Monday, January 19th, 2009

If you have created a rich text editor using Javascript’s execCommand and an IFRAME and you intend to use the output inside a Flash textfield, then you may have to change the output from your RTE for the bold, italic and underline commands.

execCommand() for making the selection inside the IFRAME bold will give out something like this:

  • <span style=”font-weight: bold;”>Bold text</span>

And flash expects it to be

  • <b>Bold text</b>

In this situation you can use a bit of regex to convert the style based <span> element to a <b> element like this

//get the content first
var rte_content = document.getElementById(‘rte_content’);
//put it in a string
var str = oRTE.document.body.innerHTML;

//replace the content
str = str.replace(/<span style=”font-weight: bold;”>(.+?)<\/span>/g,’<b>$1</b>’)

Now you can pass the ’str’ to a hidden form element or whichever way you are using to post the content. The same applies to italic and underline…

The dreaded Apostrophe

Monday, November 24th, 2008

I used to find myself stumbling over the humble looking single inverted comma over and over again!

First it was while putting it in a MySQL database,
then while retrieving it,
then while escaping it if magic quote gpc is enabled on the server
then while pulling it in flash through a dynamically generated/updated XML

The new mischief it created was when retrieved from the database and displayed in a textfield so that the user can update the text.

So if i have a string like Hello’s World and it has successfully entered the MySQL database after going through mysql_real_escape_string(), it creates a problem when retrieved inside a textfield. It just doesnt show anything from the single inverted comma onwards… so it just shows


Hello

The same thing can be echoed successfully but in a textfield it fails. Putting htmlspecialchars() on a string with a single inverted comma in it did not solve it either but got me closer to the solution. I had to only specify ENT_QUOTES as the second argument of the htmlspecialchars() function. So

htmlspecialchars($str, ENT_QUOTES)  would give out

Hello’s World

When this string is now pulled inside a text field and then saved again, it wont truncate anything but might show slashes. So it d show

Hello\’s World

Now if I add the stripslashes function, everything works fine

htmlspecialchars(stripslashes($str), ENT_QUOTES)

This post was put here after I had posted the same thing as a problem on the DevShed forum where I asked and answered it myself. a few months ago.

Rich Text Editor for CMS

Saturday, January 27th, 2007

I ve decided I m going to create one CMS system and use it for every project. Same with the shopping cart and the products section of any site. There is a bit of a mental debate regarding MySQL and XML but one of them should be soon finalized. The sole reason for considering XML is ‘it is portable’ and I still need to learn how to transfer a MySQL database from one server to another.

The objective of creating one CMS or shopping cart system is, once that is done then I can concentrate solely on design which is something that has not been done consciously for years now.

Anyway, any good CMS solution should have at least some basic text formatting options when users add content. The solution that I had provided earlier was: Above every ‘textarea’ where the user would insert content, I had written very proudly ‘Feel free to use HTML tags in here!’ Now that was some solution!

I have noticed that useless solutions dont make a big issue, they simply get ignored and die out on their own. So I started hunting for tutorials to make rich text editors for CMS. Fortunately, I came across the following link: http://www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm. It gave me just what I wanted: A text editor that generates code for whatever formating the user does inside the textarea.

Though I still havent checked if the same code gets converted into formatted textarea while editing it!

Avoiding a php page from caching content

Friday, January 12th, 2007

One of the most recent minor problems while test writing code for a site (Desire) was avoiding cached content to be shown on refreshing the browser. When testing, a page is uploaded umpteen times with minor edits in the page. Till some days ago this was not a problem. Since the last few days, Firefox, the browser I use to view pages and to upload files using the add-on(FireFTP), started showing cached content each time I hit refresh or F5. I tried to find some ways to avoid this and primarily the PHP cache control scripts available online offered some solutions where they set the header to not show cache content. None of that worked and I started fiddling with the browser’s(Firefox) settings. Nothing happened. Then I finally opened IE and accessed the Tools > Internet Options

tools.JPG

I clicked on Settings and change the radio button for ‘Check for newer versions of stored pages’ to ‘Every visit to the page

tools2.JPG

Thats it! Now every time the page loads, it loads with the last edited changes regardless of how small they were and how small was the page! The only hassle is, I will have to change this setting back to its default when I need to surf the net or check mails etc. But thats a small price to pay!