how to crete table in yii framework?

already do this coding, but it doesnt show anything…even the table…what is wrong with my coding? please help me…


<table>

	<tr>

	

	<?php

	$cntRow = 0;

	foreach ($alatan as $alatans)

	{

		$aid = $alatans->Equip_ID;

		$cntRow++;

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

		foreach ($equipment as $equipments){

	  		if ($equipments->Equip_ID === $aid){

				$aname = $equipments->Equipment_Name . "<br />";

			}

		}

		echo "<td><center><strong>" . $aname . "</strong>";

		echo CHtml::link('<img src=""' . Yii::app()->request->baseUrl . $alatans->Image . '" /><br />', array('store/details/','alatan' => $alatans->Equip_ID));

		echo $alatans>Equipment_Name . "<br />" . $alatans->Description . "</center></td>";

	}

	?>

	</tr>

	</table>

Why you are creating a table like this…you can use a CGridView or CListView. ;)

CGridView or CListView ? how? i dont know to use it…i only follow the tutorial in the youtube…huhuhu

jacmoe already edit my coding? but at where? ilook at it is same coding…

Hi starry yii,

What Jacmoe seem to have done was to add [ code ][ /code ] (without the spaces) tags around your PHP code. That way your code is shown here in colors and with indentation. It makes it more readable for us. He did not change your actual code.

The first thing I would check is if both $alatan and $equipment are arrays, and if they are not empty. You can do that by temporarily adding the following code right above the table and viewing the page:




<?php var_dump($alatan, $equipment); ?>



There are two other things that I noticed. First a very small typo near the end:




// this line misses a character

echo $alatans>Equipment_Name . "<br />" . $alatans->Description . "</center></td>";


// it should read:

echo $alatans->Equipment_Name . "<br />" . $alatans->Description . "</center></td>";



Secondly, I am not sure if it is supposed to happen, but the second foreach loop (with $equipment) will never add more than one $aname to the table output. In that case I would suggest removing the <br /> at the end of that line. In fact, you probably don’t need most (if any at all) of the <br /> tags that are in your code now.

Finally, as far jayant’s comment is concerned. I think you should first try to get a basic table working, like you are trying now. CGridView is neat, but it means you need to have your models well in order. I’m not sure if that is the case here.

Btw, do you happen to have a link to that Youtube tutorial you mentioned? It may help in figuring out what is supposed to happen.

means that, i must remove all the <br /> tags? the tutorial video shown very fast way…he only paste the already coding that he done it…he did not show where the coding come from…huhuhu




<?php if (!empty($model)) : ?>

<table class="list" width="60%">

  <thead width="60">

  <tr>

      <td colspan="6">

      Project Repositories

      </td>

  </tr>


  <tr>

    <th width="15">Name</th>

    <th width="10">type</th>

    <th width="20">URL</th>

    <th width="20">Local Path</th>

    <th width="15">Status</th>

    <th width="20">Actions</th>

  </tr>

  </thead>

  <tbody>

<?php foreach($model as $n=>$repository): ?>

  <tr class="<?php echo $n%2?'even':'odd';?>">

    <td width="15"><?php echo CHtml::encode($repository->name); ?></td>

    <td width="10"><?php echo CHtml::encode($repository->type); ?></td>

    <td width="20"><?php echo CHtml::encode($repository->url); ?></td>

    <td width="20"><?php echo CHtml::encode($repository->local_path); ?></td>

    <td width="15"><?php echo CHtml::encode($repository->status ? 'OK' : 'Pending'); ?></td>

    <td width="20">

      <?php echo CHtml::link('Update',array('repository/update','id'=>$repository->id, 'identifier' => $_GET['identifier'])); ?>

      <?php echo CHtml::linkButton('Delete',array(

          'submit'=>array('/repository/delete', 'id' => $repository->id, 'identifier' => $_GET['identifier']),

          'confirm'=>"Are you sure you want to delete {$repository->name}?")); ?>

        </td>

  </tr>

<?php endforeach; ?>

  </tbody>

</table>

<?php else: ?>

<p class="nodata"><?php echo 'No data to display'; ?></p>

<?php endif; ?>

this is the link…

http://www.youtube.com/watch?v=0UVVYvSqUvU

its only show No data to display… doesnt work…huhuhu

Then $model is empty. ;)

which model? $alatan?

How the heck should I know??

You are simply not providing any details.

