Jump to content

Problem when calling Class


hansolobg
 Share

Recommended Posts

Hello I'm new to Processwire.

I'm starting to build a platform. I want to separate some of my logic into the site/src folder.

I added a simple tester class inside the site/src folder:

site/src/Helper.php
 

<?php namespace test;

/**
 * In this class all usefull helper functions are aggregated.
 */
class Helper
{
    

    public static function test()
    {
        return "hello";
    }
}

 

Then I want to use those functions e.g. in the template folder.

I use them as the following:

site/templates/home.php

<?php namespace ProcessWire;

use test\Helper;

$test = Helper::test();
?>

 

Now I get the following error:

 

Fatal Error: Uncaught Error: Class 'test\Helper' not found in /var/www/html/site/templates/home.php:5
Stack trace:
#0 /var/www/html/wire/core/TemplateFile.php(287): require()
#1 /var/www/html/wire/core/Wire.php(380): ProcessWire\TemplateFile->___render()
#2 /var/www/html/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___render', Array)
#3 /var/www/html/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array)
#4 /var/www/html/wire/modules/PageRender.module(514): ProcessWire\Wire->__call('render', Array)
#5 /var/www/html/wire/core/Wire.php(383): ProcessWire\PageRender->___renderPage(Object(ProcessWire\HookEvent))
#6 /var/www/html/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___renderPage', Array)
#7 /var/www/html/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\PageRender), 'renderPage', Array)
#8 /var/www/html/wire/core/WireHooks.php(822): ProcessWire\Wire->__call('renderPage', Array)
#9 /var/www/html/wire/core/Wire.p (line 5 of /var/www/html/site/templates/home.php) 

 

What am I doing wrong here?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...