Category Archives: Frameworks

11 Things which every developer would do when starting a new project

For every project which is going to be started there are at least 11 things which you need to do before. Here is my list of things which need to be happen before starting any project. During my work experience I’ve started many projects and I think that these are the most important issues which you need to do before start the project.
Continue reading

CakePHP and Oracle – Handling CLOB fields

New year – new behaviour 😀

Everyone who had experience in Oracle and some frameworks /or at least ADO libs/ experienced the problem of ORA-01704: string literal too long. For the people who hadn’t pleasure to work with oracle – Oracle accept strings in SQL to be not longer than 4000 characters. I always had problems with this issue, because when the sting is too long you need to treat it with oracle variables and binding them in strange way /at least not with ordinary SQL/. The only way found so far is the solution of ADOdb library.
Continue reading

Check for existing children behaviour

In some of my projects I had a requirement to prevent deletion of the records, which had children. That’s why I create a small behaviour which checks these cases and prevent this.

Add this code in /app/models/behaviours/has_children.php

<?php
/**
 * Prevent deletion if child record found
 *
 * @author    Nik Chankov
 * @url    http://nik.chankov.net
 */

class HasChildrenBehavior extends ModelBehavior {
    /**
     * Empty Setup Function
    */

    function setup(&$model) {
        $this->model = $model;
    }
   
    /**
     * Run the check and cancel the deletion if child is found
     * @access public
     */

    function beforeDelete(){
        if(isset($this->model->hasMany)){
            foreach($this->model->hasMany as $key=>$value){
                $childRecords = $this->model->{$key}->find('count', array('conditions'=>array($value['foreignKey']=>$this->model->id)));
                if($childRecords > 0){
                    return false;
                }
            }
        }
        //Checking habtm relation as well, thanks to Zoltan
        if(isset($this->model->hasAndBelongsToMany)){
            foreach($this->model->hasAndBelongsToMany as $key=>$value){
                $childRecords = $this->model->{$key}->find('count', array('conditions'=>array($value['foreignKey']=>$this->model->id)));
                if($childRecords > 0){
                    return false;
                }
            }
        }
        return true;
    }
}
?>

Continue reading

Storing the settings into database

Today I would like to show you how I am storing and fetching the settings for my applications in CakePHP. The reason why I am doing this is pretty obvious – once the application is complete and installed it’s better to have settings such as

  • How many rows per page to show in the paginated table
  • Where is the upload dir for the files
  • What is the Date format used in the application

And many other.
Continue reading

10 reasons to choose CakePHP as Framework

Two months ago I wrote about benefits of Community Frameworks compared with Home-Grown ones. In the article I mentioned some of the benefits of Cake, but it was “scratching the surface” rather than complete info.
Here I want to list all those things, but near to each of them I will give short explanation what is it and how CakePHP implement it.

So, if somebody ask me what are those 10 things which drive me to choose this framework as my primary one I will answer with:
Continue reading

CakePHP and Layout – secret of data passing through

In my current project I need to deal with the Layout more than adding some header, static menu and footer in it. I need to have dynamic menu loaded from the database plus additional blocks which will contain some data related to the main content. For example YouTube.com /and many other sites/ has some blocks which appear all over the site like related movies block from the right depending from the tags related to the main movie. There are a lot examples.

Well, searching in the CakePHP Manual, CakePHP Google Group or Bakery doesn’t satisfy my understanding how to solve the case. Apart from $anything_for_layout: Making HTML from the View available to the layout article I didnt find anything on this topic. And this one sounds like a hack rather than a complex solution.
Continue reading

CakePHP and Character Set in the Database

Today I found something in the CakePHP which saves me a lot of effort when I need to migrate the database as well as searching for non-English characters from the Database. What is the story:
I had 2-3 projects build with Cake which were for non-English environments. That means the localization of the projects as well as storing proper data into DB with proper encoding. The current project is the same.

In these projects I saw that the data was not stored properly in the MySQL. From the Cake project interface everything looks ok, but when I open phpMyAdmin – the chars looked like strange symbols /not ??? neither &#1239;&&#2934;/. So far I ignored this because as far it is working from CakePHP interface for me everything was ok.
Continue reading

Advanced Datepicker helper for CakePHP

This is a really old post. I’ve wrote a new one which you can find it here


I am using this part of code from long time ago, but it wasn’t in a separate helper. It was part from one not very good written Auth component/helper mash up which I already not using. I fact the default Date input of CakePHP Framework is ugly and not user friendly at all. The drop-downs are good because the format is clear and users cannot mess it, but if you thinking for the user convenience, then you should know that it’s 3 times easier just to type the date in a field or to pick it from a Calendar pop up than selecting from 3 drop-downs.
Continue reading

Modify templates before start baking…

When I start with CakePHP at the beginning I created my views, controllers and models manually. It was a lot of work to do the initial process especially when I still learned the Framework. Then I found /I cannot remember where, probably in another blog/, bake.php script in the {cakeproject}/cake/scripts/ directory which simplified very much the initial process.
Continue reading

Extended Autocomplete Helper

When I started with CakePHP, my first project includes also Autocomplete functionality for some fields. Of course I start using default Ajax Helper provided from the library. The main problem was that in most of the cases I needed the ID of the string which I searched. The best example is the Country list which is very easy to be accessed with Autocomplete, but instead to messing up with strings as usual developer I wanted to have the ID of the specified country. I used some kind of hack by adding callback function onComplete, which checks the selection in the Autocomplete field, and by this selection set hidden ID field, but as you can imagine this is not the best choice, first of all because it’s a hack – you rely on a sting which already sound as a hack /imagine if you are searching in a list there are some duplicated entries – examples are too many/ and second if you rely on callback this mean that you need another second or two for the second responce. Anyway, by giving this examples just wanted to convince you once again that Autocomplete helper with Key and Value related are really necessary in the projects /or at least that’s what I am thinking./

Well so far the default Autocomplete helper doesn’t provide such functionality. That’s why I created this helper which solves this problem partly. Why partly? You will see the answer of this in Strict Autocomplete with Scriptaculous (Part II)
Continue reading