External XML created by Concrete

Permalink
Hi,

I'm building a new block with a XML-based Flash file.

De XML must be an external loaded XML file. I created in the tools directory a phpscript that loads the XML (generated from the database).

The flashfile (in view.php) loads this file.

The code from the view.php
<script type="text/javascript">
   var flashvars = {};
   flashvars.xml = "/blocks/myblock/tools/xml.php?bID=<? echo $this->controller->getBlockID() ?>";
   flashvars.font = "font.swf";
   var attributes = {};
   attributes.wmode = "transparent";
   attributes.id = "slider";
      swfobject.embedSWF("/blocks/myblock/elements/flashfile-1.swf", "flash-container", "900", "360", "9", "/blocks/myblock/elements/flashfile-2.swf", flashvars, attributes);
</script>


The file that should be loaded is: /blocks/myblock/tools/xml.php?bID=<? echo $this->controller->getBlockID() ?>

The code in xml.php:
---start of file----
$myblock = BlockType::getByHandle('myblock');
$myblock->controller->bID = $_REQUEST['bID'];
$settings = $myblock->controller->build_xml();
echo <?xml.... ...
---end of file---


When de XML file is loaded, the function BlockType::getByHandle('myblock'); can't be recognized.

Which code should be added so that my function in xml.php will be recognized?
Which require_once, Loaders and modules?

Thank you!

DeWebmakers
 
andrew replied on at Permalink Reply
andrew
You're on the right track. It doesn't look like you'll have to change much in the tools file itself. The trouble I think is coming from how you're calling it

It looks like you're calling it directly as a php script. If you call it in another way, it will automatically load the libraries you need, instantiate a database object, etc...

Instead of this:

flashvars.xml = "/blocks/myblock/tools/xml.php?bID=<? echo $this->controller->getBlockID() ?>";

Try this:

$uh = Loader::helper('concrete/urls');
$bt = BlockType::getByHandle('myblock');
$url = $uh->getBlockTypeToolsURL($bt)."/xml?bID=".$this->controller->getBlockID();


And then

flashvars.xml = "<?=$url?>";

That should build a URL like

"index.php/tools/blocks/myblock/xml?bID=12345"

Which will then run your script, but wrapped in concrete, so that it will have access to the block types script, the database, etc...
DeWebmakers replied on at Permalink Reply
DeWebmakers
Hi Andrew,

Thank you! It was the solution for my problem.
Concrete5 keeps amazing me!