-- Codiac <[EMAIL PROTECTED]> wrote
(on Thursday, 17 July 2008, 10:39 AM -0700):
> I have to retract my previous mail, stating the issue is resolved. I've
> double checked and there's definitely something strange going on with adding
> filters to elements using Zend_Config_Xml. Not sure what it is (probably me
> again), so i need help.
>
> I played around with setting different (very wrong) options for the
> StripTags filter, so now I have the following in my config file:
Here's a simple XML config file I used:
<?xml version="1.0"?>
<configdata>
<form>
<elements>
<keywords>
<type>text</type>
<options>
<name>keywords</name>
<label>Keywords</label>
<filters>
<stripTags>
<filter>StripTags</filter>
<options>
<tagsAllowed>
<tag><![CDATA[<a>]]></tag>
<tag><![CDATA[<p>]]></tag>
</tagsAllowed>
<attributesAllowed>class</attributesAllowed>
<commentsAllowed>1</commentsAllowed>
</options>
</stripTags>
</filters>
</options>
</keywords>
</elements>
</form>
</configdata>
I then did the following script:
$config = new Zend_Config_Xml(dirname(__FILE__) . '/form.xml', 'form');
$form = new Zend_Form($config);
$filters = $form->keywords->getFilters();
var_export($filters);
and I get the following output:
array (
'Zend_Filter_StripTags' =>
Zend_Filter_StripTags::__set_state(array(
'commentsAllowed' => true,
'_tagsAllowed' =>
array (
'tag' =>
array (
'<a>' => NULL,
'<p>' => NULL,
),
),
'_attributesAllowed' =>
array (
'class' => NULL,
),
)),
)
As you can see, the filter is being correctly setup.
One thing to note when using configuration: the options you pass are
passed IN ORDER to the constructor of the filter -- you can't skip
options, nor can you pass them out-of-order -- which is why the below
config does not work. It's missing the first argument (corresponding to
'tagsAllowed'), and it's got commentsAllowed and attributesAllowed in
the wrong order.
> <filters>
> <striptags>
> <filter>StripTags</filter>
> <options>
> <commentsAllowed>
> <tag><![CDATA[<p>]]></tag>
> </commentsAllowed>
> <attibutesAllowed>
> <attrib>class</attrib>
> </attibutesAllowed>
> </options>
> </striptags>
> </filters>
>
> I used $form->getElement('body')->getFilter('StripTags') to get the filter
> from the element and used a simple print_r to check how it was setup:
>
> Zend_Filter_StripTags Object([commentsAllowed] => [_tagsAllowed:protected]
> => Array([<p> => Array())
> [_attributesAllowed:protected] => Array([class] => ))
>
>
> ???
>
> When I use the following config of options:
>
>
> <filters>
> <striptags>
> <filter>StripTags</filter>
> <options>
> <tagsAllowed>
> <tag><![CDATA[<p>]]></tag>
> </tagsAllowed>
> <commentsAllowed>
> <![CDATA[<p>]]>
> </commentsAllowed>
> <attibutesAllowed>
> <attrib>class</attrib>
> </attibutesAllowed>
> </options>
> </striptags>
> </filters>
>
> I get:
>
> Zend_Filter_StripTags Object([commentsAllowed] => 1 [_tagsAllowed:protected]
> => Array([tag] => Array([<p>] => ))
>
> [_attributesAllowed:protected] => Array([<p>] => ))
>
> What the !@&$????
>
> Questions:
> Do I need to add all options in the config file for a filter? Is there a
> particular order in which to add those options?
>
> No matter which order I use for setting the options....they simple don't get
> set properly! Does it have anything to do with the following code in
> Zend_Form_Element::_loadFilter?
>
> if (empty($filter['options'])) {
> $instance = new $name;
> } else {
> $r = new ReflectionClass($name);
> if ($r->hasMethod('__construct')) {
> $instance = $r->newInstanceArgs((array) $filter['options']);
> } else {
> $instance = $r->newInstance();
> }
> }
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/