my $alatan have data… i ask u nicely but u answer like that? such a sad…

Hi starry yii,

I’m affraid I can’t really tell what is going wrong in your code right now. Is there any chance you could upload what you have so far so I can run it and play around with it a bit? If you don’t want to post it here in public, feel free to e-mail me instead. I will PM you my address. If you are okay with sharing, could you include:

[list=1]

[*]your webapp, but not the framework itself (to save size). Don’t forget to remove usernames and password from your config file!

[*]a database dump that can be imported

[/list]

If you are not okay with sharing, we really do need at least more information about what is in the $alatan and $equipment variables when your code is run. Could you then paste the result of the var_dump() I suggested above?

ok…i will send it to you…but u want all the file or how? i ont understand… did u means the php file only? or complete with the database? how should i paste the result of var_dump? u man print screen or what?

I am spending my time trying to help you, but you are not making it easy.

I want to see code from your controller and your model.

And the code you are using from the view.

And I want to see it right now!

i’m sorry…i paste here the coding ok…tq for trying help me… :)

  1. coding store controller.php

<?php

class StoreController extends Controller

{

public &#036;message;


public function actionIndex()


{


	&#036;this-&gt;message = 'Hello from Store.Index()';


	&#036;this-&gt;render('index', array('content'=&gt;&#036;this-&gt;message));


}





public function actionBrowse()


{


	if (&#036;_GET[&quot;id&quot;]){


				


		&#036;equipmentCriteria = new CDbCriteria();


		&#036;equipmentCriteria -&gt;select = &quot;Equipment_Name,Description&quot;;


		&#036;equipmentCriteria -&gt;condition = &quot;Equip_ID = &quot; . &#036;_GET[&quot;id&quot;];


		


		&#036;alatanCriteria = new CDbCriteria();


		//&#036;alatanCriteria -&gt;alias = &quot;b1&quot;;


		//&#036;alatanCriteria -&gt;select = &quot;DISTINCT 'b1' . 'Equip_ID', 'b1' . 'Name', 'b1'.'Amount'&quot;;


		&#036;alatanCriteria -&gt;select = &quot;Stock_ID, Equip_ID,Amount&quot;;


		&#036;alatanCriteria -&gt;condition = &quot;Stock_ID = &quot; . &#036;_GET[&quot;id&quot;];


		//&#036;alatanCriteria -&gt;order = &quot;'b1'.'Equip_ID' ASC&quot;;


		


		//&#036;alatanCriteria = new CDbCriteria();


		//&#036;alatanCriteria -&gt;alias = &quot;a1&quot;;


		//&#036;alatanCriteria -&gt;select = &quot;DISTINCT 'a1' . 'ID_Number', 'a1' . 'Name', 'a1'.'Amount'&quot;;


		//&#036;alatanCriteria -&gt;select = &quot;LEFT JOIN 'alatan' ON 'alatan'.'ID_Number'= 'a1' . 'Name'&quot;;


		//&#036;alatanCriteria -&gt;condition = &quot;'alatan'.'ID_Number' = &quot; . &#036;_GET[&quot;id&quot;];


		//&#036;alatanCriteria -&gt;order = &quot;'a1'.'ID_Number' ASC&quot;;


					


		


		&#036;this-&gt;render('index', array('alatan' =&gt; alatan::model()-&gt;findAll(&#036;alatanCriteria),


									 'equipment' =&gt; Equipment::model()-&gt;findAll(&#036;equipmentCriteria)));


		


		}else{


			&#036;this-&gt;message = 'Hello from Store.Browse()';


			&#036;this-&gt;render('index', array('content'=&gt;&#036;this-&gt;message));


}

}

public function actionDetails()


{


	if(&#036;_GET[&quot;id&quot;]){


		&#036;equipmentCriteria = new CDbcriteria();


		&#036;equipmentCriteria -&gt;select = &quot;*&quot;;


		&#036;equipmentCriteria-&gt;condition = &quot;Equip_ID = &quot; . &#036;GET[&quot;equipment&quot;];


		&#036;this-&gt; render('index', array('equipment' =&gt; Equipment::model()-&gt;findAll(&#036;equipmentCriteria) ));


		}


		else{


	


	&#036;this-&gt;message = 'Hello from Store.Details()';


	&#036;this-&gt;render('index', array('content'=&gt;&#036;this-&gt;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'=&gt;'path.to.FilterClass',


			'propertyName'=&gt;'propertyValue',


		),


	);


}





public function actions()


{


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


	return array(


		'action1'=&gt;'path.to.ActionClass',


		'action2'=&gt;array(


			'class'=&gt;'path.to.AnotherActionClass',


			'propertyName'=&gt;'propertyValue',


		),


	);


}


*/

}

  1. coding index.php in directory protected\views\store

