Error In Yii: Undefined Index: Gid

Hi, everyone , I am new newbie in Yii

I am following Yii Music Store Tutorial (to Step Five) at Youtube and used source at blog

I have a error "Undefined index: gid" in "C:\xampp\htdocs\yiimusicstore­\protected\views\store\index.p­hp(12)"

Here is "C:\xampp\htdocs\yiimusicstore\protected\views\store\index.php"


<?php

$this->breadcrumbs=array(

	'Store',

);

?>

<img

	src="<?php echo Yii::app()->request->baseUrl; ?>/images/logo.png" />

	<h1><em><?php echo CHtml::encode(Yii::app()->name); ?></em></h1>                                   <?php //My Music Store Web Application?>


<?php

if ( isset($_GET["gid"])==1 ||  (  isset($_GET["albid"]) && isset($_GET["aid"]) ) ||  isset($_GET[ 'artistid' ])      )                                    // sua cho nay vao 23/10 *************************************************************

if ( $_GET["gid"]  )

    {

                                                                                                                       echo '<h3>Vi sao hok hien duoc</h3>' ;

	foreach ($Genres as $Genre){

		echo '<h1>' . $Genre->Name . "</h1><br />";

		$desc = $Genre->Description;

	}

  ?>


<div id="gmenu"><?php echo $desc; ?></div>


<table>

	<tr>

	<?php

	$cntRow = 0;

	foreach ($Albums as $Album)

	{

		$aid = $Album->ArtistId;

		$cntRow++;

		if($cntRow % 2) echo "</tr><tr>";

		foreach ($Artists as $Artist){

			if($Artist->ArtistId === $aid){

				$aname = $Artist->Name . "<br />";

			}

		}

		echo "<td><center><h3><strong>" . CHtml::link($aname, array('/Store/ArtistDetails/', 'artistid'=>$aid)) . "</strong></h3>";

		echo CHtml::link('<img src="' . Yii::app()->request->baseUrl . $Album->AlbumArtUrl . '" /><br />', array('store/details/', 'albid' => $Album->AlbumId, 'aid'=>$aid));

		echo $Album->Title . "<br />" . $Album->Price . "</center></td>";

	}

	?>

	</tr>

</table>


<?php }

	elseif                                                                                                              //************************************************

        ($_GET["albid"] && $_GET["aid"]   )

           {

                //$_GET["gid"] = 6 ;

                                                                                                                      echo '<h3>Vi sao hok hien duoc</h3>' ;

		foreach($Artists as $Artist){

			$aname = $Artist->Name;

			$abio = $Artist->bio;

		}

		foreach($Albums as $Album){

			$title = $Album->Title;

			$tracks = $Album->tracks;

			$price = $Album->Price;

			$albid = $Album->AlbumId;

			$aid = $Album->ArtistId;

			$lnotes = $Album->LinerNotes;

			$AlbumArtLargeUrl = $Album->AlbumArtLargeUrl;

		} ?>

<h1><?php echo CHtml::link($aname, array('/Store/ArtistDetails/', 'artistid'=>$aid)); ?></h1>

<table>

	<tr>

		<td valign="top"><?php echo '<img src="' . Yii::app()->request->baseUrl . $AlbumArtLargeUrl . '"  /><br /></td>'; ?>

		<td>TESTTTTTTTTTTTTTTTTTTT</td>

		<td valign="top"><?php echo "<h4>TRACKS</h4>" . $tracks; ?></td>

	

	</tr>

	<tr>

		<td valign="top"><?php echo $title . "<br />"; 

		echo $price . "<br />";

		echo CHtml::link('Add to Cart', array('/ShoppingCart/', 'albid'=>$albid, 'aid'=>$aid)) . "<br />"; ?>

		</td>

	</tr>

</table>

		<?php echo '<h3>Liner Notes</h3>' . $lnotes; ?>

		<?php

	} 	

	elseif  

         ($_GET['artistid']){

                                                                                                                        echo '<h3>Vi sao hok hien duoc</h3>' ;

		foreach($Artists as $Artist){

			$aname = $Artist->Name;

			$abio = $Artist->bio;

			$artistArtlUrl = $Artist->ArtistGraphicUrl;

		} ?>

<h1><?php echo $aname; ?></h1>

<?php echo '<img style="float:left; margin: 0 5px 5px 0;" src="' . Yii::app()->request->baseUrl . $artistArtlUrl . '"  /><br /></td>'; ?>

<?php echo "<h4>Bio</h4>" . $abio; ?>	


<?php } 

