Wednesday, September 1, 2010

Defining XML in default.ctp for use globally

Hi there

I am creating a site with an XML file with all the site changables
like email, phone number, address etc. Currently these are prone to
change so I want to keep the simplicity of using XML.

Problem is I have to keep cutting and pasting the same bit of code in
all my view files well, every page actually and that's bad.

I simply want to call the XML once, set it in a variable and on my
pages, I want to simply call that variable. So for instance, on my
contacts page, I want to get my XML <?php
$xmlConfiguration_array["Config"]["Numbers"]["office"] ?> and display
it to the page but what i've discovered is that if I set
$xmlConfiguration_array variable in the default.ctp file, I can't
access it anywhere else on the site.

Here is the function that I use to load the XML and it works fine.

function parseConfig_xml() {
App::import('Xml');
$configuration_xml = file_get_contents("xml/configuration.xml");
$parsedConfiguration_xml = & new XML($configuration_xml);
$parsedConfiguration_xml = Set::reverse($parsedConfiguration_xml);

return $parsedConfiguration_xml;
};

$xmlConfiguration_array = parseConfig_xml();

What's the best way of defining my configuration XML for use over the
entire site?

Many thanks in advance for the help and advice.

Akas

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: