namespace issue

20 views
Skip to first unread message

Brian Ramsay

unread,
Apr 19, 2014, 9:26:13 AM4/19/14
to habar...@googlegroups.com
I'm having a problem converting an old theme of mine to the newest version of Habari.

Without 'namespace Habari;' in theme.php I get errors saying that it can't find the class 'Theme', 'Format', 'Post', etc. But if I put 'namespace Habari;' in it tells me it can't find my theme's class.
Error: Class 'Janus' not found in system/classes/themes.php line 383

The only way I can get it to work is if I explicitly use 'Habari\' on every object, which is getting a litlle annoying, and I don't see this in other themes that I look at. I can't tell what other themes are doing  to resolve this because I don't notice anything different about theme.php.

I'm assuming that I just don't know enough about PHP namespaces. Can anyone point me in the right direction?

Thanks,
Brian

Bryce Campbell

unread,
Apr 19, 2014, 10:14:53 AM4/19/14
to habar...@googlegroups.com

All PHP files need the namespace statement. It is annoying, but until something is done, that is how it will be.

--
--
To post to this group, send email to habar...@googlegroups.com
To unsubscribe from this group, send email to habari-dev-...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/habari-dev
---
You received this message because you are subscribed to the Google Groups "habari-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to habari-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Konzertheld

unread,
Apr 19, 2014, 10:16:26 AM4/19/14
to habar...@googlegroups.com
Hi Brian,

I assume "Janus" is your theme's name. Code like the following should work:

namespace Habari; 
class Janus extends Theme 
{
   public function action_init() {
     Format::apply( 'autop', 'comment_content_out' ); 
   } 

That would create a theme class named Janus in the Habari namespace and make use of the Format class from the Habari namespace.

If that does not work, it is possible you run an old version of Habari 0.10, I vaguely remember a bug concerning namespaces. Make sure you run the latest master from GitHub.

Hope that helps.

Chris Meller

unread,
Apr 19, 2014, 10:18:01 AM4/19/14
to Habari Dev
You have two options for managing the namespaces:

namespace Habari;

At the very beginning of your file to put your theme’s class in the Habari namespace.

Or prefix all class references in your theme.php file with \Habari\. So Theme Foo extends \Habari\Theme, \Habari\Stack::add(), and so on and so forth.

We are open to suggestions on how to properly fix that, if anyone has any. :)



Brian Ramsay

unread,
Apr 19, 2014, 12:30:02 PM4/19/14
to habar...@googlegroups.com
it is possible you run an old version of Habari 0.10, I vaguely remember a bug concerning namespaces. Make sure you run the latest master from GitHub.

If I remove the namespace declaration but use class Janus extends Habari\Theme it works. Hmmm, and I notice it says "powered by Habari 0.10-alpha", so it looks like that could be it. I'm using the latest master of https://github.com/habari/system and I guess I should be on the 0.9.2 branch instead.

Thanks!

Brian


--
--
To post to this group, send email to habar...@googlegroups.com
To unsubscribe from this group, send email to habari-dev-...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/habari-dev
---
You received this message because you are subscribed to a topic in the Google Groups "habari-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/habari-dev/dvml4m_xYJc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to habari-dev+...@googlegroups.com.

Chris Meller

unread,
Apr 19, 2014, 12:43:29 PM4/19/14
to Habari Dev
That’s right, master is our dev branch, we make new ones for releases (there should be a 0.9.2 tag you can use). 0.10 isn’t completely functional right now, so you’ll probably want to stick with 0.9 for a while.


You received this message because you are subscribed to the Google Groups "habari-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to habari-dev+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages