<![CDATA[ How to import a Policy from a xml in a snippet ? - My Forums]]> https://forums.modx.com/thread/?thread=98940 <![CDATA[How to import a Policy from a xml in a snippet ?]]> https://forums.modx.com/thread/98940/how-to-import-a-policy-from-a-xml-in-a-snippet#dis-post-534957
I had exported a custom XML file Policy from the manager of a specific project.
I want to import this file dynamicly from a snippet in a new project. To do that, I used modAccessPolicy method.

here's my code :

$data = file_get_contents('custom.policy.xml');
$xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);

$policy = $modx->newObject('modAccessPolicy');
$policy->set('data', $json);
$policy->save();


If any one could tell me the right way,
Thanks for your help laugh]]>
junicool Nov 29, 2015, 10:52 AM https://forums.modx.com/thread/98940/how-to-import-a-policy-from-a-xml-in-a-snippet#dis-post-534957
<![CDATA[Re: How to import a Policy from a xml in a snippet ?]]> https://forums.modx.com/thread/98940/how-to-import-a-policy-from-a-xml-in-a-snippet#dis-post-535046
Actually, I think Markus Schlegel is the author of that bit of code, so he deserves most of the credit.]]>
BobRay Nov 30, 2015, 04:21 PM https://forums.modx.com/thread/98940/how-to-import-a-policy-from-a-xml-in-a-snippet#dis-post-535046
<![CDATA[Re: How to import a Policy from a xml in a snippet ?]]> https://forums.modx.com/thread/98940/how-to-import-a-policy-from-a-xml-in-a-snippet#dis-post-535042 I based my work on yours, and now it works smiley]]> junicool Nov 30, 2015, 02:36 PM https://forums.modx.com/thread/98940/how-to-import-a-policy-from-a-xml-in-a-snippet#dis-post-535042 <![CDATA[Re: How to import a Policy from a xml in a snippet ? (Best Answer)]]> https://forums.modx.com/thread/98940/how-to-import-a-policy-from-a-xml-in-a-snippet#dis-post-534992
Here's what the Policy object looks like: http://bobsguides.com/modx-object-quick-reference.html#modAccessPolicy.

You might also look at the code of the NewsPublisher snippet. The third and fourth files here have code to create a Policy and Policy Template.

If you have a code editor that will let you run and debug php scripts (e.g., PhpStorm), you'll save a lot of time if you write the code in it and step through it to see what you're getting until you can get things in the correct form.

]]>
BobRay Nov 30, 2015, 12:54 AM https://forums.modx.com/thread/98940/how-to-import-a-policy-from-a-xml-in-a-snippet#dis-post-534992