Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Member function view() #4

Open
BrookeDot opened this issue Dec 12, 2022 · 16 comments
Open

Uncaught Member function view() #4

BrookeDot opened this issue Dec 12, 2022 · 16 comments
Labels
question Further information is requested

Comments

@BrookeDot
Copy link

I am attempting to upgrade from Hybird Core 5.x to 6.0 and getting the following error with views:

Fatal error: Uncaught Error: Call to a member function view() on bool
in /Users/brooke/Local Sites/local/app/public/wp-content/themes/mythic/vendor/themehybrid/hybrid-view/src/functions-helpers.php on line 32

PHP 8.1
WordPress 6.1

I'm assuming the way a view is called is different for 6.0?

@ghost
Copy link

ghost commented Dec 13, 2022

hybrid-core version 6 is/has been broken down into separate components rather than a whole system. Personally 5.x works fine.. I don't think is necessary to move to 6..

@BrookeDot
Copy link
Author

BrookeDot commented Dec 13, 2022

hybrid-core version 6 is/has been broken down into separate components rather than a whole system.

Yep, I used Hybrid for a long time, (since 1.5 😬 ) this is my first time trying to use 6.0 here are the packages I have installed:

$ composer show
composer/installers                   v1.12.0 A multi-framework Composer library installer
themehybrid/hybrid-attr               1.0.0   Hybrid Attr provides devs a system for adding filterable attributes. This is sort of like `body_class()`, `post_class()`, and `comment_class()`...
themehybrid/hybrid-contracts          1.0.0   Contracts for the Hybrid Core framework.
themehybrid/hybrid-core               6.0.0   Hybrid Core: A framework for developing modern WordPress plugins and themes.
themehybrid/hybrid-template           1.0.0   Template helper functions.
themehybrid/hybrid-template-hierarchy 1.0.0   Smarter and more flexible template hierarchy for WordPress.
themehybrid/hybrid-template-manager   1.0.0   Custom template registration system for WordPress.
themehybrid/hybrid-theme              1.0.1   A collection of helper functions and filters to aid in theme development.
themehybrid/hybrid-tools              1.0.0   Helper tools and functions.
themehybrid/hybrid-view               1.0.0   System for setting up and rendering theme template files. Views are a bit like a suped-up version of the core WordPress get_template_part() fun...

Personally 5.x works fine.. I don't think is necessary to move to 6..

My main reason to moving is for PHP 8+ compatibility and because the module approach in theory means fewer files since I won't need breadcrumbs or get_the_image for my use case.

@ghost
Copy link

ghost commented Dec 13, 2022

so the view should be
$engine = \Hybrid\App::resolve( 'view/engine' );
$engine->display( 'header' );
$engine->display( 'footer' );

or you can use helper function below.
\Hybrid\View\display();

@BrookeDot
Copy link
Author

or you can use helper function below.
\Hybrid\View\display();

Yeah the theme is based on Mystic so is using:

// // Load header/* template.
\Hybrid\View\display( 'header', Hybrid\Template\hierarchy() );

// // Load content/* template.
\Hybrid\View\display( 'content', Hybrid\Template\hierarchy() );

// // Load footer/* template.
\Hybrid\View\display( 'footer', Hybrid\Template\hierarchy() );

@ghost
Copy link

ghost commented Dec 13, 2022

haha, I was about to mention Mystic just now, but looks like you found what you need!

@BrookeDot
Copy link
Author

The problem is when upgrading Mystic from Hybrid 5.x to 6.x there is the fatal error. I'm sure it's either a bug in this component, or I'm doing the upgrade wrong. So trying to figure out which it is.

@ghost
Copy link

ghost commented Dec 13, 2022

what does your bootstrap-app.php look like, did you add the view provider!
$slug->provider( 'Hybrid\View\Provider::class' );

@ghost
Copy link

ghost commented Dec 13, 2022

even if you have those components install through composer, you need to add those specific components as a provider. so soemthing like this below so it becomes available to use!

/**
 * Create a new framework instance
 *x
 * This will create an instance of the framework allowing you to initialize the theme.
 */
$initiator =  new \Hybrid\Core\Application();

/**
 * Register default providers.
 */
$initiator->provider( Hybrid\Template\Hierarchy\Provider::class );
$initiator->provider( Hybrid\Teplate\Manager\Provider::class );
$initiator->provider( Hybrid\View\Provider::class );

/**
 * Register custom providers for the theme.
 */
$initiator->provider( Initiator\Menu\Provider::class );
$initiator->provider( Initiator\Sidebar\Provider::class );

/**
 * Create an action hook for child themes.
 */
do_action( 'initiator/child/theme', $initiator );

/**
 * Boot the Framework
 */
$initiator->boot();

@ghost
Copy link

ghost commented Dec 13, 2022

the hierarchy provider works best with view together. then by adding a filter

add_filter( 'hybrid/template/path', function() {
  return 'public/views';
} );

without this filter, i think it defaults to resources/view

@ghost
Copy link

ghost commented Dec 16, 2022

did you ever get this resolved!

@justintadlock
Copy link
Member

You'll get that error when the Engine object is not being resolved. This sounds like a case of the view service provider not having been added as @benlumia007 said here: #4 (comment)

@justintadlock justintadlock added the question Further information is requested label Dec 16, 2022
@saas786
Copy link
Collaborator

saas786 commented Dec 19, 2022

@BrookeDot

If you could share your code, will be able to help you better.

But here are is the relevant bit of code you need in your theme...

/app/bootstrap-app.php

$mythic->register( \Hybrid\Template\Hierarchy\Provider::class );
$mythic->register( \Hybrid\Template\Manager\Provider::class );
$mythic->register( \Hybrid\Theme\Provider::class );
$mythic->register( \Hybrid\View\Provider::class );

/app/Providers/AppServiceProvider.php

use Hybrid\View\Contracts\Engine as EngineContract;
use Hybrid\View\Contracts\View as ViewContract;

and

		...
	public function register() {

		...
		// Create aliases for the view and engine.
		$this->app->alias( ViewContract::class, 'view' );
		$this->app->alias( EngineContract::class, 'view/engine' );

		...

/composer.json

...
    "require": {
...
        "themehybrid/hybrid-theme": "^1.0",
        "themehybrid/hybrid-template-manager": "^1.0",
        "themehybrid/hybrid-template-hierarchy": "^1.0",
        "themehybrid/hybrid-template": "^1.0",
        "themehybrid/hybrid-view": "^1.0",
...
    },
...   

@redactuk
Copy link

redactuk commented Dec 19, 2023

Did anyone get this to work?

@saas786 wote:
use Hybrid\View\Contracts\Engine as EngineContract; use Hybrid\View\Contracts\View as ViewContract;
that does not work for me, tells undefined namespace 'Contracts'

Anyone?

@saas786
Copy link
Collaborator

saas786 commented Dec 20, 2023

@redactuk
Is your code in a public repository? If so, please share the link so I can review it and provide you with accurate feedback.

@redactuk
Copy link

@redactuk Is your code in a public repository? If so, please share the link so I can review it and provide you with accurate feedback.

No it is not. What I have so far is here:
#9
based on your answer above, but clearly what you included above was for hybrid-view 1.x not the latest 2.x

@saas786
Copy link
Collaborator

saas786 commented Dec 20, 2023

If you want to continue using the legacy view system but with HC v7, refer to the following links:

You don't need the new hybrid-view v2 for that.

Similarly, if you want to use it with HC v6:

I can try to update both Mythic and Exhale to the latest code, but I think the current code should suffice for your needs.


Here is the latest implementation, and you can also see the prefixing logic applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants