tags:

views:

90

answers:

3

Hi, I got an old PHP system integrated with a new CakePHP one. The problem is when displaying data I occasionally get index undefined errors meaning the models aren't related to where they're supposed to be maybe because there's no validation. There are gaps resulting into models loosing their relationship with a model I'm expecting hence te index undefined error.

What do you guys think is the best way to remedy this issue if let's say I can't touch the old PHP system?

A: 

You could potentially use the model's afterFind callback to massage your data into the correct form.

Travis Leleu
+1  A: 

You can use if (isset($post['Comment'])) style checks before using indexes that may or may not exist as well.

Mark Story
then i'll be putting a lot of if(isset)) in my views.is this the best possible way?
A: 

First, I think empty() is now preferred to isset() as empty checks for nulls, zeroes, and empty strings, as well as whether or not something is set.

Second, if your issue is relating the models then debug($this->model1->model2) is your best friend. It will show you if the models are properly related (It should state model2 object in bold if all is well, anything else and your relations aren't working.).

If you can't touch the old system, you can still make it work and look like cake by creating a cake model for it. Set the model to use no table, and build functions that will shape the resulting arrays and objects into cakephp arrays. Essentially, create a cake wrapper for the old functions. You can use the inflector class to help automate that a bit

stevenf