<?php

$this->breadcrumbs=array(

'Store',

);

?>

<?php if($_GET["id"]) {

foreach (&#036;equipment as &#036;equipments){


	echo '&lt;h1&gt;' . &#036;equipments-&gt;Equipment_Name . &quot;&lt;/h1&gt;&lt;br/&gt;&quot;;


	&#036;desc = &#036;equipments-&gt;Description;


}

?>

<div id="gmenu">

 &lt;?php echo &#036;desc; ?&gt;

</div>

<?php var_dump($alatan, $equipment); ?>

<table>

&lt;tr&gt;


&lt;?php


  &#036;cntRow = 0;


  foreach (&#036;alatan as &#036;alatans)


  {


	&#036;aid = &#036;alatans-&gt;Equip_ID;


	&#036;cntRow++;


	if (&#036;cntRow % 2) echo &quot;&lt;/tr&gt;&lt;tr&gt;&quot;;


	foreach (&#036;equipment as &#036;equipments){


	  	if (&#036;equipments-&gt;Equip_ID === &#036;aid){


			&#036;aname = &#036;equipments-&gt;Equipment_Name;


		}


	}


	echo &quot;&lt;td&gt;&lt;center&gt;&lt;strong&gt;&quot; . &#036;aname . &quot;&lt;/strong&gt;&quot;;


	echo CHtml::link('&lt;img src=&quot;' . Yii::app()-&gt;request-&gt;baseUrl . &#036;alatans-&gt;Image . '&quot; /&gt;', array('store/details/','alatan' =&gt; &#036;alatans-&gt;Equip_ID));


	echo &#036;alatans-&gt;Equipment_Name . &#036;alatans-&gt;Description . &quot;&lt;/center&gt;&lt;/td&gt;&quot;;


}


?&gt;


&lt;/tr&gt;

</table>

<?php }

elseif($_GET["alatan"]){

foreach(&#036;alatan as &#036;alatans){


//	echo '&lt;img src=&quot;&quot;' . Yii::app()-&gt;request-&gt;baseUrl . &#036;equipments-&gt;equipmentUrl . '&quot; /&gt;&lt;br/ &gt;';


	echo &#036;alatan-&gt;Equip_ID . &quot;&lt;br /&gt;&quot;;


	echo &#036;alatan-&gt;Equipment_Name . &quot;&lt;br /&gt;&quot;;


//	echo &#036;alatan-&gt;Amount . &quot;&lt;br /&gt;&quot;;


//	echo CHtml::link('Add to Cart', array('store/cart/','equipment' =&gt; &#036;equipments-&gt;Equip_ID)) . &quot;&lt;br/&gt;&quot;;


}

}

else {

?>

<h1><?php echo $this->id . ‘/’ . $this->action->id; ?></h1>

<h3>

<?php echo $content; ?>

</h3>

<?php } ?>

I have a feeling that jacmoe’s and my request for information are getting mixed up a bit. Jacmoe, may I suggest that I let starry yii mail me the code and have me post the relevant bits here? You know, less noise - more signal… ;)

Starry yii, I am going to ask you to do the following:

[list=1]

[*]copy the protected folder (the one where you keep your config, controllers, views and so on) to a temporary place

[*]in that temporary copy, edit protected/config/main.php so you remove all usernames and passwords (although I will ignore them if you happen to forget one)

[*]create a zip file of this temporary folder

[*]create a database dump and make a zip file out of it. If you use PHPAdmin, select the database for the store, click the export tab and save as a zip file.

[*]then sent both zip files to the e-mail address that I PM’ed you.

[/list]

I will take a quick look and post the code here that is relevant. Does that sound like a plan?

Cool.

As long as it means I’m off the hook.

But the point is still valid: unless Starry Yii can find eager helpers who are willing to download and debug his code - or use their psychic powers to figure out what’s wrong - then he needs to learn how to ask for help.

I know. And I’ll try to teach that when posting the code. Makes pointing out things easier. :)