# Yii Framework Forum: Giix Crud - Yii Framework Forum

• (2 Pages)
• 1
• 2

## Giix Crud

### #21Rodrigo Coelho

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

Posted 06 January 2013 - 01:57 PM

Hi lilli,
Happy new year!

No, giix doesn't provide this feature, but you can just follow this wiki: How to upload a file using a model.

Are you making great progress?
1

### #22lilli

• Junior Member
• Group: Members
• Posts: 43
• Joined: 19-April 12

Posted 06 January 2013 - 02:18 PM

Happy new Y(ii)ear to you!

I've made some progress but not that much (you know, holidays...).
Anyway, Yii it's really great. I'm wondering how the 2.0 version will be... Let's see.

0

### #23Rodrigo Coelho

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

Posted 06 January 2013 - 02:43 PM

lilli, on 06 January 2013 - 02:18 PM, said:

Happy new Y(ii)ear to you!

Lol

lilli, on 06 January 2013 - 02:18 PM, said:

Anyway, Yii it's really great. I'm wondering how the 2.0 version will be... Let's see.

It will be awesome. Check here for mouth-watering info.

lilli, on 06 January 2013 - 02:18 PM, said:

That's a good tutorial, with lots of details. It seems to cover the same approach used on the wiki.
0

### #24Rodrigo Coelho

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

Posted 06 January 2013 - 02:52 PM

Oh, and a security note: as a general rule, you shouldn't save the uploaded file under a Web-accessible directory unless necessary and until you verify the nature of the file (that the file is actually an image, for example).

References:
http://en.wikibooks....vulnerabilities
http://stackoverflow...rity-check-list
1

### #25lilli

• Junior Member
• Group: Members
• Posts: 43
• Joined: 19-April 12

Posted 06 January 2013 - 03:49 PM

Rodrigo Coelho, on 06 January 2013 - 02:52 PM, said:

Oh, and a security note: as a general rule, you shouldn't save the uploaded file under a Web-accessible directory unless necessary and until you verify the nature of the file (that the file is actually an image, for example).

References:
http://en.wikibooks....vulnerabilities
http://stackoverflow...rity-check-list

0

### #26lilli

• Junior Member
• Group: Members
• Posts: 43
• Joined: 19-April 12

Posted 10 January 2013 - 02:05 PM

Hi Rodrigo,
me again.

What if I need to add an extra data to the pivot tables?

Example:

STUDENTS
id_student
...

EXAMS
id_exam
exams
...

STUDENTS_X_EXAMS
id_student
id_exam
vote (this is the extra-primary keys data)
date (another one...)

How can I insert the additional datas on the Insert/Update views?

Thanks,

Lilli
0

### #27jacmoe

• Elite Member
• Group: Moderators
• Posts: 3,469
• Joined: 10-October 10
• Location:Denmark

Posted 10 January 2013 - 05:37 PM

/* moved from General Discussion */
"Less noise - more signal"
0

### #28luc

• Standard Member
• Group: Members
• Posts: 211
• Joined: 22-June 10
• Location:france

Posted 11 January 2013 - 03:57 AM

lilli, on 10 January 2013 - 02:05 PM, said:

Hi Rodrigo,
me again.

What if I need to add an extra data to the pivot tables?

Example:

USERS
id_user
...

EXAMS
id_exam
exams
...

USERS_X_EXAMS
id_user
id_exam
vote (this is the extra-primary keys data)
date (another one...)

How can I insert the additional datas on the Insert/Update views?

Thanks,

Lilli

I've got a Category model, an Image model and pivot table "category_image' with additional field "position" for sorting images within a category. In Category controller:

```	public function actionSort(\$catId)
{
foreach( \$_POST['img'] as \$order => \$id )
{
\$command = Yii::app()->content->createCommand(); //content is my DB connection
\$command->update(
'category_image',
array(
'position'=>\$order,
),
'image_id=:ID AND category_id=:catID',
array(':ID'=>\$id,'catID'=>\$catId)
);
//echo \$id.'=>'.\$order.'=>'.\$catId.'/';
}

}
```

Hope this helps
Hey Ho !
Let's go !
0

### #29lilli

• Junior Member
• Group: Members
• Posts: 43
• Joined: 19-April 12

Posted 11 January 2013 - 04:40 AM

Thanks luc,
but when i have to call your function?

I mean let's go back to my example:
in Students controller i have this create action, generated with giix.

