我以前沒有給出有關問題的良好信息。我的問題是,在創建蛋糕php中的下拉樹時.Cake PHP拋出此錯誤。創建樹時發生致命錯誤
Fatal error: Allowed memory size of 524288000 bytes exhausted (tried to allocate 429982192 bytes) in /home/isteam/public_html/upms/app/controllers/tests_controller.php on line 85
我試圖通過php inin函數增加運行時間的限制,但沒有成功。
ini_set('memory_limit','2000M');
我的代碼表的結構是這樣的
|id|parent_id|cat_name|
我的代碼如下
function admin_takecat(){
$this->layout=false;
$this->render(false);
Configure::write('debug',2);
App::import('Model','Category');
$this->cats=new Category();
$firstlevel=$this->cats->find('list',array('fields'=>array('Category.id','Category.cat_name'),'conditions'=>array('Category.parent_id'=>0,'department_id'=>9)));
$dropbox='<select>';
foreach($firstlevel as $id=>$val){
$dropbox.='<option value='.$id.'>'.$val.'</option>';
$count=$this->cats->find('count',array('conditions'=>array('Category.parent_id'=>0,'Category.department_id'=>9,'Category.parent_id'=>$id)));
if($count>0){
$dropbox=$this->_recursive($id,$dropbox,1);
}
}
$dropbox.='</select>';
echo $dropbox;
}
function _recursive($catid,$dropbox,$level){
App::import('Model','Category');
$this->cats=new Category();
$listcats=$this->cats->find('list',array('fields'=>array('Category.id','Category.cat_name'),'conditions'=>array('Category.parent_id'=>0,'Category.department_id'=>9,'Category.parent_id'=>$catid)));
$mark='';
for($i=1;$i<=1;$i++){
$mark.='-';
}
foreach($listcats as $id=>$val){
$dropbox.='<option value='.$id.'>'.$mark.$val.'</option>';
$count=$this->cats->find('count',array('conditions'=>array('Category.parent_id'=>0,'Category.department_id'=>9,'Category.parent_id'=>$id)));
if($count>0){
$dropbox.=$this->_recursive($id,$dropbox,$level+1);
}
}
return $dropbox;
}
請建議我該怎麼do..Or這樣做的任何其他方式..
Cake有一個[Tree行爲](http://book.cakephp.org/1.3/view/1339/Tree)內置;可能值得一看。 – Ross