• One Database file - two servers

    By Andy, filed under CakePHP, Tips, Database

    If you have your website on one server for testing/development (like this laptop) and your live site on another, it's quite likely that once in a while your database.php file from one or the other will find itself referring to the wrong database. Over at With Cake a solution was proposed to allow you to switch database sources in the app model, however it might be easier to...

    read more5 comments

  • Prevent Robots from accessing an action

    By Andy, filed under CakePHP, Tips

    If, like on this site, you have some demo applications with some data in them, it's wise to try to ensure that the test data you spent an hour or two creating doesn't get deleted.

    For the demos that were on this site (they'll be coming back after some tweaking) I set up a script to run once per hour to truncate and reimport the test data - thus ensuring that malicious...

    read more2 comments

  • The power of logs

    By Andy, filed under CakePHP, Error, Logs, Phishing

    One of the changes I made to my site recently, was to override the App Error Function to keep track of how things are going wrong. I did this by simply logging all the information available and redirecting the user to a safe page (the home page).

    I've found this to be very useful in general, especially for debugging what was going wrong with multiple inter-plugin...

    read more0 comments

  • Plugins and Routes

    By Andy, filed under CakePHP, Tips, Plugins, Routes

    Routes are a great feature, but if you try using them with Plugins you might find that you start pulling your hair out. Fear not however, there's always a solution and it's usually not that difficult. If you use routes of the form below, you can map directly to a plugin's page:

    $Route->connect('/Something/*', array('controller' => 
    
    'PluginName', 'action' => 'ControllerName',...
    1. $Route->connect('/Something/*', array('controller' =>
    2. 'PluginName', 'action' => 'ControllerName',...

    read more0 comments

  • CakePHP Quick Tips

    By Andy, filed under CakePHP, Tips

    Quite often the question is asked "How can I access XYZ in my controller/view/model etc?". IMO this question rarely needs to be asked ;).

    Using the following simple approach should empower you to answer most questions:

    1. Set DEBUG to 2 in your /app/config/core.php file so you can see the executed SQL whilst you are developing, you can set it to 3 to see a dump of the...

    read more1 comment

  • How to delete an MPTT Node

    By Andy, filed under CakePHP, Tools, ACL, Tips, MPTT, Hacks, SQL

    If you use MPTT tables anywhere (The cake acl system uses it) you may have found that when you delete an entry, the lft and rght fields for the neighouring nodes don't get updated. This may have rather dire concequences ;)

    There is an open ticket for how to delete from the cake acl tables, but as it is potentially quite generic, I thought I'd include the (potential)...

    read more1 comment

  • Elements and Recursion

    By Andy, filed under CakePHP, Tips, requestAction

    A long time ago, I took to using elements as shown in the paste below.

    echo $this->renderElement("Element",$params);
    
    1. echo $this->renderElement("Element",$params);
    2.  

    At the time, this was the only way I could find to pass the information from the view in general to the element. If this was needed at all, it was probably a temporary glitch but I kept to this syntax since that time. It is overkill to do this now, and...

    read more0 comments

  • Where did I put that call?

    By Andy, filed under CakePHP, Tips, Hacks

    In the site update, this little tidbit went missing, so here it is again:

    function pr($var) {
        if (DEBUG > 0) {
            
    
    $array = debug_backtrace();
            echo(str_replace(ROOT, "", $array[0]['file'])." (line ".$array[0]['line'].")");
       
    
         echo "<pre>";
            print_r($var);
            echo "</pre>";
        }
    }
    
    1. function pr($var) {
    2. if (DEBUG > 0) {
    3. $array = debug_backtrace();
    4. echo(str_replace(ROOT, "", $array[0]['file'])." (line ".$array[0]['line'].")");
    5. echo "<pre>";
    6. print_r($var);
    7. echo "</pre>";
    8. }
    9. }
    10.  

    With this minor change, you can see where your debug calls are...

    read more0 comments

 1 | 2 | 3 | 4 | 5 | 6