1

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

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>
4

1 回答 1

1

您没有足够的内存用于 php 脚本,请添加以下内容:

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

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

于 2015-02-06T16:03:55.160 回答