CakePHP致命错误:允许的内存大小为134217728字节耗尽

时间:2013-06-22 10:27:01

标签: php cakephp cakephp-2.0 memory-size

编辑:结果我的数据库密钥配置不正确,这意味着控制器在尝试检索卖家列表时进入无限循环。 谢谢你的帮助!

CakePHP新手在这里。

我正在使用cakePHP脚手架来显示单个模型(客户经理)及其相关模型(卖家和会议)的内容。 目前有2个客户经理(每个有3个属性),大约220个卖家(约20个属性)和2个会议(有4个属性)在数据库中。 一周前,这一切都运行良好,但突然,当我尝试查看单个客户经理的详细信息时,我收到此错误:

错误:允许的内存大小为134217728字节耗尽(尝试分配44613632字节) 文件:... \ app \ View \ Layouts \ default.ctp 行:70

该行是:

<?php echo $this->fetch('content'); ?>

它是默认布局的一部分,再次由脚手架提供。

我尝试提高内存限制,但一段时间后代码就会超时。 此外,我似乎没有访问数据库那么多的信息来触发这样的事情。

我是CakePHP的新手,所以我的调试经验非常有限。

以下是控制器视图方法的片段:

    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));
}

以下是客户经理的模型:

    <?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'
        )
    );

}

以下是观点:

<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']); ?>
            &nbsp;
        </dd>
        <dt><?php echo __('Last Name'); ?></dt>
        <dd>
            <?php echo h($accountManager['AccountManager']['last_name']); ?>
            &nbsp;
        </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>

1 个答案:

答案 0 :(得分:1)

你没有足够的内存用于php脚本,请添加:

ini_set('memory_limit', '-1');

注意:这告诉php解释器使用脚本需要的所有内存,以便您可以将其设置为您的环境。