Minor bug on Gii

Hi,

The generated view in views/update fails to correctly display breadcrumbs in the case of :

[color="#FF0000"]foobar cannot be blank[/color]

It’s not a joke !

To reproduce:

create an SQL table–>generate a model–>generate CRUD–>create an item–>go to “update item”–>send a blank form and look at the breadcrumbs :D

I can’t reproduce it… you need to explain that a bit better… how are the breadcrumbs displayed… how should they look… what you mean with “in the case of foobar cannot be blank”… what is foobar?

foobar is a generic name for an <input type="text">, [color="#FF0000"]cannot be blank[/color] occurs when a field has a "required" rule.

The breadcrumbs will look like:

Home >> >> Update

instead of :

Home >> item >> Update

Sure it’s a minor bug due to :




$model->attributes=$_POST['foobar'];



Where the breadcrumbs try to shows the empty attribute from the empty form sent

OK, did reproduce it this time…

Yes, this can happen if you have ajaxvalidation, clientvalidation and validateOnSubmit disabled…

Yes, this can get even tricky when you have a BELONGS_TO relationship and you’d like (like me) to show the hierarchy in the breadcrumbs. High risk of “Trying to get property of non object” when you want to show it like

Home » Parent model’s title » Model’s title » Update

I guess we can use the model’s attributes from db in the breadcrumbs (an additional findByPk(id) will be necessary), and not rely on POST data that may not be valid at the submit time.

Or storage of the breadcrumbs array into a session cookie…

Issue on GitHub - https://github.com/yiisoft/yii/issues/665

solved in 2mins:




public function actionUpdate($id) {

        $this->loadModel($id,'update');

        Yii::app()->session->add('item',$this->model->getAttribute('title'));

        ...



in the view:




<?php

$this->breadcrumbs=array(

	Yii::app()->session->get('item'),

	'Update',

);

...

?>