The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Mon May 07, 2012 1:49 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Sep 05, 2011 8:49 pm
Posts: 15
Hi all,

I would like to recover some data of the XML file to display them with PHP :
<author> .....</author>
<version> ....</version>
etc

I've tried this :
Code:
<?php echo $this->xml->version;?>

It's a shame :'(

Any solution will be very appreciate !
Thanks in advance,

Regards


Last edited by Tioutankhamon on Mon May 07, 2012 9:20 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon May 07, 2012 6:37 pm 
Joomla! Guru
Joomla! Guru

Joined: Sat Jan 21, 2006 8:42 pm
Posts: 925
Code asumes that you use it in your index.php file from your template and it loads the templateDetails xml file, if you need another file change the path
Code:
$xml = simplexml_load_file(__DIR__ .'/templateDetails.xml');
echo htmlentities((string) $xml->author);


Top
 Profile  
 
PostPosted: Mon May 07, 2012 7:22 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Sep 05, 2011 8:49 pm
Posts: 15
Thanks you for your answer.

This is about a component, so I should write :
Code:
$xml = simplexml_load_file(__DIR__ .'components/com_name-of-the-component/file.xml');

and add :
Code:
<?php echo htmlentities((string) $xml->author); ?>

in the default.php file where I want to diplay these datas.

but I stll have the same notice :
Notice: Trying to get property of non-object in C:\wamp\www\......


Last edited by Tioutankhamon on Mon May 07, 2012 8:13 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon May 07, 2012 8:04 pm 
Joomla! Guru
Joomla! Guru

Joined: Sat Jan 21, 2006 8:42 pm
Posts: 925
then your path to the file is wrong, also both lines should be in the same file


Top
 Profile  
 
PostPosted: Mon May 07, 2012 8:08 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Sep 05, 2011 8:49 pm
Posts: 15
Thanks again.
Yes, the two lines are in "default.php"

I will try to change the path to the XML file.


Top
 Profile  
 
PostPosted: Mon May 07, 2012 8:23 pm 
Joomla! Guru
Joomla! Guru

Joined: Sat Jan 21, 2006 8:42 pm
Posts: 925
in your code above you missed a slash after the __DIR__, should be __DIR__.'/folder/file.xml'
also __DIR__ points to the current folder, for the path you posted try
JPATH_SITE .'/components/com_name-of-the-component/file.xml'


Top
 Profile  
 
PostPosted: Mon May 07, 2012 9:19 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Sep 05, 2011 8:49 pm
Posts: 15
It's fine and perfect. God bless you, RedEye !

Thanks a lot for your help.


Top
 Profile  
 
PostPosted: Tue May 08, 2012 5:59 am 
Joomla! Guru
Joomla! Guru

Joined: Sat Jan 21, 2006 8:42 pm
Posts: 925
You`re welcome
if it`s your post on the google group it would be nice to add a link to this thread there, or just add the 2 lines there


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 



Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group