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

Closed
caedmon5 opened this Issue Feb 24, 2012 · 2 comments

Comments

Projects
None yet
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

This comment has been minimized.

Show comment Hide comment
@samdark

samdark Feb 24, 2012

Member

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

Member

samdark commented Feb 24, 2012

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

@caedmon5

This comment has been minimized.

Show comment Hide comment
@caedmon5

caedmon5 Feb 24, 2012

Sorry, I don't know what that means.

On 12-02-24 09:48 AM, Alexander Makarov wrote:

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


Reply to this email directly or view it on GitHub:
#393 (comment)

Daniel Paul O'Donnell
Professor of English
University of Lethbridge
Lethbridge AB T1K 3M4
Canada

+1 403 393-2539

Sorry, I don't know what that means.

On 12-02-24 09:48 AM, Alexander Makarov wrote:

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


Reply to this email directly or view it on GitHub:
#393 (comment)

Daniel Paul O'Donnell
Professor of English
University of Lethbridge
Lethbridge AB T1K 3M4
Canada

+1 403 393-2539

acorncom added a commit to acorncom/yii that referenced this issue Mar 9, 2012

acorncom added a commit to acorncom/yii that referenced this issue Mar 9, 2012

samdark added a commit that referenced this issue Mar 9, 2012

Merge pull request #478 from acorncom/393-tweak-to-blog-tutorial-code…
…-example

Added elipsis to blog tutorial code per bug #393

@samdark samdark closed this Mar 9, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment