Archive

Archive for the ‘Zend Framework’ Category

Non-existant fields Zend_Db_Table_Abstract

December 20th, 2008

I'd run into a problem in the Zend Table where when inserting data from a form, if a field didn't exist in the database ZF would crap out with an exception. Having to unset posted variables I didn't need, meant more typing, more typing meant more unnecessary code.

I found the easiest way to get around this is by overriding the insert method in my extended App_Db_Table_Abstract class. Here's what my new insert method looks like.

  1. public function insert($data, $skip = true){
  2.  
  3. if($skip === true){
  4. $oldData = $data;
  5. $data = array();
  6. foreach($this->info('metadata') as $key => $value){
  7. if(isset($oldData[$key])){
  8. $data[$key] = $oldData[$key];
  9. }
  10. }
  11. }
  12.  
  13. parent::insert($data);
  14.  
  15. }

The method takes two parameters, the data ($data) and a Boolean value ($skip). Skip defaults to true, so I don't need to add this parameter to every call to insert, it's also there in case I don't want to skip my data.

It then iterates through the table meta data, which contains the field names for the table, checks to see if the key exists in the data from the form. If the field exists in the array then it's added to the new data array.

Finally the parent insert method is called, bobs your uncle.

In case you're wondering, I've subclassed some of the Zend classes, this allows me to override methods to my liking.

PHP, Zend Framework ,

Zend_Acl Db Storage

July 25th, 2008

I've spent the last few hours trying to extend Zend_Acl_Role_Registry and Zend_Acl to support Db storage, when it just hit me what I'm actually trying to do, and a much easier way to do it!
Read more...

PHP, Zend Framework , ,

Zend Framework and DoJo

July 23rd, 2008

I pretty much wet my self when ZF announced that they'd be integrating Dojo with the next iteration, and low and behold the first RC was made publicly available a few days ago. I literally dived in head first today, only to find the documentation was some what lacking.

I don't think the documentation is quite complete, but hats off to ZF for taking a step in the right direction.

Here's a quick tutorial on using Dojo's container's and pane's with ZF. I've added line breaks so it fits into the old blog.

Read more...

Dojo, Javascript, PHP, Zend Framework , , , ,