Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Data Fields Don't Inherit From Hierarchy? #83

Closed
natefoundry opened this issue May 11, 2018 · 8 comments
Closed

Data Fields Don't Inherit From Hierarchy? #83

natefoundry opened this issue May 11, 2018 · 8 comments

Comments

@natefoundry
Copy link

I created a new page called Home (page-home.php) and set it as my Front Page. I'm attempting to use the ACF plugin to add fields to the home page and created a controller for it:

namespace App;

use Sober\Controller\Controller;

class PageHome extends Controller
{
    public function hero_video()
    {
        return get_field('hero_video');
    }
}

In my page-home.blade.php view:

  <div class="hero-background">
    <video autoplay muted loop playsinline>
      <source src="{{$hero_video}}" type="video/webm"/>
    </video>
  </div>

However, it doesn't seem to exist when I debug it:

Controller Debugger:
$site_name » string
$post » object
Hierarchy Debugger:
controllers/app.php
controllers/index.php
controllers/singular.php
controllers/page.php
controllers/page-14.php
controllers/page-home.php
controllers/front-page.php

If I move the hero_video() method to the controller for front-page.php it works:

<?php
namespace App;

use Sober\Controller\Controller;

class FrontPage extends Controller
{
  public function hero_video()
  {
      return get_field('hero_video');
  }
}

Debug output after change:

Controller Debugger:
$site_name » string
$post » object
$hero_video » string
Hierarchy Debugger:
controllers/app.php
controllers/index.php
controllers/singular.php
controllers/page.php
controllers/page-14.php
controllers/page-home.php
controllers/front-page.php

Is this the way inheritance for data fields is supposed to work? If not, what am I doing wrong?

@darrenjacoby
Copy link
Member

Hi @natefoundry, would you mind updating to 2.0.1 and then trying again? You will need to update namespaces (from App to App\Controllers), and rename folder controllers to Controllers/

@darrenjacoby
Copy link
Member

Here's a PR that shows the update process clearly

roots/sage#2025

@natefoundry
Copy link
Author

I updated my composer file to use ~2.0.1, then renamed the directory and namespace for each controller, but now I have this error:

Fatal error: Uncaught ReflectionException: Class App\Controllers\page-home does not exist in /Users/nathan.perrier/git_repos/h4h/homesforheroes/web/app/themes/h4h-theme/vendor/soberwp/controller/src/Loader.php:120 

Stack trace: #0 /Users/nathan.perrier/git_repos/h4h/homesforheroes/web/app/themes/h4h-theme/vendor/soberwp/controller/src/Loader.php(120): ReflectionClass->__construct('App\\Controllers...') 
#1 /Users/nathan.perrier/git_repos/h4h/homesforheroes/web/app/themes/h4h-theme/vendor/soberwp/controller/src/Loader.php(49): Sober\Controller\Loader->setClassesAlias() 
#2 /Users/nathan.perrier/git_repos/h4h/homesforheroes/web/app/themes/h4h-theme/vendor/soberwp/controller/controller.php(22): Sober\Controller\Loader->__construct(Object(Brain\Hierarchy\Hierarchy)) 
#3 /Users/nathan.perrier/git_repos/h4h/homesforheroes/web/wp/wp-includes/class-wp-hook.php(286): Sober\Controller\loader('') 
#4 /Users/nathan.perrier/git_repos/h4h/homesforheroes/web/wp/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) 
#5 /Users in /Users/nathan.perrier/git_repos/h4h/homesforheroes/web/app/themes/h4h-theme/vendor/soberwp/controller/src/Loader.php on line 120

@darrenjacoby
Copy link
Member

It needs to be PageHome.php to follow PSR4.

@natefoundry
Copy link
Author

That fixed it. Same for all the other controllers too (including app.php)?:

★  Controllers (master u=) $ ls -1
FrontPage.php
PageHome.php
App.php

@natefoundry
Copy link
Author

Well, all that did was update me from 9.0.0 beta to 2.0.1. I still don't see the data fields on my page-home blade template.

@darrenjacoby darrenjacoby reopened this May 14, 2018
@darrenjacoby
Copy link
Member

For the hierarchy, are you using class FrontPage extends Controller implements Tree, or using protected $tree = true; in FrontPage.php? You would need to do that to inherit from PageHome.php

@natefoundry
Copy link
Author

That did it. Thanks for the help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants