01.21 php saved
kain
Tags add more
 
Note
I need to keep a level of recursion no more than 2, because otherwise I need to unBindModel too much. I know there's a function that unBindModelExcept anyway I'm not going to use it since it caused me trouble in this case.
TopicLastPostAuthor is not a declared model, so bindModel should work just nice, but I think it doesn't work because of the level of recursion, too low.
I need to obtain the [TopicLastPost][TopicLastPostAuthor] array.
  1.     function view($forum_url) {
  2.         $this->Forum->unBindModel(array('belongsTo' => array('ForumLastPost')));
  3.         $this->Forum->ForumCategory->unBindModel(array('hasMany' => array('Forum')));
  4.         $this->Forum->ForumTopics->unBindModel(array('belongsTo' => array('TopicForum')));
  5.         $this->Forum->ForumTopics->TopicLastPost->bindModel(array('belongsTo' => array('TopicLastPostAuthor' => array('className' => 'User', 'foreignKey' => 'user_id')))); // this doesn't work :(
  6.         $this->Forum->recursive = 2;
  7.         $data = $this->paginate('Forum', array("Forum.url = '{$forum_url}'"));
  8.         if (!empty($data)) {
  9.             $this->paginate = array('limit' => $data[0]['Forum']['topics_per_page'], 'order' => 'Forum.created ASC');
  10.             $this->set(compact('data'));
  11.         } else {
  12.             $this->redirect('/forum', 404, true);
  13.         }
  14.     }
  15.  
  16.  
  17. (
  18.     [Forum] => Array
  19.         (
  20.             [id] => 2
  21.             [forum_category_id] => 1
  22.             [parent_id] => 0
  23.             [forum_post_id] => 1
  24.             [name] => C and C++
  25.             [description] => The most common programming languages.
  26.             [url] => c_and_c_plus_plus
  27.             [topics] => 1
  28.             [posts] => 1
  29.             [order] => 0
  30.             [topics_per_page] => 20
  31.         )
  32.  
  33.     [ParentForum] => Array
  34.         (
  35.             [id] =>
  36.             [forum_category_id] =>
  37.             [parent_id] =>
  38.             [forum_post_id] =>
  39.             [name] =>
  40.             [description] =>
  41.             [url] =>
  42.             [topics] =>
  43.             [posts] =>
  44.             [order] =>
  45.             [topics_per_page] =>
  46.         )
  47.  
  48.     [ForumCategory] => Array
  49.         (
  50.             [id] => 1
  51.             [name] => Software Development
  52.             [order] => 0
  53.             [url] => software_development
  54.         )
  55.  
  56.     [ChildForum] => Array
  57.         (
  58.         )
  59.  
  60.     [ForumTopics] => Array
  61.         (
  62.             [0] => Array
  63.                 (
  64.                     [id] => 1
  65.                     [forum_id] => 2
  66.                     [forum_post_id] => 1
  67.                     [forum_topic_state_id] => 1
  68.                     [user_id] => 1
  69.                     [title] => Il mio primo topic
  70.                     [url] => il_mio_primo_topic
  71.                     [created] => 2007-01-21 00:00:00
  72.                     [reads] => 2
  73.                     [replies] => 0
  74.                     [notification] => 1
  75.                     [sticky] => 0
  76.                     [TopicLastPost] => Array
  77.                         (
  78.                             [id] => 1
  79.                             [parent_id] => 0
  80.                             [forum_topic_id] => 1
  81.                             [forum_id] => 2
  82.                             [user_id] => 1
  83.                             [title] => Il mio primo topic
  84.                             [body] => Questo è il mio primo topic.. sarà una lunga giornata
  85.                             [created] => 2007-01-21 07:02:38
  86.                             [ip_address] => 127.0.01
  87.                         )
  88.  
  89.                     [TopicState] => Array
  90.                         (
  91.                             [id] => 1
  92.                             [name] => PUBLISHED
  93.                         )
  94.  
  95.                     [TopicAuthor] => Array
  96.                         (
  97.                             [id] => 1
  98.                             [user_state_id] => 1
  99.                             [user_group_id] => 1
  100.                             [language_id] => 1
  101.                             [username] => kain
  102.                             [password] => d65be92f2d6db01d4517636b3cbbf6e9
  103.                             [email] => claudio@kuht.it
  104.                             [created] => 2006-12-17 23:55:39
  105.                             [modified] => 2007-01-21 03:07:18
  106.                             [hashcode] => 8yxplajn61209vbgomf7
  107.                             [email_token] => of0jv4kb2dct1386nig5
  108.                             [realname] => Claudio Poli
  109.                             [location] => Milano
  110.                             [interests] =>
  111.                             [occupation] =>
  112.                             [url] => http://www.icoretech.org
  113.                             [bio] => Sistemista e programmatore
  114.                             [birthday] => 1982-10-29 00:00:00
  115.                             [signature] => Claudio "kain" Poli
  116. iCoreTech CEO
  117.                             [license] => Creative Commons
  118.                             [avatar] =>
  119.                             [im_icq] =>
  120.                             [im_aim] =>
  121.                             [im_yim] =>
  122.                             [im_msn] =>
  123.                             [im_jabber] =>
  124.                             [im_skype] =>
  125.                             [show_realname] => 1
  126.                             [show_contact_info] => 1
  127.                             [show_signature] => 1
  128.                             [ip_address] => 127.0.0.1
  129.                             [enable_profile] => 1
  130.                             [enable_notifications] => 1
  131.                         )
  132.  
  133.                 )
  134.  
  135.         )
  136.  
  137. )
Parsed in 0.204 seconds, using GeSHi 1.0.7.14

Modify this Paste