Yii Framework Forum: CTreeView AJAX Tree - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

CTreeView AJAX Tree Rate Topic: ***** 2 Votes

#21 User is offline   bingjie2680 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 08-June 11

Posted 08 July 2011 - 03:14 AM

View Postostovar, on 02 July 2011 - 02:38 AM, said:

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
1

#22 User is offline   Hermans 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 17-February 11

Posted 08 July 2011 - 04:05 AM

View Posthav3fun, on 30 May 2011 - 09:32 AM, said:

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:

Quote

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

This post has been edited by Hermans: 08 July 2011 - 04:11 AM

0

#23 User is offline   macinville 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 268
  • Joined: 25-October 10
  • Location:Marikina City, Philippines

Posted 09 July 2011 - 11:06 AM

View PostHermans, on 08 July 2011 - 04:05 AM, said:

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:

Quote

...
We suppose here that the corresponding nodes (the root nodes) have a parent_id set to NULL. In SQL, "=" can't compare a value with NULL, so we have to use the <=> operator instead.
...

Probably an error when used with sqlite3? I'm tied to MySQL as of the moment, can't test your scenario yet.
Tell your tail.
Don't be shy to upvote a post if it was able to help you
0

#24 User is offline   macinville 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 268
  • Joined: 25-October 10
  • Location:Marikina City, Philippines

Posted 09 July 2011 - 11:15 AM

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.
Tell your tail.
Don't be shy to upvote a post if it was able to help you
0

#25 User is offline   macinville 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 268
  • Joined: 25-October 10
  • Location:Marikina City, Philippines

Posted 10 July 2011 - 09:00 AM

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

This post has been edited by macinville: 14 July 2011 - 10:13 AM

Tell your tail.
Don't be shy to upvote a post if it was able to help you
3

#26 User is offline   Hermans 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 17-February 11

Posted 10 July 2011 - 10:18 AM

@macinville
thank you :)
0

#27 User is offline   Ostovar IT 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 76
  • Joined: 09-June 11
  • Location:iran, tehran

Posted 11 July 2011 - 04:57 AM

View Postbingjie2680, on 08 July 2011 - 03:14 AM, said:

I have just write something about this. you can find solution here

hi
thanks ... it's work. :D
when data inserted to the database, how can i update CTreevie with Jquery (without refresh page)??
تحلیل، طراحی و برنامه نویسی وب، آموزش "ایی" فریمورک و برنامه نویسی وب، اخبار، مقالات، درج آگهی، استخدام و ... در وب سایت فناوری اطلاعات استوار
www.ostovarit.com
09128157188
0

#28 User is offline   chriscao 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 03-February 10

Posted 13 July 2011 - 02:12 AM

a great work, many thanks~
0

#29 User is offline   macinville 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 268
  • Joined: 25-October 10
  • Location:Marikina City, Philippines

Posted 13 July 2011 - 12:02 PM

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.
Tell your tail.
Don't be shy to upvote a post if it was able to help you
1

#30 User is offline   andromeda 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 02-April 12

Posted 09 May 2012 - 09:16 PM

where,
if i call tree from three table??
0

#31 Guest_midaskkiii_*

  • Group: Guests

Posted 04 June 2012 - 10:58 AM

Where to get a free ivo maker?
0

#32 User is offline   al_rahim 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 24-March 13
  • Location:Jeddah

Posted 06 February 2014 - 01:31 AM

If I use oracle database then what should be the query to get treeview for the same example?
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users