ostovar:
Hi
CTreeView won’t display when i add createLinks() function
my CTreeView works great with out urls
how can i add url for each nodes??
I have just write something about this. you can find solution here
h3rm
July 8, 2011, 9:05am
22
hav3fun:
Hi again, and thanks for your quick response.
I´ve checked firebug console but there´s no log related to AJAX calls.
I don´t know where is the problem, i´ve spent two days on this when it´s supposed to be quite simple, right?
This is the snippet in my SiteController:
public function actionTree(){
if (!Yii::app()->request->isAjaxRequest) {
exit();
}
$parentId = "NULL";
if (isset($_GET['root']) && $_GET['root'] !== 'source') {
$parentId = (int) $_GET['root'];
}
$sql = "SELECT m1.id, m1.title AS text, m2.id IS NOT NULL AS hasChildren,m1.url "
. "FROM menu AS m1 LEFT JOIN menu AS m2 ON m1.id=m2.id_parent "
. "WHERE m1.id_parent <=> $parentId "
. "GROUP BY m1.id ORDER BY m1.position ASC";
$req = Yii::app()->db->createCommand($sql);
$children = $req->queryAll();
$children = $this->createLinks($children);
echo str_replace(
'"hasChildren":"0"',
'"hasChildren":false',
CTreeView::saveDataAsJson($children)
);
exit();
}
And this is the code in my wiew:
<?php
$this->widget(
'CTreeView',
array(
'animated'=>'fast', //quick animation
'collapsed' => true,
'url' => array('/site/tree'),
)
);
?>
so that my test page is localhost/index.php/site/tree
Can you see where the problem is?
Thanks!
Hi… i tried but get error like:
CDbException
CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]: General error: 1 near ">": syntax error. The SQL statement executed was: SELECT m1.id, m1.name AS text, m2.id IS NOT NULL AS hasChildren FROM tree AS m1 LEFT JOIN tree AS m2 ON m1.id=m2.parent_id WHERE m1.parent_id <=> NULL GROUP BY m1.id ORDER BY m1.name ASC (D:\AppServ\www\yii\framework\db\CDbCommand.php:516)
#0 D:\AppServ\www\yii\framework\db\CDbCommand.php(374): CDbCommand->queryInternal(‘fetchAll’, Array, Array)
#1 D:\AppServ\www\yii\prj\cbj\protected\controllers\SiteController.php(255): CDbCommand->queryAll()
#2 D:\AppServ\www\yii\framework\web\actions\CInlineAction.php(50): SiteController->actionAjaxFillTree()
#3 D:\AppServ\www\yii\framework\web\CController.php(300): CInlineAction->runWithParams(Array)
#4 D:\AppServ\www\yii\framework\web\CController.php(278): CController->runAction(Object(CInlineAction))
#5 D:\AppServ\www\yii\framework\web\CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#6 D:\AppServ\www\yii\framework\web\CWebApplication.php(277): CController->run(‘ajaxfilltree’)
#7 D:\AppServ\www\yii\framework\web\CWebApplication.php(136): CWebApplication->runController(‘site/ajaxFillTr…’)
#8 D:\AppServ\www\yii\framework\base\CApplication.php(158): CWebApplication->processRequest()
#9 D:\AppServ\www\yii\prj\cbj\index.php(13): CApplication->run()
#10 {main}
use: sqlite3 and Yii Version 1.1.8
I do not understand the meaning of this syntax:
<=> $parentId
Hi… i tried but get error like:
use: sqlite3 and Yii Version 1.1.8
I do not understand the meaning of this syntax:
<=> $parentId
The explanation for ‘<=>’ is in the wiki page:
Probably an error when used with sqlite3? I’m tied to MySQL as of the moment, can’t test your scenario yet.
BTW,in my example given, I have provided a link to my base theme to retrieve the icons. If your tree does not need an icon, delete that part…it might just cause trouble if not.
I have finished creating an extension which extends to CTreeView and can create links with ease. It can handle both Nested Set and Adjacency List model, and can be used in AJAX calls too!
Extension page: MTreeView
Downloads: MTreeView.zip
Explanation: My Blog
This is the thread I created so can voice out your observations and comments and suggestions.
Edit: updated the links
ostovar
(Ostovarit)
July 11, 2011, 9:57am
27
hi
thanks … it’s work.
when data inserted to the database, how can i update CTreevie with Jquery (without refresh page)??
chriscao
(Labs Net)
July 13, 2011, 7:12am
28
a great work, many thanks~
I have improved the extension so as to make it useful to more “tree-lovers”. Click here to be redirected to the extension’s discussion page.
andromeda
(Daney Andromeda)
May 10, 2012, 2:16am
30
where,
if i call tree from three table??
al_rahim
(Arahimit)
February 6, 2014, 6:31am
31
If I use oracle database then what should be the query to get treeview for the same example?