```	public function actionCreate() {
\$model = new Students;

\$this->performAjaxValidation(\$model, 'Students-form');

if (isset(\$_POST['Students'])) {
\$model->setAttributes(\$_POST['Students']);
\$relatedData = array(
'exams' => \$_POST['Students']['exams'] === '' ? null : \$_POST['Students']['exams'],
);

if (\$model->saveWithRelated(\$relatedData)) {
if (Yii::app()->getRequest()->getIsAjaxRequest())
Yii::app()->end();
else
\$this->redirect(array('view', 'id' => \$model->id_student));
}
}

\$this->render('create', array( 'model' => \$model));
}```

and in my view i have this:

```	<div class="relationscreate">
<h2><?php echo GxHtml::encode(\$model->getRelationLabel('exams')); ?></h2>
<?php echo \$form->checkBoxList(\$model, 'exams', GxHtml::encodeEx(GxHtml::listDataEx(Exams::model()->findAllAttributes(null, true)), false, true)); ?>
</div>```

where do i have to put the vote and date, additional fields, to associate them with the relative checkboxlist exam?
0

### #30luc

• Standard Member
• Group: Members
• Posts: 211
• Joined: 22-June 10
• Location:france

Posted 11 January 2013 - 05:41 AM

I think that in your case, checkBoxList is not the right choice.
Using a loop through
`\$exams=Exams::model()->findAll();`
and create for each exam relation a checkbox for setting the relation and all the neccessary additionnal fields (vote, date ...).
Hey Ho !
Let's go !
0

### #31lilli

• Junior Member
• Group: Members
• Posts: 43
• Joined: 19-April 12

Posted 11 January 2013 - 02:18 PM

luc, on 11 January 2013 - 05:41 AM, said:

I think that in your case, checkBoxList is not the right choice.
Using a loop through
`\$exams=Exams::model()->findAll();`
and create for each exam relation a checkbox for setting the relation and all the neccessary additionnal fields (vote, date ...).

Luc, i still have many doubts...

forget the additional fields for a moment. how can i get the same output of a checkBoxList related to a model without using it?

this is the output of the checkBoxList:
```<input type="hidden" name="Students[exams]" value="" id="ytStudents_exams"><span id="Students_exams">
<input type="checkbox" name="Students[exams][]" checked="checked" value="1" id="Students_exams_0"><label for="Students_exams_0">History</label><br>
<input type="checkbox" name="Students[exams][]" checked="checked" value="2" id="Students_exams_1"> <label for="Students_exams_1">Math</label><br>
<input type="checkbox" name="Students[exams][]" value="3" id="Students_exams_2"> <label for="Students_exams_2">Geography</label><br>
<input type="checkbox" name="Students[exams][]" value="4" id="Students_exams_3"> <label for="Students_exams_3">Literature</label>```

for managing the insert/update of a many to many relations i need something like a checkBoxList.

```			\$exams=Exams::model()->findAll();
foreach (\$exams as \$key=>\$value){
//i really can't find a way for having the same output
//(i can get just the labels but not the value or if they're checked or not)
}
```

i'm quite desperate...
0

### #32lilli

• Junior Member
• Group: Members
• Posts: 43
• Joined: 19-April 12

Posted 11 January 2013 - 05:04 PM

lilli, on 11 January 2013 - 02:18 PM, said:

```			\$exams=Exams::model()->findAll();
foreach (\$exams as \$key=>\$value){
//i really can't find a way for having the same output
//(i can get just the labels but not the value or if they're checked or not)
}
```

ok,
if i create the array like this:
`\$exams=GxHtml::encodeEx(GxHtml::listDataEx(Exams::model()->findAllAttributes(null, true)), false, true);`

i will have an array with as key the primary key of Exams and as value the value of the exams but it's not enough.

i still have the problem in update action, because, without checkBoxList, i don't know how to pass the model to say if it's checked or not.

help, please. all my project depends if i can fix this problem or not.
0

### #33lilli

• Junior Member
• Group: Members
• Posts: 43
• Joined: 19-April 12

Posted 11 January 2013 - 08:08 PM

probably this is not the best solution, but it's a solution (and i don't see many alternatives):

on students view:

```\$exams=GxHtml::encodeEx(GxHtml::listDataEx(Exams::model()->findAllAttributes(null, true)), false, true);

foreach (\$exams as \$key=>\$value){
echo "<input type='text' name='Students[vote][".\$key."]' value='".\$students_x_exams[\$key]."' >";
}
```

and in the update action:
```public function actionUpdate(\$id) {

\$students_x_exams = StudentsXExams::model()->findAll('id_student=:id_student',
array(':id_student'=>(int)  \$id));
\$students_x_exams=CHtml::listData(\$students_x_exams,"id_exam","vote");

...

if (\$model->saveWithRelated(\$relatedData)) {

\$students_x_exams= new StudentsXExams();
foreach (\$_POST['Students']['vote'] as \$id_exam=>\$vote){
\$criteria= new CDbCriteria();
\$criteria->condition="id_student=".\$model->id_student;
\$istr_x_agg->updateAll(array('vote'=>\$vote),\$criteria);
}

\$this->redirect(array('view', 'id' => \$model->id_student));
}

...

\$this->render('update', array(
'model' => \$model,
'students_x_exams'=>\$students_x_exams,
));
}
```

