Zend navigation findActive returns null - php

I have a problem with Zend navigation and finding active element of menu.
I build an Zend 1.12 application with modules, and read the navigation from xml file.
I wrote a simple helper which store information about current page, and to find this page I use function:
protected function findDeepestActivePage()
{
$naviHelper = $this->getView()->navigation();
$renderInvisible = $naviHelper->getRenderInvisible();
$result = $naviHelper->setRenderInvisible(true)->findActive($naviHelper->getContainer());
$naviHelper->setRenderInvisible($renderInvisible);
if (empty($result)) {
return null;
}
return $result['page'];
}
But in few elements of menu that function can't find active element. Navigation part which is problematic(elements from menu users):
<admin route="admin.summary" id="admin" resource="admin.index.index" visible="1">
<label>Panel Administracyjny</label>
<pages>
<main route="admin.summary" id="amain" resource="admin.index.index" visible="1">
<pages>
<summary route="admin.summary" resource="admin.index.index">
<label>Podsumowanie</label>
<module>admin</module>
<controller>index</controller>
<action>index</action>
</summary>
</pages>
</main>
<users route="admin.users.list" resource="admin.user.index" id="users" visible="1">
<label>Użytkownicy</label>
<pages>
<list route="admin.users.list" resource="admin.user.index" visible="0">
<label>Lista użytkowników</label>
<module>admin</module>
<controller>user</controller>
<action>index</action>
</list>
<add route="admin.users.add" resource="admin.user.add" visible="0">
<label>Dodaj użytkownika</label>
<module>admin</module>
<controller>user</controller>
<action>add</action>
</add>
<details route="admin.users.details" resource="admin.user.details" visible="0">
<label>Szczególy użytkownia</label>
<module>admin</module>
<controller>user</controller>
<action>details</action>
</details>
<edit route="admin.users.edit" resource="admin.user.edit" visible="0">
<label>Edycja użytkownika</label>
<module>admin</module>
<controller>user</controller>
<action>edit</action>
</edit>
</pages>
</users>
</pages>
</admin>
I have other part of navigation with module panel and there is similar part in it and works fine. I try to solve the problem, but everything I found was not helpfull.

Related

PHP/XML - Problem with default namespaces when append fragment

