Posts in the "Code" Category

  • Just a quick one today, if you find you are having to use nested Set::Extracts or nested foreach loops in your code to extract data then it is possible you have some incorrect associations.
    For instance if you array looks like this:
    Array ( [0] => Array [...]

    Share with your friends and help out this site:
    • Digg
    • del.icio.us
    • Facebook
    • Google Bookmarks
    • E-mail this story to a friend!
    • LinkedIn
    • Live
    • Reddit
    • StumbleUpon
    • Twitter
    • Yahoo! Bookmarks
    Read More...
  • I recently had a bit of a brain block how to do a certain thing in cakePHP – I basically wanted to update a model from a view but not using a GET method (as that would have allowed URL manipulation – and potentially created problems).
    The simple answer (again thanks to Darren at zeen.co.uk) is [...]

    Share with your friends and help out this site:
    • Digg
    • del.icio.us
    • Facebook
    • Google Bookmarks
    • E-mail this story to a friend!
    • LinkedIn
    • Live
    • Reddit
    • StumbleUpon
    • Twitter
    • Yahoo! Bookmarks
    Read More...
  • For a CakePHP n00b the pagination thing might seem a bit complicated. Well to be frank it is in someways. For instance you can only currently paginate stuff easily when there is a model involved!
    For instance here is a pagination with a deep association:

    $this->UserProfile->User->Friend->recursive = -1;
    $this->set(’userFriends’, $this->paginate($this->UserProfile->User->Friend,
    array(’Friend.user_id’ => $userid, ‘Friend.accepted’ => 1)));
     
    $this->set(’userFriendsWaiting’, $this->paginate($this->UserProfile->User->Friend,
    array(’Friend.user_id’ => [...]

    Share with your friends and help out this site:
    • Digg
    • del.icio.us
    • Facebook
    • Google Bookmarks
    • E-mail this story to a friend!
    • LinkedIn
    • Live
    • Reddit
    • StumbleUpon
    • Twitter
    • Yahoo! Bookmarks
    Read More...
  • I sometimes think it is useful to see exactly what variables (and values are being passed to the view in cakePHP), especially if the project you are working on is complex with much pseudo repetitive data.
    A simple solution to do this is to insert this piece of code in your view:

    foreach ($this->getVars() as $name) {
     
    pr($$name);
    }

    Share [...]

    Share with your friends and help out this site:
    • Digg
    • del.icio.us
    • Facebook
    • Google Bookmarks
    • E-mail this story to a friend!
    • LinkedIn
    • Live
    • Reddit
    • StumbleUpon
    • Twitter
    • Yahoo! Bookmarks
    Read More...
  • Right,
    When I started out on this I hit t’internet looking for any kind of hints as to the best way of going about this. The first thing I came across was the use of a Self Referential HABTM relationship ( User<-HABTM->User ), naturally not being the uber Cake Nerd this really didnt work out too [...]

    Share with your friends and help out this site:
    • Digg
    • del.icio.us
    • Facebook
    • Google Bookmarks
    • E-mail this story to a friend!
    • LinkedIn
    • Live
    • Reddit
    • StumbleUpon
    • Twitter
    • Yahoo! Bookmarks
    Read More...

Ad