Multiple Combo boxes with YUI and CakePHP

Ajax, CakePHP, YUI

As a developer, I hate writing similar code for the same process over and over again. Just like highly optimized database design, developers should always try to write code as efficiently as possible.

I’m working on a project where I use YUI and CakePHP to fill multiple combo boxes on a page using Json data. At first, I wrote separate code with the same functionality for each combo box. Every time I needed to change the functionality, I had to change it for each combo box. After doing this multiple times, I decided to combine the functionality on both the front-end (YUI) and the back-end (CakePHP).

Continue reading

Checkout My New Site - T-shirts For Geeks

YAHOO.util.Connect, CakePHP, Json Data

Ajax, CakePHP, YUI

I’ve been upgrading an Intranet application that I created for a client. I created the front-end using YUI (Yahoo! User Interface Library) and I am working on migrating the back-end to CakePHP. After setting up CakePHP, my first step of integrating YUI with CakePHP is retrieving data ajaxally. The application was already using YAHOO.util.Connect to retrieve the data, but I had to change my parsing code due to the format of the Json data that is returned by CakePHP.

Continue reading

Checkout My New Site - T-shirts For Geeks

CakePHP Session Write Auth Error

CakePHP

I justed received an error when logging into a CakePHP app. It was the Auth Component error:

you are not authorized to access that location

It occurred when I attempted to create two session variables:

if ($loggedIn == 1) {
	$result = $this->User->findByUsername($this->Auth->user("username"));
	if ($result) {
		$this->Session->write('User.langID', $result['User']['language_id']);
		$this->Session->write('User.cntryID', $result['User']['country_id']);
		echo '{"type":"continue"}';
	}
}

Because one generally receives this error message when attempting to access a page that is secured by the Auth Component and ACL, I thought that the session component was attempting to write to a restricted area. After a bit of testing, I realized that the User session var (User.langID) was being used by the Auth Component. So I changed User to an application specific variable:

$this->Session->write('rdsStaff.langID', $result['User']['language_id']);
$this->Session->write('rdsStaff.cntryID', $result['User']['country_id']);

No more errors. I hope this will be useful to someone in the same situation.

Checkout My New Site - T-shirts For Geeks

Associating CakePHP .ctp Files in Aptana, Eclipse

CakePHP, IDE

Viewing CakePHP’s .ctp files in Aptana Studio has been quite annoying due to the lack of syntax highlighting. I have grown use to it until earlier today when I was converting a .php file into a .ctp. I knew there had to be a way to associate .ctp files with .php files in Aptana/Eclipse. I did a bit of searching and found the solution.

  1. Go to Window/Preferences/General
  2. Select Content Types
  3. In the right pane, select the Text Navigation tree
  4. Select PHP Content Type
  5. Click the Add button
  6. Enter *.ctp and click Ok

If you have a .ctp file open, you will have to close and re-open it to view the changes. Much better.

Checkout My New Site - T-shirts For Geeks

CakePHP: Baking on Ubuntu

CakePHP, Ubuntu

I have been upgrading an web application for a client. I initially created the application using a custom php framework – spliced together however awkwardly, but it worked. In version 2, I included YUI 2.8, but have been using the same backend.

The site is nearly complete (ajax functionality, and database development), I decided that I needed a more structured php framework. I chose CakePHP primarily because I could bake the models, views, and controllers. With only 17 tables, The application is not very large, but the thought of creating models, views, and controllers for 17 tables did not sound exciting.

I could not bake on my Mac. I got an error, “Call to undefined function mysql_connect()”. I searched for hours trying to figure out why I was receiving the error, but to no avail. I think that I need to re-install PHP. Not going to happen. I instead decided to setup Cake on my Ubuntu box (See my post: Setting Ubuntu For Web Development).

Continue reading

Checkout My New Site - T-shirts For Geeks

CakePHP: Missing Database Table

CakePHP

I started back on a CakePHP intranet application that I haven’t worked on in a while. I received a ‘Missing Database Table’ error when I viewed the application in a browser. The table that was mentioned in the error had been deleted a few months ago and I no longer had a model, view or controller for this table. After a few hours of investigating, I found that I had to delete the cache files (app/tmp/cache) that were created when I initially baked this table.

Checkout My New Site - T-shirts For Geeks

CakePHP: Setting up mod_rewrite on Ubuntu

CakePHP, Ubuntu

After installing CakePHP on my Ubuntu box, I viewed the default home page in my browser and noticed that the page was not styled. Cake did not know the path to the CSS file because I had not enabled mod_rewrite. Although I could opt to setup CakePHP to work without mod_rewrite, I decided to enable it.

Continue reading

Checkout My New Site - T-shirts For Geeks

CakePHP and YUI: CSS File Location

Ajax, CakePHP, YUI

I recently started converting an existing PHP project to CakePHP and YUI 2.8. The first decision that I had to make was where to place the YUI CSS files. I tried to find a quick, yet elegant solution, but I ended up with solution that was not so quick (or elegant).

I copied all of my YUI files from webroot/js/yui/ to webroot/css/yui/. I then opened each folder under webroot/css/yui/ and removed all of the js files (leaving the assets folder). If a folder contained js files only, then I deleted the folder.

I opened each folder under webroot/js/yui/ and removed all asset folders and css files. If a folder contained css files only, then I deleted the folder.

I spent about an hour trying to find another solution, so I guess the few minutes it took to remove the files/folders was worth it.

Checkout My New Site - T-shirts For Geeks

CakePHP: Dynamic Content in Layout

CakePHP

I was working on my first CakePHP project. I created a layout for the project and I realized that the layout was the same for multiple pages in the application – only the content was different. At first, I began to duplicate the layout for the other pages and changed the content accordingly. This didn’t make sense – I hate repeating the same code. CakePHP did not seem to have a way to create dynamic content within a layout. My first thought was to create the project using CodeIgniter’s, but I really wanted to create a web application using CakePHP.

After struggling to find a solution, I finally found the the correct way to create dynamic content with CakePHP.

Note: This post has been rewritten. When I first created this post, I was new to CakePHP. The original post did not display the best solution for creating dynamic content, so I rewrote it.

Continue reading

Checkout My New Site - T-shirts For Geeks