I have the original file and I want to append fragment in security tag.
<!-- Original File -->
<example>
<header>
<facticeA>123</facticeA>
<facticeB>456</facticeB>
</header>
<body>
<facticeC>789</facticeC>
</body>
<security></security>
</example>
<!-- ------------ -->
<!-- Original Fragment -->
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="_eb0b47cc-d4b0-44ba-a08c-90047e3a8b03" IssueInstant="2022-07-18T14:08:46.138Z" Version="2.0">
<saml2:Issuer></saml2:Issuer>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">XXXXXXXX</Signature>
</saml2:Assertion>
<!-- ----------------- -->
I use "createDocumentFragment()" and "appendXml()" PHP functions
And I have this result.
<!-- Final File -->
<example>
<header>
<facticeA>123</facticeA>
<facticeB>456</facticeB>
</header>
<body>
<facticeC>789</facticeC>
</body>
<security>
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:default="http://www.w3.org/2000/09/xmldsig#" ID="_eb0b47cc-d4b0-44ba-a08c-90047e3a8b03" IssueInstant="2022-07-18T14:08:46.138Z" Version="2.0">
<saml2:Issuer/>
<default:Signature xmlns="http://www.w3.org/2000/09/xmldsig#">XXXXXXXX</default:Signature>
</saml2:Assertion>
</security>
</example>
<!-- ---------- -->
The inserted fragment is not the same than original fragment.
"Signature" tag become "default:Signature" tag. And the namespace "xmldsig" present in Signature tag is append to Assertion tag with word "default"
If I delete namespace "xmldsig" in the Signature tag I have no problem.
The inserted fragment is the same than original fragment.
This seems to be a bug in the node import. A possible workaround is to define a prefix for this namespace on the document element.
$document = new DOMDocument();
$document->preserveWhiteSpace = false;
$document->loadXML($exampleXML);
$xpath = new DOMXpath($document);
$document->documentElement->setAttributeNS(
'http://www.w3.org/2000/xmlns/', 'xmlns:sig', 'http://www.w3.org/2000/09/xmldsig#'
);
$fragment = $document->createDocumentFragment();
$fragment->appendXML($samlXML);
foreach ($xpath->evaluate('(//security)[1]') as $security) {
$security->appendChild($fragment);
}
$document->formatOutput = true;
echo $document->saveXML();
Output:
<?xml version="1.0"?>
<example xmlns:sig="http://www.w3.org/2000/09/xmldsig#">
<header>
<facticeA>123</facticeA>
<facticeB>456</facticeB>
</header>
<body>
<facticeC>789</facticeC>
</body>
<security>
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="_eb0b47cc-d4b0-44ba-a08c-90047e3a8b03" IssueInstant="2022-07-18T14:08:46.138Z" Version="2.0">
<saml2:Issuer/>
<sig:Signature xmlns="http://www.w3.org/2000/09/xmldsig#">XXXXXXXX</sig:Signature>
</saml2:Assertion>
</security>
</example>
Interesting enough, if you create the nodes using DOM methods it works correctly:
$document = new DOMDocument();
$document->preserveWhiteSpace = false;
$document->loadXML($exampleXML);
$xpath = new DOMXpath($document);
foreach ($xpath->evaluate('(//security)[1]') as $security) {
$security->appendChild(
$saml = $document->createElementNS('urn:oasis:names:tc:SAML:2.0:assertion', 'saml2:Assertion')
);
$saml->setAttribute('ID', '_eb0b47cc-d4b0-44ba-a08c-90047e3a8b03');
$saml->appendChild(
$document->createElementNS('urn:oasis:names:tc:SAML:2.0:assertion', 'saml2:Issuer')
);
$saml->appendChild(
$signature = $document->createElementNS('http://www.w3.org/2000/09/xmldsig#', 'Signature')
);
$signature->textContent = 'XXXXXXXX';
}
$document->formatOutput = true;
echo $document->saveXML();
Output:
<?xml version="1.0"?>
<example>
<header>
<facticeA>123</facticeA>
<facticeB>456</facticeB>
</header>
<body>
<facticeC>789</facticeC>
</body>
<security>
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="_eb0b47cc-d4b0-44ba-a08c-90047e3a8b03">
<saml2:Issuer/>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">XXXXXXXX</Signature>
</saml2:Assertion>
</security>
</example>
You could create a recursive function the recreates the nodes from the fragment.

XML PHP Get children value

XML:
<Result xmlns="" xmlns:xsi="" totalResultsAvailable="0" totalResultsReturned="0" schk="true" totalLooseOffers="0" xsi:schemaLocation="">
<details>
<ID></ID>
<applicationVersion>1.0</applicationVersion>
<applicationPath/>
<date>2016-05-23T12:17:16.369-03:00</date>
<elapsedTime>17</elapsedTime>
<status>success</status>
<message>success</message>
</details>
<category id="1">
<thumbnail url="http://image.google.com/test.jpg"/>
<links>
<link url="www.google.com" type="category"/>
<link url="www.google2.com" type="xml"/>
</links>
<name>Category</name>
<filters>
<filter id="1" name="Filter1">
<value id="1" value="Test1"/>
<value id="2" value="Test2"/>
<value id="3" value="Test3"/>
</filter>
<filter id="2" name="Filter2">
<value id="1" value="Test4"/>
<value id="2" value="Test5"/>
<value id="3" value="Test6"/>
</filter>
</filters>
</category>
</Result>
PHP:
$xml = simplexml_load_file("http://xml.com");
foreach($xml->category->filters as $filters){
foreach($filters->children() as $child){
echo $child['value'];
}
}
I'm trying to get the filters value, but nothing shows with the code i have. I saw something about xpath but don't know if it's applicable in this situation. Do you have any clue?
--
When the XML looks like this:
<Result xmlns="" xmlns:xsi="" totalResultsAvailable="0" totalResultsReturned="0" schk="true" totalLooseOffers="0" xsi:schemaLocation="">
<details>
<ID></ID>
<applicationVersion>1.0</applicationVersion>
<applicationPath/>
<date>2016-05-23T12:17:16.369-03:00</date>
<elapsedTime>17</elapsedTime>
<status>success</status>
<message>success</message>
</details>
<subCategory id="1">
<thumbnail url="http://image.google.com/test.jpg"/>
<name>Subcategory</name>
</subCategory>
<subCategory id="2">
<thumbnail url="http://image.google.com/test2.jpg"/>
<name>Subcategory2</name>
</subCategory>
</Result>
Then am able to do this:
foreach($xml->subCategory as $subCategory){
$categoryId = $subCategory['id'];
$categoryName = $subCategory->name;
}
The elements you reference as $child in the inner loop actually point to the <filter> nodes, not the children <value> nodes you are attempting to target attributes for. So this really is just a matter of extending the outer foreach loop to iterate over $xml->category->filters->filter rather than its parent $xml->category->filters.
// Iterate the correct <filter> node, not its parent <filters>
foreach ($xml->category->filters->filter as $filter) {
foreach($filter->children() as $child){
echo $child['value'] . "\n";
}
}
Here it is in demonstration: https://3v4l.org/Rqc4Y
Using xpath, you can target the inner nodes directly.
$values = $xml->xpath('//category/filters/filter/value');
foreach ($values as $value) {
echo $value['value'];
}
https://3v4l.org/vPhKE
Both of these examples output
Test1
Test2
Test3
Test4
Test5
Test6