else 

    {

    // echo "<h1>" . $this->id . '/' . $this->action->id . "</h1>";

    // echo "<h3>" . $content . "</h3>";

    }

?>



And "C:\xampp\htdocs\yiimusicstore\protected\controllers\StoreController.php


<?php


class StoreController extends Controller

{

	public $message;

	public function actionIndex()

	{

		$this->message = "Select a Genre or Artist to see the Albums in our Store.";

		$this->render('index', array('content'=>$this->message));

	}

	

	public function actionBrowse()

	{

		if($_GET["gid"]){

			$genreCriteria = new CDbCriteria();

			$genreCriteria->select = "`GenreId`, `Name`, `Description`";

			$genreCriteria->condition = "genreId = " . $_GET["gid"];

			

			$artistCriteria = new CDbCriteria();

			$artistCriteria->alias = "t1";

			$artistCriteria->select = "DISTINCT `t1`.`Name`, `t1`.`ArtistId`";

			$artistCriteria->join = "LEFT JOIN `tbl_album` ON `tbl_album`.`ArtistId` = `t1`.`ArtistId`";

			$artistCriteria->condition = "`tbl_album`.`GenreId` = " . $_GET["gid"];

			$artistCriteria->order = "`t1`.`ArtistId` ASC";

			

			$albumCriteria = new CDbCriteria();

			$albumCriteria->alias = "t2";

			$albumCriteria->select = "*";

			$albumCriteria->condition = "`GenreId` = " . $_GET["gid"];

			$albumCriteria->order = "`ArtistId` ASC";

			

			$this->render('index', array('Albums' => Album::model()->findAll($albumCriteria),

			                             'Artists'=> Artist::model()->findAll($artistCriteria),

			                             'Genres' => Genre::model()->findAll($genreCriteria)));

		}else{

			$this->message = 'Select a Genre from the Home page or an Artist on the left to see the Albums in our Store.';

			$this->render('index', array('content'=>$this->message));

		}

	}

	

    public function actionDetails()

	{

		if($_GET["albid"] && $_GET["aid"]){

			$albumCriteria = new CDbCriteria();

			$albumCriteria->select = "*";

			$albumCriteria->condition = "AlbumId = " . $_GET["albid"];

			

			$artistCriteria = new CDbCriteria();

			$artistCriteria->select = "*";

			$artistCriteria->condition = "`ArtistId` = " . $_GET["aid"];

			

			$this->render('index', array('Albums' => Album::model()->findAll($albumCriteria),

			                             'Artists' => Artist::model()->findAll($artistCriteria),

			));

		}

		else{

			$this->message = "Please select an album to view it's details";

			$this->render('index', array('content'=>$this->message,));

		}

	}

	

	public function actionArtistDetails()

	{

		if($_GET["artistid"])

		{

			$artistCriteria = new CDbCriteria();

			$artistCriteria->select = "*";

			$artistCriteria->condition = "`ArtistId` = " . $_GET["artistid"];

			

			$this->render('index', array('Artists' => Artist::model()->findAll($artistCriteria),

			));

		}

		else{

			$this->message = "Please select an Artist to view their details";

			$this->render('index', array('content'=>$this->message,));

		}

	}


	// Uncomment the following methods and override them if needed

	/*

	public function filters()

	{

		// return the filter configuration for this controller, e.g.:

		return array(

			'inlineFilterName',

			array(

				'class'=>'path.to.FilterClass',

				'propertyName'=>'propertyValue',

			),

		);

	}


	public function actions()

	{

		// return external action classes, e.g.:

		return array(

			'action1'=>'path.to.ActionClass',

			'action2'=>array(

				'class'=>'path.to.AnotherActionClass',

				'propertyName'=>'propertyValue',

			),

		);

	}

	*/

}

Please help me !! and thanks you very much !!

It’s saying that $_GET[“gid”] isn’t set on line 12 of the view. I suspect that line should also be


if (isset($_GET["gid"]))

As an aside, there are better ways of getting query parameters in yii.


$gid = Yii::app()->request->getQuery('gid');

That allows you to get the value of the GET parameter, returning a default value if the parameter isn’t set rather than triggering a PHP error. The default is null, but you can specify your own default value as the second parameter to getQuery(). For POST values use Yii::app()->request->getPost().

I’m still trying to do but can’t do it

Can you check and edit for me ?

www.mediafire.com/?4h5af0kaka6pshl

Thanks for every help!

[post=‘www.mediafire.com/?4h5af0kaka6pshl’]1[/post]

as keith pointed out change it

to