Reputation: 45
EDIT: Turns out my DB keys were not configured properly, which meant that the controller entered an infinite loop whenever it was trying to retrieve the list of sellers. Thanks for the help!
CakePHP newbie here.
I am using cakePHP scaffolding to display the contents of a single model (Account Managers) and its related models (Sellers and Meetings). There are currently 2 Account Managers (they have 3 attributes each), around 220 Sellers (with around 20 attributes), and 2 meeting (with 4 attributes) in the database. A week ago, this all worked fine, but suddenly, when I attempt to view the details of a single Account Manager, I get this error:
Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 44613632 bytes) File: ...\app\View\Layouts\default.ctp Line: 70
The line is:
<?php echo $this->fetch('content'); ?>
And it's part of the default layout, which is, again, provided by the scaffolding.
I tried raising the memory limit, but then the code just times out after a while. Also, I don't seem to be accessing the database that much of fetch that much info to trigger something like this.
I'm new to cakePHP so my debugging experience is very limited.
Here's the snippet from the controller view method:
public function view($id = null) {
if (!$this->AccountManager->exists($id)) {
throw new NotFoundException(__('Invalid account manager'));
}
$options = array('conditions' => array('AccountManager.' . $this->AccountManager->primaryKey => $id));
$this->set('accountManager', $this->AccountManager->find('first', $options));
}
Here's the model for Account Managers:
<?php
App::uses('AppModel', 'Model');
/**
* AccountManager Model
*
* @property Primary $Primary
* @property Seller $Seller
* @property Meeting $Meeting
*/
class AccountManager extends AppModel {
/**
* Display field
*
* @var string
*/
public $displayField = 'first_name';
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
'Primary' => array(
'className' => 'Primary',
'foreignKey' => 'account_manager_id',
'dependent' => false
),
'Seller' => array(
'className' => 'Seller',
'foreignKey' => 'account_manager_id',
'dependent' => false
)
);
/**
* hasAndBelongsToMany associations
*
* @var array
*/
public $hasAndBelongsToMany = array(
'Meeting' => array(
'className' => 'Meeting',
'joinTable' => 'account_managers_meetings',
'foreignKey' => 'account_manager_id',
'associationForeignKey' => 'meeting_id',
'unique' => 'keepExisting'
)
);
}
And here's the view:
<div class="accountManagers view">
<h2><?php echo __('Account Manager'); ?></h2>
<dl>
<dt><?php echo __('First Name'); ?></dt>
<dd>
<?php echo h($accountManager['AccountManager']['first_name']); ?>
</dd>
<dt><?php echo __('Last Name'); ?></dt>
<dd>
<?php echo h($accountManager['AccountManager']['last_name']); ?>
</dd>
</dl>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('Edit Account Manager'), array('action' => 'edit', $accountManager['AccountManager']['id'])); ?> </li>
<li><?php echo $this->Form->postLink(__('Delete Account Manager'), array('action' => 'delete', $accountManager['AccountManager']['id']), null, __('Are you sure you want to delete # %s?', $accountManager['AccountManager']['id'])); ?> </li>
</ul>
</div>
<div class="related">
<h3><?php echo __('Related Sellers'); ?></h3>
<?php if (!empty($accountManager['Seller'])): ?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php echo __('Id'); ?></th>
<th><?php echo __('Username'); ?></th>
<th><?php echo __('Account Type'); ?></th>
<th><?php echo __('First Name'); ?></th>
<th><?php echo __('Last Name'); ?></th>
<th><?php echo __('Primary Id'); ?></th>
<th><?php echo __('Third Party Id'); ?></th>
<th><?php echo __('Email'); ?></th>
<th><?php echo __('Work Phone'); ?></th>
<th><?php echo __('Cell Phone'); ?></th>
<th><?php echo __('Address'); ?></th>
<th><?php echo __('City'); ?></th>
<th><?php echo __('Zip'); ?></th>
<th><?php echo __('Country'); ?></th>
<th><?php echo __('Store Url'); ?></th>
<th><?php echo __('Main Site'); ?></th>
<th><?php echo __('Main Vertical'); ?></th>
<th><?php echo __('Main Category'); ?></th>
<th><?php echo __('Birthday'); ?></th>
<th><?php echo __('Notes'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
<?php
$i = 0;
foreach ($accountManager['Seller'] as $seller): ?>
<tr>
<td><?php echo $this->Html->link($seller['id'], array('controller' => 'sellers', 'action' => 'view', $seller['id'])); ?></td>
<td><?php echo $this->Html->link($seller['username'], array('controller' => 'sellers', 'action' => 'view', $seller['id'])); ?></td>
<td><?php echo $seller['account_type']; ?></td>
<td><?php echo $seller['first_name']; ?></td>
<td><?php echo $seller['last_name']; ?></td>
<td><?php echo $seller['primary_id']; ?></td>
<td><?php echo $seller['third_party_id']; ?></td>
<td><?php echo $seller['email']; ?></td>
<td><?php echo $seller['work_phone']; ?></td>
<td><?php echo $seller['cell_phone']; ?></td>
<td><?php echo $seller['address']; ?></td>
<td><?php echo $seller['city']; ?></td>
<td><?php echo $seller['zip']; ?></td>
<td><?php echo $seller['country']; ?></td>
<td><?php echo $seller['store_url']; ?></td>
<td><?php echo $seller['main_site']; ?></td>
<td><?php echo $seller['main_vertical']; ?></td>
<td><?php echo $seller['main_category']; ?></td>
<td><?php echo $seller['birthday']; ?></td>
<td><?php echo $seller['notes']; ?></td>
<td class="actions">
<?php echo $this->Html->link(__('Edit'), array('controller' => 'sellers', 'action' => 'edit', $seller['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'sellers', 'action' => 'delete', $seller['id']), null, __('Are you sure you want to delete # %s?', $seller['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $this->Html->link(__('New Seller'), array('controller' => 'sellers', 'action' => 'add')); ?> </li>
</ul>
</div>
</div>
<div class="related">
<h3><?php echo __('Related Meetings'); ?></h3>
<?php if (!empty($accountManager['Meeting'])): ?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php echo __('Interface'); ?></th>
<th><?php echo __('Date'); ?></th>
<th><?php echo __('Notes'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
<?php
$i = 0;
foreach ($accountManager['Meeting'] as $meeting): ?>
<tr>
<td><?php echo $this->Html->link($meeting['interface'], array('controller' => 'meetings', 'action' => 'view', $meeting['id'])); ?></td>
<td><?php echo $meeting['date']; ?></td>
<td><?php echo $meeting['notes']; ?></td>
<td class="actions">
<?php echo $this->Html->link(__('Edit'), array('controller' => 'meetings', 'action' => 'edit', $meeting['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'meetings', 'action' => 'delete', $meeting['id']), null, __('Are you sure you want to delete # %s?', $meeting['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $this->Html->link(__('New Meeting'), array('controller' => 'meetings', 'action' => 'add')); ?> </li>
</ul>
</div>
</div>
Upvotes: 1
Views: 7206
Reputation: 2759
You doesn't have enough memory for php script, add this:
ini_set('memory_limit', '-1');
NOTE: This tell to php interprer to use all memory that script to need so you can take a look to set it as your environment.
Upvotes: 1