Hi,
I have a file containing MyPage extends Page, and MyPage_Controller extends Page_Controller.
Now I want *onBeforePublish* trigger some filewriting (xml-file to be exported via ftp).
I tried:
function onBeforePublish(){
$xml = $this->renderWith('XML');
file_put_contents('/full/path/to/xml-file.xml', $xml);
}
Result:
ERROR [User Warning]: None of these templates can be found in theme 'xyz': XML.ss
IN POST /admin/pages/edit/EditForm
Next, I tried:
class MyPage extends Page
{
...
function onBeforePublish(){
$myPageController = new MyPage_Controller();
$myPageController->setDatacord($this);
$xml = $myPageController->xml();
file_put_contents('/full/path/to/xml-file.xml', $xml);
}
}
class myPage_Controller extends Page_Controller{
private static $allowed_actions = array (
'xml'
);
public function setDatacord($data){
$this->dataRecord = $data;
}
public function xml(){
$xml = $this->renderWith('XML');
return $xml;
}
}
....
Same Result, with a backtrace to the xml-action in MyPage_Controller.
Remark:
The MyPage-Object is only viewable to logged in users and therefore my third attempt:
function onBeforePublish(){
$request = Director::test($myPageURL.'xml');
$xml = $request->getBody();
...
}
fails due to a redirect to the Login-Form.
Any ideas how to solve this?
Btw:
The template XML.ss is in the themes/xyz/templates/includes folder.