Lithium Framework MySQL raw query

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, 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 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.


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.

Need Your Help

how to search web content with blobs or long strings

python django google-app-engine full-text-search

According to