I call for collective wisdom on this one. I am having the following extremely weird bug.
I have a model named File.php. I have used it in several places in my app. But now it doesn't seem to work.
In this case, it works in my Template.php:
$this->Behaviors->load('Containable');
$this->contain(
array(
'User',
'TemplatesUserType' => array(
'UserType',
'FilesTemplatesUserType'=>array('File')
)
)
);
$template=$this->find('first',array('conditions'=>array('Template.id'=>$template_id,"Template.user_id"=>$user['User']['id'])));
This also works in FilesTemplatesUserTypesController:
$this->FilesTemplatesUserType->File->recursive=-1;
$file=$this->FilesTemplatesUserType->File->findByName($name);
if(gettype($file)=="array" && count($file)>0){
$file_id=$file["File"]["id"];
}
else{
$this->FilesTemplatesUserType->File->create();
$this->FilesTemplatesUserType->File->save(array("File"=>array("name"=>$name)));
$file_id=$this->FilesTemplatesUserType->File->getInsertID();
}
$this->request->data["FilesTemplatesUserType"]["file_id"]=$file_id;
}
$this->FilesTemplatesUserType->create();
$this->FilesTemplatesUserType->save($this->request->data);
Both cases work, perfectly fine. But now, from model Document.php, it fails throwing a 500 internal server error:
$this->Behaviors->load("Containable");
$this->contain(array(
"UsersVersion"=>array(
"conditions"=>array("UsersVersion.user_id !="=>$user["User"]["id"]),
"User"
),
"Draft"=>array(
"fields"=>array("Draft.id,Draft.template_id,Draft.name"),
"Template"=>array(
"fields"=>array("Template.id, Template.name, Template.user_id"),
"TemplatesUserType"=>array(
"DraftsUser"=>array(
"User"
),
"FilesTemplatesUserType"=>array("FilesUsersVersion","File")
)
)
)
)
);
$draft=$this->findById($document_id);
But it is until I remove the "File" that works.
To debug, I tried this in the same file:
$model=$this->Draft->Template->TemplatesUserType->FilesTemplatesUserType->File;
$model->recursive=-1;
$file=$model->findByName("Ident");
It throws an error at line 88 in CORE/Utility/File.php
indicating that $path has: array("class"=>"File","alias"=>"File")
instead of a string
and the following error message: Fatal error: Call to undefined method File::findByName() in C:\Inetpub\vhosts\*******.com\httpsdocs\eolas\app\Controller\DocumentsController.php on line 245
To make matters more confusing, this works from my Template.php model:
$model=$this->TemplatesUserType->FilesTemplatesUserType->File;
$model->recursive=-1;
$file=$model->findByName("Ident");
It appears that somehow the error occurs depending on the recursive level that the model File is being called and that is when it might get in conflict with File.php Utility class.
My question is: Why is it working perfectly in some places and until now is failing? Is there something to CakePHP inner workings that I am hitting correctly by chance and now I am losing it?
I hope you can steer me in the right direction (and not to have to change my model name, =P).
Thank you very much in advance!