0

I'm facing a problem with a site I'm building using the Yii framework.

In the site I have a form for the Photos model. The Photos model is related to the Stores model like so:

Stores Model

public function relations()
{
return array(
'photos' => array(self::HAS_MANY, 'Photo', 'storeId'),
...

Photos Model

public function relations()
{
return array(
'store' => array(self::BELONGS_TO, 'Store', 'storeId'),
);
}

In the Photos form, I am trying to get a dropdown with the list of all the stores like so:

<div class="row">
<?php echo $form->labelEx($model,'storeId'); ?>
<?php 
//The below line is causing the problem
echo $form->dropDownList($model,'storeId', 
CHtml::listData(Store::model()->findAll(), 'id', 'name')); 
?>
<?php echo $form->error($model,'storeId'); ?>
</div>

What's happening is that the page rendering breaks down at the dropdownList line. If I remove the line, the form displays properly. I have a feeling this might be because the store model's relationship with the photo model, but can't quite figure out why, or how to fix this.

Can somebody shed some light on what could be happening? Thanks!

Edit:

Figured it out partly!

I temporarily fixed the issue by adding the following code:

$criteria = new CDbCriteria();
$criteria->limit = 10;
$stores = Store::model()->findAll($criteria);

It seems the problem is that the Store table has too many records (more than 35000), which is causing some problems. Maybe this is a memory issue?

tereško
  • 58,060
  • 25
  • 98
  • 150
Donnie Thomas
  • 3,888
  • 8
  • 47
  • 70
  • 1
    what's the error? did you try `Store::model()->findAll()` outside of the dropdown function? – ldg Jun 26 '11 at 02:31
  • There's no error - the page shows only the HTML up to the point where I have the Store::model()->findAll() command (even outside the dropdown). Even the logging output is now shown. The HTML is literally just limited to the view, right before the command. – Donnie Thomas Jun 26 '11 at 08:58
  • so, yeah, it could be timing out - is the intention to show all 35k stores in a HTML drop-down? – ldg Jun 26 '11 at 20:56

1 Answers1

2

Do you get any errors in the log files?

If the code above is exactly yours, you may just be missing a closing bracket...

<?php 
//The below line is causing the problem
echo $form->dropDownList(
  $model,
  'storeId', 
  CHtml::listData(Store::model()->findAll(), 'id', 'name')
); 
?>
schmunk
  • 4,708
  • 1
  • 27
  • 50
  • Sorry, the missing bracket was a typo but is present in the code. I don't see any log files created, and YII_debug is set to true. Any log files are created in the root directory, right? – Donnie Thomas Jun 25 '11 at 23:44
  • Can you do a print_r agains the chtml::listData to see what the problem is? – Chux Jun 26 '11 at 13:52
  • And also please turn on Yii's complete logging, nothing in protected/runtime/application.log? – schmunk Jun 27 '11 at 10:39