2013-06-22 88 views
1

編輯:結果我的數據庫密鑰配置不正確,這意味着控制器試圖檢索賣方列表時就進入無限循環。 感謝您的幫助!CakePHP致命錯誤:允許的內存大小爲134217728字節用盡

CakePHP新手在這裏。

我使用cakePHP腳手架來顯示單個模型(帳戶經理)及其相關模型(賣方和會議)的內容。 目前有2個帳戶管理員(他們每個有3個屬性),220個賣家(大約20個屬性)和2個會議(4個屬性)在數據庫中。 一個星期前,這一切工作正常,但突然間,當我嘗試查看單個客戶經理的細節,我得到這個錯誤:

錯誤:用盡134217728個字節允許內存大小(試圖分配44613632字節) 文件:... \程序\查看\佈局\ default.thtml中 行: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> 
+0

你確定你沒有把線路放入無限循環? – Raptor

+3

把'死'放在視圖的盡頭。如果沒有錯誤,則佈局中會有一個循環。如果它有同樣的問題,請移動芯片,以確定負責的代碼行。 – AD7six

+0

@ AD7six,我試着添加die();但是之後我只是得到一個沒有錯誤代碼的白頁。 – wonderv

回答

1

你不有足夠的內存爲php腳本,加上:

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

注意:這告訴php解釋器使用腳本需要的所有內存,因此您可以看看它設置爲您的環境。

相關問題