pungpoo / giix

Automatically exported from code.google.com/p/giix
0 stars 0 forks source link

Add the option to call a model method when generating list data in valueEx #38

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm hoping to be able to call a model method before outputting a string for a 
dropdown list:
echo 
$form->dropDownList($model,'id',GxHtml::listDataEx($clients,'id','nameForList'))
;

What do you see instead?
I get an error stating that nameForList isn't defined for my model (I knew that 
:-)

What version of giix are you using?
1.9.1

What is your stack (operating system, web server, DBMS, PHP version)?
Ubuntu 10.10, MySQL, PHP 5.2

What version of the Yii Framework are you using?
HEAD

I've pasted in a patch here for valueEx.  Seems like it could add just an 
additional bit of ease to using GiiX.  Thanks for all the work on it, I use it 
a lot these days!

--- a/protected/extensions/giix-components/GxHtml.php
+++ b/protected/extensions/giix-components/GxHtml.php
@@ -143,6 +143,8 @@ class GxHtml extends CHtml {
                                return $model->__toString();
                        else
                                return $defaultValue;
+               } elseif(method_exists($model, $attribute)) {
+                       return $model->$attribute();
                } else {
                        return parent::value($model, $attribute, $defaultValue);
                }

Original issue reported on code.google.com by acorn...@gmail.com on 1 May 2012 at 11:33

GoogleCodeExporter commented 8 years ago
Is this a feature request?
Maybe you should post on the forum topic for giix:
<http://www.yiiframework.com/forum/index.php/topic/13154-giix-%E2%80%94-gii-exte
nded/>

A suggestion: you can try calling the method directly instead of passing its 
name as a string.

Original comment by rodrigo.coelho@gmail.com on 1 May 2012 at 11:45