Important! All Kohana-related posts are now at http://kohana.lillem4n.se.
A friend of mine needed to use the Kohana XML-module to create XML with a XSLT-stylesheet attatched to it. This is a quick example of how you could do that. There are several other ways, but this is pretty straight forward.
The following code should be placed inside a controller method:
// First we need a DOM document do begin with
$dom = new DomDocument('1.0', 'UTF-8');
// Format the output so we can read it more easily
$dom->formatOutput = true;
// This sets the used XSL stylesheet to "example.xsl"
$dom->appendChild($dom->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="example.xsl"'));
// We need a root node in the XML
$xml_root = $dom->appendChild($dom->createElement('root'));
// This is the big XML data... database queries and other nice data should be in here
// Right now there is only a tiny bit of foo-node and bar-content
$someXmlContent = array('foo' => 'bar');
// Put the $someXmlContent inside the root-node
xml::toXML($someXmlContent, $xml_root);
// Write to screen
echo $dom->saveXML();
/** Produces
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<root>
<foo>bar</foo>
</root>
*/
// End of PHP code
Hashes: #kohana xslt #xslt #kohana xml module #kohana module #kohana #xml #php
2010-01-10
2010-01-06
New form rules
Important! All Kohana-related posts are now at http://kohana.lillem4n.se.
The module formrules is updated with two new methods: futureTimeStamp() and pastTimeStamp().
This can simply be passed in a form validation to check a string for both validation to strtotime() and so it is either in the future or in the past. Example:
This is an update to this post.
Hashes: #kohana form rules module #kohana module #kohana #form validation #php
The module formrules is updated with two new methods: futureTimeStamp() and pastTimeStamp().
This can simply be passed in a form validation to check a string for both validation to strtotime() and so it is either in the future or in the past. Example:
$post->add_rules('someFormField', 'formrules::futureTimeStamp')
This is an update to this post.
Hashes: #kohana form rules module #kohana module #kohana #form validation #php
Labels:
form validation,
kohana,
kohana form rules module,
kohana module,
php
Subscribe to:
Posts (Atom)