attempt to read property on null in document.php line 250
/**
* #since 2.0.0
* #access public
*/
public function get_main_id() {
if ( ! $this->main_id ) {
$post_id = $this->post->ID;
I have the same error. In my case this ocurr after migration of site to other server with All-in-One WP Migration plugin.
The file with problem is: C:\xampp\apps\wordpress\htdocs\wp-content\plugins\elementor\core\base\document.php
Related
I have a rather large Symfony 4.4 project that I recently reopened. Going through the code with PhpStorm 2020.3, adding some new functionality and code cleanup.
I get to a couple of Controllers and I'm getting a "Missing Route" error in PhpStorm. However, the routes do exist when I run php bin/console debug:router.
Is there a cache that I haven't cleared to cause PhpStorm to rescan routes?
Output from: php bin/console debug:router
admin_deviceprofile_index GET ANY ANY /admin/deviceprofile/
admin_deviceprofile_show GET ANY ANY /admin/deviceprofile/{deviceprofile_id}/show
admin_deviceprofile_create GET|POST ANY ANY /admin/deviceprofile/create
admin_deviceprofile_edit GET|POST ANY ANY /admin/deviceprofile/{deviceprofile_id}/edit
admin_deviceprofile_delete DELETE ANY ANY /admin/deviceprofile/{deviceprofile_id}/delete
My snippet of the Controller ...
/**
* #Route("/admin/deviceprofile",
* name="admin_deviceprofile_")
*/
class DeviceProfileController extends AbstractController
{
/**
* Lists all Device Profiles.
* #Route("/",
* name="index",
* methods={"GET"})
* #param Request $request
* #return Response
*/
public function index(Request $request): Response
{ ... }
/**
* Creates a new Device Profile entity.
* #Route("/create",
* name="create",
* methods={"GET", "POST"})
* #param Request $request
* #return Response
*/
public function create(Request $request): Response
{
$profile = new DeviceProfile();
$formProfile = $this->createForm(DeviceProfileType::class, $profile);
$formProfile->handleRequest($request);
if ($formProfile->isSubmitted() && $formProfile->isValid()) {
...
return $this->redirectToRoute('admin_deviceprofile_index');
}
return $this->render(...);
}
}
PhpStorm claims the 'admin_deviceprofile_index' is Missing. However, it is not. Also, this same pattern of having a route for the controller is used elsewhere, yet those routes are fine, the problem appears in just a couple of Controllers.
Also, through debugging this 'problem', I moved the controller route partials to the functions themselves, and PhpStorm still did not see the routes properly.
I have also ran php bin/console cache:clear and have done the PhpStorm: File > Invalidate Caches / Restart to no avail.
Anything I could try to clear this up? I loathe seeing "errors" in the code inspection.
Figured out that if you have a PhpStorm #noinspection tag block and a class-level docblock, it will conflict causing the erroneous "Missing Route" message.
Github issue here
I just updated the jetpack wordpress plugin, and this error happened:
Fatal Error (E_ERROR): Call to undefined method Jetpack_Simple_Payments::is_enabled_jetpack_simple_payments() occurred in wp-content/plugins/jetpack/modules/widgets/simple-payments.php on line 480 please make sure that your website is accessible
Does any one has any approach about a solution? Thanks,
for the time being you can add the missing method is_enabled_jetpack_simple_payments in the file:
jetpack/modules/simple-payments/simple-payments.php
function is_enabled_jetpack_simple_payments() {
/**
* Can be used by plugin authors to disable the conflicting output of Simple Payments.
*
* #since 6.3.0
*
* #param bool True if Simple Payments should be disabled, false otherwise.
*/
if ( apply_filters( 'jetpack_disable_simple_payments', false ) ) {
return false;
}
// For WPCOM sites
if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'has_blog_sticker' ) ) {
$site_id = $this->get_blog_id();
return has_blog_sticker( 'premium-plan', $site_id ) || has_blog_sticker( 'business-plan', $site_id );
}
// For all Jetpack sites
return Jetpack::is_active() && Jetpack::active_plan_supports( 'simple-payments');
}
I'm new to Symfony. In Symfony 2.8.3 project I created mirgation file using
php app/console doctrine:migrations:generate
But when I put some code in up() and down() methods and try to run
php app/console doctrine:migrations:migrate
I get mistake:
Migration 20160314161511 failed during Pre-Checks. Error Notice: Undefined offset: 1
[Symfony\Component\Debug\Exception\ContextErrorException]
Notice: Undefined offset: 1
I tried to put different code by using "clear" SQL or via scheme, even left up/down methods with only //comments. But still no success.
DoctrineMigrationsBundle was installed and registered in AppKernel.php.
Here's the code of my aim mirgation:
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160314161511 extends AbstractMigration
{
/**
* #param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql(
"CREATE TABLE tblProductData (
intProductDataId int(10) unsigned NOT NULL AUTO_INCREMENT,
strProductName varchar(50) NOT NULL,
strProductDesc varchar(255) NOT NULL,
strProductCode varchar(10) NOT NULL,
dtmAdded datetime DEFAULT NULL,
dtmDiscontinued datetime DEFAULT NULL,
stmTimestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (intProductDataId),
UNIQUE KEY (strProductCode)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Stores product data'"
);
}
/**
* #param Schema $schema
*/
public function down(Schema $schema)
{
$this->addSql(
'DROP TABLE tblProductData'
);
}
}
Here is the doctrine_migrations section of my config.yml:
doctrine_migrations:
dir_name: "%kernel.root_dir%/DoctrineMigrations"
namespace: Application\Migrations
table_name: migration_versions
name: Application Migrations
doctrine section of config.yml I left with default value
When I use
php app/console doctrine:migrations:status
I get Available Migrations: 1 and New Migrations: 1
This is a known bug in zend-code library which is a dependency of DoctrineMigrations and this issue appears only on Windows. The temporary workaround is to go to vendors/zend-code/Generator/MethodGenerator.php#L96 and change:
protected static function clearBodyIndention($body) {
....
$lines = explode(PHP_EOL, $body);
....
$body = implode(PHP_EOL, $lines);
....
}
to:
protected static function clearBodyIndention($body) {
....
$lines = explode("\n", $body);
....
$body = implode("\n", $lines);
....
}
The developer of DoctrineMigrations is aware of this bug and you can find more info in this issue.
At this point there is a pull request to zend-code and hopefully this will be merged soon into the master which will then fix the problem.
I'm using just the framework without the CMS module for the first time. When I visit the app via a URL that is not handled by a controller/action, I just get a page with the text "No URL rule was matched". This results from Director::handleRequest() not matching any controllers to the url segments... Or "Action 'ABC' isn't available on class XYZController."
I'd like to direct any unmached requests to a controller equivalent of a nice 404 page. What is the correct or best way to do this?
The error templates are only included in the CMS. The framework just returns the HTTP response code with a message in plain text.
I've just started on my own framework-only project too and this is my solution:
[routes.yml]
---
Name: rootroutes
---
Director:
rules:
'': 'MyController'
'$URLSegment': 'MyController'
[MyController]
class MyController extends Controller {
private static $url_handlers = array(
'$URLSegment' => 'handleAction',
);
public function index() {
return $this->httpError(404, "Not Found");
}
/**
* Creates custom error pages. This will look for a template with the
* name ErrorPage_$code (ie ErrorPage_404) or fall back to "ErrorPage".
*
* #param $code int
* #param $message string
*
* #return SS_HTTPResponse
**/
public function httpError($code, $message = null) {
// Check for theme with related error code template.
if(SSViewer::hasTemplate("ErrorPage_" . $code)) {
$this->template = "ErrorPage_" . $code;
} else if(SSViewer::hasTemplate("ErrorPage")) {
$this->template = "ErrorPage";
}
if($this->template) {
$this->response->setBody($this->render(array(
"Code" => $code,
"Message" => $message,
)));
$message =& $this->response;
}
return parent::httpError($code, $message);
}
}
[ErrorPage.ss]
<h1>$Code</h1>
<p>$Message</p>
You can also create more specific error templates using ErrorPage_404.ss, ErrorPage_500.ss etc.
Without updating the routes as previously mentioned, there's a module that I've been recently working on which will allow regular expression redirection mappings, hooking into a page not found (404). This has been designed to function with or without CMS present :)
https://github.com/nglasl/silverstripe-misdirection
It basically makes use of a request filter to process the current request/response, appropriately directing you towards any mappings that may have been defined.
I've got Symfony 2 successfully installed and set up and have been following the documentation through.
I'm currently up to http://symfony.com/doc/2.0/book/doctrine.html
Everything is fine until I get to this line:
php app/console doctrine:generate:entities Acme/StoreBundle/Entity/Product
at which point I get the following error:
[RuntimeException]
The autoloader expected class "Acme\StoreBundle\Entity\Product" to be defined
in file "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Symf
ony\app/../src\Acme\StoreBundle\Entity\Product.php". The file was found but the
class was not in it, the class name or namespace probably has a typo.
This has happened to me on both Linux and Windows machines.
The contents of Product.php is as per the tutorial:
// src/Acme/StoreBundle/Entity/Product.php
namespace Acme\StoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="product")
*/
class Product
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(type="string", length=100)
*/
protected $name;
/**
* #ORM\Column(type="decimal", scale=2)
*/
protected $price;
/**
* #ORM\Column(type="text")
*/
protected $description;
}
That message comes from DebugUniversalClassLoader.php:
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
require $file;
if (!class_exists($class, false) && !interface_exists($class, false)) {
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
}
}
So, the file must be there, and readable, otherwise the findFile and the require wouldn't have worked. All this check is doing is require()ing the file and then using the standard PHP class_exists() to see if the class is now there.
The only thing I can think of that could cause this message given those file contents: you've missed off the <?php at the start of the file. Now, I know this is going out on a bit of a limb, but I honestly can't think of anything else that wouldn't cause some other kind of error.
I had the same error "The file was found but the class was not in it, the class name or namespace probably has a typo.". It's only because
<?php
is missing at the beginning of the file !! Argh, copy-paste from a tutorial...
Bye !