Install new theme for Magento. Fatal error: Class 'ThemeAdminPanel_ExtraConfig_Helper_Data' not found in .../app/Mage.php on line 546

I install new theme for magento and change "System > Configuration"> Design.
I write name for new theme in themes options. After "Save config" now I get error when try go to "System > Configuration": Class 'ThemeAdminPanel_ExtraConfig_Helper_Data' not found in .../app/Mage.php on line 546
When upload files for new theme I see that create new folders in app/code/local:
/app/code/local/ThemeAdminPanel
/app/code/local/Mage
app/code/local/ThemeAdminPanel/ExtraConfig/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<ThemeAdminPanel_ExtraConfig>
<version>1.0.0</version>
<depends>
<!-- no dependencies -->
</depends>
</ThemeAdminPanel_ExtraConfig>
</modules>
<global>
<models>
<!-- ... -->
<ExtraConfig>
<class>ThemeAdminPanel_ExtraConfig_Model</class>
</ExtraConfig>
<!-- ... -->
</models>
<helpers>
<ExtraConfig>
<class>ThemeAdminPanel_ExtraConfig_Helper</class>
</ExtraConfig>
</helpers>
<resources />
<extraconfig />
<blocks>
<mygeneral><class>ThemeAdminPanel_ExtraConfig_Block</class></mygeneral>
</blocks>
</global>
<!---->
<default>
<mygeneral>
<generaloptions>
<menutype>1</menutype>
<topbanner>default/phone.png</topbanner>
<googlefont>Source Sans Pro:200,200italic,300,300italic,regular,italic,600,600italic,700,700italic,900,900italic</googlefont>
<additional_nav>Contacts</additional_nav>
<additional_nav_href>index.php/contacts/</additional_nav_href>
<topbtn>1</topbtn>
<enable_ajax>1</enable_ajax>
<hide_wish>0</hide_wish>
<hide_compare>0</hide_compare>
<hide_cart>0</hide_cart>
</generaloptions>
<background>
<maincolor>F7F7F9</maincolor>
<pattern>default/pattern.png</pattern>
<bg_repeat></bg_repeat>
<bg_attachment></bg_attachment>
<bg_position_x></bg_position_x>
<bg_position_y></bg_position_y>
</background>
<product_list>
<shorten_name>23</shorten_name>
<layer>1</layer>
<sale_label>1</sale_label>
<sale_label_text>Sale</sale_label_text>
<new_label>1</new_label>
<new_label_text>New</new_label_text>
</product_list>
<share>
<facebookgroupid>115403961948855</facebookgroupid>
<twittername>dedalx</twittername>
<use_share>1</use_share>
<share_code><![CDATA[<span class='st_fblike_hcount' displayText='Facebook Like'></span>
<span class='st_twitter_hcount' displayText='Tweet'></span>
<span class='st_pinterest_hcount' displayText='Pinterest'></span>
<span class='st_plusone_hcount' displayText='Google +1'></span>]]></share_code>
</share>
<slideshow>
<use_slideshow>1</use_slideshow>
<hide_right_sliders>0</hide_right_sliders>
<autoplay>1</autoplay>
<speed>8000</speed>
<slides_count>2</slides_count>
</slideshow>
<productpage>
<use_zoom>1</use_zoom>
<use_carousel>1</use_carousel>
</productpage>
<colors>
<active_color>6CBE42</active_color>
<button_hover>58BAE9</button_hover>
</colors>
<customcode>
<customcss>/* Add any CSS code here */</customcss>
<customjs>// Add any JavaScript code here</customjs>
</customcode>
</mygeneral>
</default>
<!---->
<adminhtml>
<menu>
<metroshop translate="title" module="ExtraConfig">
<title>MetroShop</title>
<sort_order>6666</sort_order>
<children>
<settings translate="title" module="ExtraConfig">
<title>Theme Settings</title>
<sort_order>10</sort_order>
<action>adminhtml/system_config/edit/section/mygeneral</action>
</settings>
</children>
</metroshop>
</menu>
<layout>
<updates>
<ExtraConfig>
<file>options.xml</file>
</ExtraConfig>
</updates>
</layout>
</adminhtml>
</config>
app/code/local/ThemeAdminPanel/ExtraConfig/Helper/Data.php:
<?php
class ThemeAdminPanel_ExtraConfig_Helper_Data extends Mage_Core_Helper_Abstract
{
}
?>
I see that this class added to code but can't find in /app/Mage.php in this part:
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
As I understand have some problem in theme about adding class to Mage.php.
Additional in file etc/config.xml don't have Class 'ThemeAdminPanel_ExtraConfig_Helper_Data'. But' I'm not sure how to fix and solve this problem.
Please, help me to solve this problem.
All cache clean by FTP.

