Trying to add PHP to Joomla website crashed -


i've never done php coding before, i'm using forum extension chronoforums , i'm trying add php forums if user logged in display welcome: $user , if not display link login/register. here code tried, crashed forum page.

<?php    $user = jfactory::getuser();   $status = $user->guest;   if($status == 1) {       $url = "/forum/login";       echo "<a href=\"$url\">login/register</a>";   } else {        echo "<p>welcome: {$user->username}</p>";   }    ?>    

error:

    fatal error: class 'gcore\extensions\chronoforums\helpers\jfactory' not found in d:\wamp\www\administrator\components\com_chronoforums\extensions\chronoforums\helpers\elements.php on line 72 call stack #   time    memory  function    location 1   0.0008  687992  {main}( )   ..\index.php:0 2   0.1207  9311448 jsite->dispatch( )  ..\index.php:52 3   0.1248  9382296 jcomponenthelper::rendercomponent( )    ..\application.php:220 4   0.1318  9428368 jcomponenthelper::executecomponent( )   ..\helper.php:335 5   0.1322  9495248 require_once( 'd:\wamp\www\components\com_chronoforums\chronoforums.php' )  ..\helper.php:355 6   0.1401  10315576    gcore\libs\appj::call( )    ..\chronoforums.php:20 7   0.1402  10318272    gcore\libs\appj->dispatch( )    ..\app_j.php:290 8   0.2263  14214704    gcore\libs\view->renderview( )  ..\app_j.php:208 9   0.2267  14328112    include( 'd:\wamp\www\administrator\components\com_chronoforums\extensions\chronoforums\views\index.php' )  ..\view.php:69 10  0.2268  14328112    gcore\extensions\chronoforums\helpers\elements->header( )   ..\index.php:6 

here whole page added code to:

<?php /** * chronocms version 1.0 * copyright (c) 2012 chronocms.com, rights reserved. * author: (chronocms.com team) * license: please read license.txt * visit http://www.chronocms.com regular updates , information. **/ namespace gcore\extensions\chronoforums\helpers; defined('_jexec') or die('restricted access'); defined("gcore_site") or die; class elements {     function footer($data = array()){         $topic = isset($data['topic']) ? $data['topic'] : null;         $subscribed = isset($data['subscribed']) ? $data['subscribed'] : null;          ?>         <div class="cfu-navbar">             <div class="cfu-inner">             <span class="cfu-corners-top"><span></span></span>             <ul class="cfu-linklist">                 <li class="cfu-icon-home"><a accesskey="h" href="<?php echo r_("index.php?option=com_chronoforums"); ?>"><?php echo l_('chronoforums_board_index'); ?></a></li>                  <?php if(\gcore\libs\authorize::authorized('\gcore\extensions\chronoforums\chronoforums', 'make_posts')): ?>                     <?php if(isset($subscribed)): ?>                         <?php if(!empty($subscribed['subscribed'])): ?>                         <li class="cfu-icon-unsubscribe"><a title="<?php echo l_('chronoforums_unsubscribe_topic'); ?>" href="<?php echo r_("index.php?option=com_chronoforums&cont=topics&act=unsubscribe&t=".$topic['topic']['id']); ?>"><?php echo l_('chronoforums_unsubscribe_topic'); ?></a></li>                         <?php else: ?>                         <li class="cfu-icon-subscribe"><a title="<?php echo l_('chronoforums_subscribe_topic_desc'); ?>" href="<?php echo r_("index.php?option=com_chronoforums&cont=topics&act=subscribe&t=".$topic['topic']['id']); ?>"><?php echo l_('chronoforums_subscribe_topic'); ?></a></li>                         <?php endif; ?>                     <?php endif; ?>                     <?php if(0): ?>                     <li class="cfu-icon-bookmark"><a title="bookmark topic" href="">bookmark topic</a></li>                     <?php endif; ?>                 <?php endif; ?>             </ul>             <span class="cfu-corners-bottom"><span></span></span></div>         </div>         <?php     }      function header($data = array()){         $forum = isset($data['forum']) ? $data['forum'] : null;         ?>         <div class="cfu-navbar">             <div class="cfu-inner">             <span class="cfu-corners-top"><span></span></span>             <ul class="cfu-linklist cfu-leftside">                 <li class="cfu-icon-home">                     <a accesskey="h" href="<?php echo r_("index.php?option=com_chronoforums"); ?>"><?php echo l_('chronoforums_board_index'); ?></a>                     <?php if(!empty($forum)): ?>                     <strong>‹</strong>                     <a href="<?php echo r_("index.php?option=com_chronoforums&cont=forums&f=".$forum['id']); ?>"><?php echo $forum['title']; ?></a>                     <?php endif; ?>                 </li>              </ul>              <div class="cfu-rightside">                 <form action="<?php echo r_('index.php?option=com_chronoforums&cont=search'); ?>" method="post" name="searchform">                 <fieldset>                     <input type="text" value="" size="20" id="cfu-search_keywords" name="skeywords" class="cfu-inputbox cfu-search cfu-tiny"/>                     <input type="submit" name="forums_search" value="<?php echo l_('chronoforums_search'); ?>" class="cfu-button2"/>                     <input type="hidden" name="f" value=""/>                 </fieldset>                 </form>             </div>              <span class="cfu-corners-bottom"><span></span></span></div>         </div> <?php  $user = jfactory::getuser(); $status = $user->guest; if($status == 1){ $url = "/forum/login"; echo "<a href=\"$url\">login/register</a>"; } else {  echo "<p>welcome: {$user->username}</p>"; }    ?>            <?php     } } 

as working in gcore\extensions\chronoforums\helpers , jfactory class in global space, need prefix such, eg

$user = \jfactory::getuser(); 

alternatively, add use statement @ top, eg

namespace gcore\extensions\chronoforums\helpers;  use \jfactory; 

see http://php.net/manual/language.namespaces.global.php


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -