Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Blog tutorial code example unclear due to change in convention #393

Closed
caedmon5 opened this Issue · 2 comments

2 participants

@caedmon5

In the page Customizing Post Model, section "representing status in text" there is a section of code that is unclear because it violates the conventions used elsewhere in the tutorial. This issue is in the code chunk for the Lookup model. The text says "We modify the Lookup model class as follows to more easily access the textual data in the table" but there is no elipsis in the code to indicate that the sample code is to be added into the existing Lookup model rather than replace it.

In previous examples, the convention has been to include an elipsis in the code sample indicating the code that is to remain and to include entire methods, classes, etc. without elipsis when the code is to replace the existing code.

Here is the existing code (replacement follows):

[code]
class Lookup extends CActiveRecord
{
private static $_items=array();

public static function items($type)
{
    if(!isset(self::$_items[$type]))
        self::loadItems($type);
    return self::$_items[$type];
}

public static function item($type,$code)
{
    if(!isset(self::$_items[$type]))
        self::loadItems($type);
    return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false;
}

private static function loadItems($type)
{
    self::$_items[$type]=array();
    $models=self::model()->findAll(array(
        'condition'=>'type=:type',
        'params'=>array(':type'=>$type),
        'order'=>'position',
    ));
    foreach($models as $model)
        self::$_items[$type][$model->code]=$model->name;
}

}
[/code]

The code should read

[code]
class Lookup extends CActiveRecord
{

.....

private static $_items=array();

public static function items($type)
{
    if(!isset(self::$_items[$type]))
        self::loadItems($type);
    return self::$_items[$type];
}

public static function item($type,$code)
{
    if(!isset(self::$_items[$type]))
        self::loadItems($type);
    return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false;
}

private static function loadItems($type)
{
    self::$_items[$type]=array();
    $models=self::model()->findAll(array(
        'condition'=>'type=:type',
        'params'=>array(':type'=>$type),
        'order'=>'position',
    ));
    foreach($models as $model)
        self::$_items[$type][$model->code]=$model->name;
}

}
[/code]

@samdark
Owner

Can you do a pull reqest for this chane? Thanks.

@caedmon5
@acorncom acorncom referenced this issue from a commit in acorncom/yii
@acorncom acorncom Added elipsis to blog tutorial code per bug #393 to better indicate h…
…ow to treat the related code
d5f814b
@acorncom acorncom referenced this issue from a commit in acorncom/yii
@acorncom acorncom Added elipsis to blog tutorial code per bug #393 db5faa3
@samdark samdark closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.