1

I am fairly new to Lithium PHP Framework but I do know how to use the basic database abstraction method. I am using a plugin to build menu trees and it works great, although I want to use Lithium's abstraction layer for the functions. I'm stuck on this:

public function get_menuItems($menu_id) {
  // retrieve the left and right value of the $root node  
  $result = $this->database->query("SELECT * FROM ".$this->tbl_menu_items." WHERE menu_id = '$menu_id'");
  if ($this->database->num_rows($result)) {
    $right = array();
    $result = $this->database->query("SELECT node.title, node.type, node.class_name, node.content, node.id AS id, node.lft AS lft, node.rgt AS rgt, (COUNT(parent.title) - 1) AS depth FROM ".$this->tbl_menu_items." AS node CROSS JOIN ".$this->tbl_menu_items." AS parent WHERE node.menu_id = '$menu_id' AND parent.menu_id = '$menu_id' AND node.lft BETWEEN parent.lft AND parent.rgt GROUP BY node.id ORDER BY node.lft");
    $tree = array();
    while ($row = mysql_fetch_assoc($result)) {
      $tree[] = $row;
    }
  } else {
    $tree = false;
  }
  return $tree;
}

More so the $result part. I don't know how Lithium could handle all the "AS"'s and whatnot. I tried a few different ways to execute the query as is but no luck.

Any help would be greatly appreciated and I hope I am explaining it well enough.

Teodor Talov
  • 1,933
  • 2
  • 25
  • 39
keithp
  • 352
  • 1
  • 4
  • 13

1 Answers1

0

If your php version is 5.4 you can use li3_tree behavior. Take a look at it, as it is a good example on how to implement such recursive behavior.

Also, I would strongly suggest you to take a look at "Using Models" and "Adding functionality to Lithium models" as your example code could benefit a lot.

Oerd
  • 2,256
  • 1
  • 21
  • 35
  • @keithp: I'm really sorry if I came off too strong, really didn't mean to offend you, just consider that I took a little time off my day to point you to a solution... That said, I'd like to find a way to very politely point you to those resources, but English is just another foreign language for me and it appears that I blew my chance of a good first impression. – Oerd Feb 11 '14 at 18:56
  • You *can* use joins with lithium, you just need to get around it's "array-based" query-syntax and still-in-progress documentation. I'll try to put together an example later on, just so I can make it up :) – Oerd Feb 11 '14 at 18:58
  • Oh gees now I feel like a jerk. I thought you were just another one of those bots who trolls the internet looking for tards ha I do appreciate your help. I also was in a bad mood because I recently had a tooth removed. At any rate, if you do end up compiling an example of a join, that would be fantastic! Hell, if you could even rewrite that query sting, I'll make it up to you somehow. – keithp Feb 17 '14 at 15:50