Roots Discourse

Quick question about adding new controllers and referencing them

A bit new to this but making some progress.

Do i need to reference Location.php somewhere? $location_types is an Undefined variable.
Can’t use Location:: in non static references.

    // Controllers/Location.php
    namespace App\Controllers;
    use Sober\Controller\Controller;

    class Location extends Controller
        public function locationTypes()
            global $post;
            $taxonomies = wp_get_post_terms($post->ID, 'location_type');          
            return $taxonomies;

        public static function LocationID()
            return "The ref ID"; // works

Blade files : single.php.blade > content-single-location.blade.php > entry-meta-location.blade.php

This works so some of controllers/Location.php is ‘available’

{!! Location::LocationID() !!}

cant get this from Class Location in Location.php but i can if added it to App.php




thanks in advance, D.

Rename Location.php to SingleLocation.php and class Location to class SingleLocation

1 Like

If you haven’t already, I’d recommend reading through the documentation for Controller: The first two points under Overview are particularly relevant to your issue. Controller matches on WordPress templates, which in Sage get mapped to blade files with particular names. It does not match to specific blade files. Sage 10 adds this functionality natively, but it isn’t present in Sage 9.

1 Like

I see - thanks for the reference. I’ll try out the above and read about the controllers.

This topic was automatically closed after 42 days. New replies are no longer allowed.