Hello!
I’m creating a custom plugin for HivePress, and everything is set up, but I’m encountering an error.
Controler:
<?php
/**
* Listing controller.
*
* @package HivePress\Controllers
*/
namespace HivePress\Controllers;
use HivePress\Helpers as hp;
use HivePress\Models;
use HivePress\Forms;
use HivePress\Blocks;
use HivePress\Emails;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Controller class.
*/
final class Controller_Zakladki extends Controller {
/**
* Class constructor.
*
* @param array $args Controller arguments.
*/
public function __construct( $args = [] ) {
$args = hp\merge_arrays(
[
'routes' => [
'listing_view_doswiadczenie' => [
'title' => esc_html__( 'doswiadczenie', 'doswiadczenie' ),
'base' => 'listing_view_page',
'path' => '/doswiadczenie',
//Tried Both
'redirect' => [$this, 'redirect_doswiadczenie_page'],
/* 'redirect' => [
[
'callback' => [ $this, 'redirect_doswiadczenie_page' ],
'_order' => 1,
],
],
'action' => [ $this, 'render_doswiadczenie_page' ],
'paginated' => true,*/
],
],
],
$args
);
parent::__construct( $args );
}
/**
* Redirects listing view page.
*
* @return mixed
*/
public function redirect_doswiadczenie_page() {
the_post();
$listing = Models\Listing::query()->get_by_id( get_post() );
$listing->get_images__id();
// Get vendor.
$vendor = $listing->get_vendor();
// Set request context.
hivepress()->request->set_context( 'listing', $listing );
hivepress()->request->set_context( 'vendor', $vendor );
return false;
}
/**
* Renders listing feed page.
*
* @return string
*/
public function render_doswiadczenie_page() {
return ( new Blocks\Template(
[
'template' => 'listing_view_doswiadczenie',
'context' => [
'listing' => hivepress()->request->get_context( 'listing' ),
'vendor' => hivepress()->request->get_context( 'vendor' ),
],
]
) )->render();
}
}
The file listing_view_doswiadczenie
is a duplicate of listing_view_page
with a few changes.
Unfortunately, when trying to access the listing_view_doswiadczenie
route, an error occurs:
PHP Fatal error: Uncaught Error: Call to a member function get_images_id()
on null in /home/tpmacxnjjm/domains/wyszukiwarka.legal/public_html/wp-content/plugins/hivepress_zakladki_listing/includes/controllers/class-controller-zakladki.php:63\nStack trace:\n#0
I feel like I might have overlooked something small. How can I fetch the current listing before redirect_doswiadczenie_page
is triggered?