Yii Framework Forum: Giix Dropdownlist + Nestedsetbehavior + Virtual Attributes +  's - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Giix Dropdownlist + Nestedsetbehavior + Virtual Attributes +  's Rate Topic: -----

#1 User is offline   cappadochian 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 02-January 11

Posted 05 January 2013 - 12:41 PM

Hi Guys,

I don't know if anybody has faced such a situation, but I can't really find relevant info on the net.

I'm using Giix and nestedsetbehavior.

based on this Wiki: Understanding Virtual Attributes and get/set methods

I made a virtual attribute:
public function getNbspName() {
    return str_repeat(html_entity_decode(" "), $this->level*4) . $this->name;
}


this way, in the view, it looks as I want.

The problem: I wanted to echo the variable NbspName in the related table's create form, to kinda have the same tabbed design in the dropdown:
<?php echo $form->dropDownList($model, 'foreign_id',
GxHtml::listDataEx(Model::model()->findAllAttributes(null, true), 'id', 'NbspName')); ?>


why is it not rendered in the dropdown list the same way, with visible nbsps? If I put nbsps manually into a select list, it is rendered, so the problem is somewhere else.
And the order of data is also not correct.
Or should I try a different approach?

Thanks!
c
0

#2 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 645
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 05 January 2013 - 12:49 PM

Hi,

I don't think that this is the definitive solution for your problem, but I believe that you should name the method "getNbspName" instead.
Rodrigo Coelho


Check my extension
giix: a code generator for Yii. Posted Image


The complete beginner's study guide for the Yii Framework
0

#3 User is offline   cappadochian 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 02-January 11

Posted 05 January 2013 - 06:31 PM

Hey Guys,

I've figured it out! I was just monkeying around and experimenting, at least to find a solution for the sorting at first.
I don't really understand why, but changing to this:
<?php echo $form->dropDownList($model, 'foreign_id', GxHtml::listDataEx(
Model::model()->findAll(array('order' => 'lft ASC')), 'id', 'NbspName')); ?>

suddenly solved BOTH problems. Now the dropdown looks exactly the way I wanted!
0

#4 User is offline   cappadochian 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 02-January 11

Posted 05 January 2013 - 07:00 PM

Hi Guys,

a new problem I've found in connection with my virtual attribute, on admin page I can't search in the gridtop search on NbspName, but I can in the advanced search.
What can be the problem?

I see: because in the advanced search, I search for the original name, and down at the gridtop search, it wants to search directly to NbspName, because the view looks like this:
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'model-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        'id',
        'NbspName',
        ...

however NbspName doesn't really exist this way. Is there a way to make the gridtop search believe to search for a different value than what is shown in the columns section?

I tried to do this (looks straightforward to me):
public function search() {
...
$criteria->compare('name', $this->NbspName, true);
...
}

but no luck...

Thanks!

UPDATE: this way it's good.
however, for now, I think every data is to use it, one would like to search for it, to handle it, etc so, I don't really see the point of virtual attributes, but I'm just a beginner so maybe later I will find the real use of it.

ahh, still not completely good. I thought adding this:
$criteria->select = array("*", "CONCAT(REPEAT('&nbsp;', level), name) AS nbsp_name");


will solve the problem, but now all nbsps are printed as '&nbsp;'. how can I add the php function html_entity_decode to this custom column?

UPDATE: I have found another solution:
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'uzem-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        'id',
        array(
            'name' => 'nbsp_name',
            'type' => 'raw',
        ),
        ...


this way, the nbsps are rendered normally.
and for the related table's create _form I still need a magic GET function also, otherwise the dropdown is not working. :blink:

BEWARE: the variable name and the function name (without the 'get' part) must not be the same!
but now at last everything is working.
Thanks
c
0

Share this topic:


Page 1 of 1
  • 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