0

• Standard Member
• Group: Members
• Posts: 159
• Joined: 02-January 11

Posted 20 February 2013 - 09:19 AM

Hi Guys,

I have a little problem. On my 1.1.12, I have absolutely no problem, but I've copied my models, controllers, and views to a 1.1.13 version, and I've got the following PHP warning at only by one single "model" or "module":
`htmlspecialchars(): Invalid multibyte sequence in argument`

`...\framework\web\helpers\CHtml.php(98)`

`return htmlspecialchars(\$text,ENT_QUOTES,Yii::app()->charset);`

Stack Trace:
```#0...yii\framework\web\helpers\CHtml.php(98): htmlspecialchars()
#1...yii\framework\web\helpers\CHtml.php(2071): CHtml::encode()
#2...yii\framework\web\helpers\CHtml.php(1566): CHtml::listOptions()
#3...yii\framework\zii\widgets\grid\CDataColumn.php(95): CHtml::activeDropDownList()
#4...yii\framework\zii\widgets\grid\CGridColumn.php(109): CDataColumn->renderFilterCellContent()
#5...yii\framework\zii\widgets\grid\CGridView.php(505): CGridColumn->renderFilterCell()
#6...yii\framework\zii\widgets\grid\CGridView.php(483): CGridView->renderFilter()
#8...yii\framework\zii\widgets\CBaseListView.php(160): CGridView->renderItems()
#9 unknown(0): CBaseListView->renderSection(array("{items}", "items"))
#10...yii\framework\zii\widgets\CBaseListView.php(143): preg_replace_callback("/{(\w+)}/", array(CGridView, "renderSection"), "{summary} {items} {pager}")
#11...yii\framework\zii\widgets\CBaseListView.php(128): CBaseListView->renderContent()
#12...yii\framework\web\CBaseController.php(173): CBaseListView->run()
#13...(project folder)\protected\views\munkakor\admin.php(80): CBaseController->widget("zii.widgets.grid.CGridView", array("id" => "munkakor-grid", "dataProvider" => CActiveDataProvider, "filter" => Munkakor, "columns" => array("id", array("name" => "nbsp_name", "type" => "raw", "htmlOptions" => array("style" => "white-space: nowrap")), "rov", "root", ...)))
#14...yii\framework\web\CBaseController.php(126): require("C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdo...")
#15...yii\framework\web\CBaseController.php(95): CBaseController->renderInternal("C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdo...", array("model" => Munkakor), true)
#16...yii\framework\web\CController.php(869): CBaseController->renderFile("C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdo...", array("model" => Munkakor), true)
#17...yii\framework\web\CController.php(782): CController->renderPartial("admin", array("model" => Munkakor), true)
#18...(project folder)\protected\controllers\MunkakorController.php(90): CController->render("admin", array("model" => Munkakor))
#20...yii\framework\web\CController.php(308): CInlineAction->runWithParams(array())
#21...yii\framework\web\CController.php(286): CController->runAction(CInlineAction)
#22...yii\framework\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array())
#25...yii\framework\base\CApplication.php(169): CWebApplication->processRequest()
#26...(project folder)\index.php(13): CApplication->run()```

after a few hours of experimenting with utf8 settings (it seems all good to me everywhere) and googling I could figure out that the problem is with this one single line in protected\views\munkakor\admin.php's CGridView's columns section:
```array(
'name' => 'uzem_id',
'value' => 'GxHtml::link(\$data->uzem, array("uzem/view", "id" => \$data->uzem_id))',
'type' => 'raw',
'filter' => GxHtml::listDataEx(Uzem::model()->findAll(array('order' => 'root, lft ASC')), 'id', 'Nbsp_name'),
),```

more specifically:
'filter' => GxHtml::listDataEx(Uzem::model()->findAll(array('order' => 'root, lft ASC')), 'id', 'Nbsp_name'),
if I comment this out, the warning goes away. there are absolutely no special characters anywhere, no BOMs...
What can be wrong with this code?

UPDATE: the problem is definitely with a function in my model:
```public function getNbspName() {
return str_repeat("&nbsp;", (\$this->level - 1) * 4) . \$this->name;
}
```

it doesn't like &nbsp; there, but so far I had no problem with this. It's only since of the newer version of yii...

Thanks a lot!
BR
c
0