PHP - Parse XML contained within XML element and Output into XML doc

I'm looking to parse out only the content of the element below into its own XML document, but am unsure of the proper PHP method to use. XML data in boxb.php is unable to be modified.
EX:
Parsing code:
<?php
include 'boxb.php';
$boxb = new SimpleXMLElement($xmlstr);
$boxb->ad[0]->content;
echo $boxb->ad[0]->content;
?>
boxb.php contains the following:
<?php
$xmlstr = <<<XML
<boxb>
<ad type="agnostic_template">
<url><![CDATA[http://ads.cookie.com/8/redir/1db04901-225e-11e4-86f3-bc305bf4914b/0/632361]]></url>
<track />
<content>
<VAST version="2.0">
<Ad id="228">
<InLine>
<AdSystem version="4.11.0-10">LiveRail</AdSystem>
<AdTitle><![CDATA[TV Overlay PNG]]></AdTitle>
<Description />
<Error><![CDATA[http://t4.liverail.com/?metric=error&erc=[ERRORCODE]&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=&y=&xy=&redirect=]]></Error>
<Impression id="LR"><![CDATA[http://t4.liverail.com/?metric=impression&cofl=0&flid=0&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=29&y=29&xy=9dae&z2=0.00000]]></Impression>
<Impression id="QC"><![CDATA[http://pixel.quantserve.com/pixel/p-d05JkuPGiy-jY.gif?r=6662]]></Impression>
<Impression id="CS"><![CDATA[http://b.scorecardresearch.com/p?c1=1&c2=9864668&c3=1331&c4=&c5=09]]></Impression>
<Impression><![CDATA[http://load.exelator.com/load/?p=104&g=440&j=0]]></Impression>
<Impression><![CDATA[http://navdmp.com/usr?vast=http%3A%2F%2Ft4.liverail.com%2F%3Fmetric%3Dmsync%26p%3D78]]></Impression>
<Impression><![CDATA[http://pixel.tapad.com/idsync/ex/receive?partner_id=LIVERAIL&partner_device_id=97838239447]]></Impression>
<Impression><![CDATA[http://t4.liverail.com/?metric=rsync&p=3016&redirect=http%3A%2F%2Fliverail2waycm-atl.netmng.com%2Fcm%2F%3Fredirect%3Dhttp%253A%252F%252Ft4.liverail.com%252F%253Fmetric%253Dcsync%2526p%253D3016%2526s%253D(NM-UserID)]]></Impression>
<Impression><![CDATA[http://t4.liverail.com/?metric=rsync&p=3017&redirect=http%3A%2F%2Fm.xp1.ru4.com%2Factivity%3F_o%3D62795%26_t%3Dcm_rail]]></Impression>
<Impression><![CDATA[http://n.us1.dyntrk.com/adx/lr/sync_lr.php?lrid=97838239447]]></Impression>
<Creatives>
<Creative sequence="1" id="8455">
<NonLinearAds>
<NonLinear width="300" height="60">
<StaticResource creativeType="image/png"><![CDATA[http://cdn.liverail.com/adasset/228/8455/overlay.png]]></StaticResource>
<NonLinearClickThrough><![CDATA[http://t4.liverail.com/?metric=clickthru&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=&y=&xy=&redirect=http%3A%2F%2Fwww.liverail.com]]></NonLinearClickThrough>
</NonLinear>
<TrackingEvents>
<Tracking event="acceptInvitation"><![CDATA[http://t4.liverail.com/?metric=accept&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=&y=&xy=]]></Tracking>
<Tracking event="collapse"><![CDATA[http://t4.liverail.com/?metric=minimize&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=&y=&xy=]]></Tracking>
</TrackingEvents>
</NonLinearAds>
</Creative>
<Creative sequence="1" id="8455">
<CompanionAds>
<Companion width="300" height="60">
<StaticResource creativeType="image/jpeg"><![CDATA[http://cdn.liverail.com/adasset/228/8455/300x60.jpg]]></StaticResource>
<TrackingEvents>
<Tracking event="creativeView"><![CDATA[http://t4.liverail.com/?metric=companion&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=&y=&xy=]]></Tracking>
</TrackingEvents>
<CompanionClickThrough><![CDATA[http://t4.liverail.com/?metric=cclickthru&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=&y=&xy=&redirect=http%3A%2F%2Fwww.liverail.com]]></CompanionClickThrough>
</Companion>
<Companion width="300" height="250">
<StaticResource creativeType="image/jpeg"><![CDATA[http://cdn.liverail.com/adasset/228/8455/300x250.jpg]]></StaticResource>
<TrackingEvents>
<Tracking event="creativeView"><![CDATA[http://t4.liverail.com/?metric=companion&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=&y=&xy=]]></Tracking>
</TrackingEvents>
<CompanionClickThrough><![CDATA[http://t4.liverail.com/?metric=cclickthru&pos=1&coid=135&pid=1331&nid=1331&oid=228&olid=2281331&cid=8455&tpcid=&vid=&amid=&cc=default&pp=&vi=0&vv=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=7&adt=0&did=&buid=&scen=&mca=&mma=&mct=0&url=http%3A%2F%2Fwww.iab.net%2Fguidelines%2F508676%2Fdigitalvideo%2Fvast%2Fvast_xml_samples&trid=53ea9957dc20a5.06241648&bidf=0.00000&bids=0.00000&bidt=1&bidh=0&bidlaf=0&cb=6662.66.104.228.162.0&ver=1&w=&wy=&x=&y=&xy=&redirect=http%3A%2F%2Fwww.liverail.com]]></CompanionClickThrough>
</Companion>
</CompanionAds>
</Creative>
</Creatives>
<Extensions />
</InLine>
</Ad>
</VAST>
<!-- 321 US_NEWJERSEY_NEWYORK_METUCHEN 08840 -->
</content>
</ad>
</boxb>
XML;
?>
If you want to get the XML-data, use asXML(),
echo $boxb->ad[0]->content->asXML();
And if you want to create your own XML document, you could use for example,
$myXML = new SimpleXMLElement($boxb->ad[0]->content->asXML());
echo $myXML->asXML();
Which would echo,
<!--?xml version="1.0"?-->
<content>
...
</content>
<?php
include 'boxb.php';
// Load string and parse as XML
$boxb = simplexml_load_string($xmlstr);
// Extract "content" element from loaded XML
$content = $boxb->ad->content;
// Convert extracted info into XML
$new_xml = $content->asXML();
// Send a header tag to the browser, stating that this info is XML
header('Content-type: application/XML');
// Print the actual XML
echo $new_xml;
?>

magento - category name and image in static block?

How can i reference category name and image from a static block in magento through the magento backend? I'm running 1.7.
I am not aware of a way in which you can easily reference these values from within a static block.
Instead, I would suggest you create and use a widget (one of the most underused features of Magento in my opinion) which will provide a much cleaner and more extendible way of achieving this - though it does require more work upfront :)
Please see code below for a full (simplified) example of a Magento Widget which does exactly what you have asked from the static block:
app/etc/modules/YourCompany_Categorywidget.xml
<config>
<modules>
<MyCompany_Categorywidget>
<active>true</active>
<codePool>community</codePool>
</MyCompany_Categorywidget>
</modules>
</config>
app/code/community/MyCompany/Categorywidget/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<MyCompany_Categorywidget>
<version>1.0.0</version>
</MyCompany_Categorywidget>
</modules>
<global>
<blocks>
<categorywidget>
<class>MyCompany_Categorywidget_Block</class>
</categorywidget>
</blocks>
<helpers>
<categorywidget>
<class>MyCompany_Categorywidget_Helper</class>
</categorywidget>
</helpers>
</global>
</config>
app/code/community/MyCompany/Categorywidget/etc/widget.xml
<?xml version="1.0"?>
<widgets>
<category_widget type="categorywidget/catalog_category_widget_info" translate="name description" module="categorywidget">
<name>Category Info Block</name>
<description>Category Info Block showing name, image etc</description>
<parameters>
<block_title translate="label">
<required>1</required>
<visible>1</visible>
<label>Block Title</label>
<type>text</type>
</block_title>
<template>
<required>1</required>
<visible>1</visible>
<label>Template</label>
<type>select</type>
<value>categorywidget/info.phtml</value>
<values>
<default translate="label">
<value>categorywidget/info.phtml</value>
<label>Category Widget Info Block - Default Template</label>
</default>
<!-- Add different temmplates here for different block positions -->
</values>
</template>
<category translate="label">
<visible>1</visible>
<required>1</required>
<label>Category</label>
<type>label</type>
<helper_block>
<type>adminhtml/catalog_category_widget_chooser</type>
<data>
<button translate="open">
<open>Select Category...</open>
</button>
</data>
</helper_block>
<sort_order>10</sort_order>
</category>
</parameters>
</category_widget>
</widgets>
app/code/community/MyCompany/Categorywidget/Helper/Data.php
<?php
class MyCompany_Categorywidget_Helper_Data extends Mage_Core_Helper_Abstract
{}
app/code/community/MyCompany/Categorywidget/Block/Catalog/Category/Widget/Info.php
<?php
class MyCompany_Categorywidget_Block_Catalog_Category_Widget_Info
extends MyCompany_Categorywidget_Block_Catalog_Category_Info
implements Mage_Widget_Block_Interface
{
protected function _prepareCategory()
{
$this->_validateCategory();
$category = $this->_getData('category');
if (false !== strpos($category, '/')) {
$category = explode('/', $category);
$this->setData('category', (int)end($category));
}
return parent::_prepareCategory();
}
}
app/code/community/MyCompany/Categorywidget/Block/Catalog/Category/Info.php
<?php
class MyCompany_Categorywidget_Block_Catalog_Category_Info extends Mage_Core_Block_Template
{
protected $_category;
protected function _beforeToHtml()
{
$this->_category = $this->_prepareCategory();
return parent::_beforeToHtml();
}
protected function _prepareCategory()
{
$this->_validateCategory();
return Mage::getModel('catalog/category')->load($this->_getData('category'));
}
protected function _validateCategory()
{
if (! $this->hasData('category')) {
throw new Exception('Category must be set for info block');
}
}
public function getCategoryName()
{
return $this->_category->getName();
}
public function getCategoryImage()
{
return $this->_category->getImageUrl();
}
}
app/design/frontend/base/default/template/categorywidget/info.phtml
<?php
$_categoryName = $this->getCategoryName();
$_categoryImage = $this->getCategoryImage();
?>
<div class="categoryinfo_block block">
<p><strong><?php echo $_categoryName ?></strong></p>
<img src="<?php echo $_categoryImage ?>" alt="<?php echo $_categoryName ?>" />
</div>
I wanted the image to link to the category as well so I added ...
app/code/community/MyCompany/Categorywidget/Block/Catalog/Category/Info.php
public function getCategoryUrl()
{
return $this->_category->getUrl();
}
app/design/frontend/base/default/template/categorywidget/info.phtml
<?php
$_categoryName = $this->getCategoryName();
$_categoryImage = $this->getCategoryImage();
$_categoryUrl = $this->getCategoryUrl();
?>
<div class="categoryinfo_block block">
<p><strong><?php echo $_categoryName ?></strong></p>
<a href="<?php echo $_categoryUrl ?>" title="<?php echo $_categoryName ?>" alt="<?php echo $_categoryName ?>">
<img src="<?php echo $_categoryImage ?>" alt="<?php echo $_categoryName ?>" />
</a>
</div>
If that helps anyone else?

Categories