Archive for the ‘ cakePHP Interview Questions ’ Category

These magic functions can be used as a shortcut to search your tables by a certain field. Just add the name of the field (in CamelCase format) to the end of these functions, and supply the criteria for that field as the first parameter. PHP5 findBy Example $this->Product->findByOrderStatus(’3′); //Product.order_status = 3 $this->Recipe->findByType(‘Cookie’); //Recipe.type = ‘Cookie’ $this->User->findByLastName(‘Anderson’); //User.last_name = ‘Anderson’ $this->Cake->findById(7); //Cake.id = 7 …

MODEL VIEW CONTROLLER is a software architecture that is used to isolate business logic from presentation logic. Cakephp is based on MVC pattern. What are 3 important parts of MVC? 1. The Model represents the application data 2. The View renders a presentation of model data 3. The Controller handles and routes requests made by the client

Table names are plural and lowercased. Model names are singular and CamelCased: ModelName. Model filenames are singular and underscored: model_name.php. Controller names are plural and CamelCased with *Controller* appended: ControllerNamesController. Controller filenames are plural and underscored with *controller* appended: controller_names_controller.php Associations should use the ModelName, and the order should match the order of the foreignKeys: var $belongsTo = ‘User’; Foreign keys should always …

The Role of CakePHP

 on February 22, 2010

CakePHP was critical to the project’s success. Here I emphasize what we consider are some of the main advantages of using the Framework. It offers many useful, ready-to-use tools. CakePHP prevents us from having to “reinvent the wheel” every time. For common problems that must be solved when using an application of medium complexity, CakePHP already provides a solution. In our case the …

With CakePHP, the controller core automatically detects the file name of the view file which needs to be rendered from a controller action. You might want to reuse an existent view for an action or specify a different file name. For example, if you have a controller named “Users” and you execute a controller action named “profile”, the view file “users/profile.ctp” will be …

return $this->LogfileRecord->find(‘all’, ‘conditions’ => array(‘LogfileRecord.date between ? and ?’ => array($start_date, $end_date)));

I use it in this way. //If member_image will empty then set ‘no-photo.jpg’ as default image $thumb_photo = ife($member['Member']['member_image'], $member['Member']['member_image'], "no-photo.jpg"); Optional: Then call it in the image tag and apply clearbox if you want; <a rel="clearbox" href="<?php echo $GLOBALS['ABSOLUTE']['PATH'];?>/img/members_photos/<?php echo $thumb_photo;?>" target="_blank"> <?php echo $html->image(‘members_photos/thumbs/’.$thumb_photo, array(‘alt’ => ”, ‘border’ => ’0′, ‘width’ => ’141′, ‘height’ => ’137′));?> </a>

function deletephotograph($id){ //Get File/Image name $data = $this->Propphotograph->find(‘first’, array(‘conditions’ => array(‘Propphotograph.id’ => $id), ‘fields’ => array(‘Propphotograph.photograph’))); $image_name = $data['Propphotograph']['photograph']; // Use fileExistsInPath() function to check valid File/Image Path $thumbPath = ‘img/props_photographs/thumbs/’.$image_name.”; $imagePath = ‘img/props_photographs/’.$image_name.”; if (fileExistsInPath($imagePath)){unlink($imagePath);} // Delete Image if it exists if (fileExistsInPath($thumbPath)){unlink($thumbPath);} // Delete Image Thumb if it exists $this->Propphotograph->delete($id); // Delete Record $this->Session->setFlash(‘The photograph has been deleted.’); $this->redirect($this->referer()); }

I had a situation where I needed to iterate through a list of items and insert new rows for each. I quickly discovered that if you insert an item and then immediately insert another, the item that is inserted next doesn’t insert at all. Instead the previously inserted row was being updated. For example: $items = array(‘Item 1′,’Item 2′,’Item 3′); foreach ($items as …

The Cake is Still Rising

 on February 4, 2010

Recent weeks have seen a few changes in the development team, as well as some clarification of the road map for CakePHP future releases. We’d like to thank those leaving for all their hard work and contributions. For those sticking around, you are in for a treat! CakePHP Project Manager Garrett Woodworth and Developer Nate Abele have left the CakePHP development team. The …