Revision #11 has been created by François Gannaz on May 25, 2012, 11:23:58 AM with the memo:
Added headers and a final note
« previous (#10) next (#12) »
Display an AJAX tree from your DB using CTreeView
This example uses a MySQL DB with a table named `tree` with the fields `id`, `name`, and `parent_id`. The `parent_id` will be `NULL` for root elements. The SQL is kept simple (no autoinc, no FK, etc).
[...]MySQL has no recursive queries. In order to fetch tree nodes, you have to recursively send SQL queries for each node, asking for its children. The easiest way to do so is to send these queries with AJAX, so that the tree can be displayed even if the deep nodes haven't been fetched yet. If you're using Oracle or Postgresql, there are other solutions, though this will also work.
In your view, add:
This will create a tree widget [CTreeView](http://www.yiiframework.com/doc/api/1.1/CTreeView/) on your page, and its data will be fetch
using the `ajaxFillTree` of the current controller.
So we have to add this action to the controller:
The `exit()` might not be necessary, but if you enabled the logs to Firebug or extensions like a debug toolbar, then Yii
write some JS at the end of your response
, and it will break the JSON format.