Author Topic: Help with php?  (Read 1055 times)

Jaded

  • The Codfather
  • Formerly known as Jaded
Help with php?
« on: 19 February, 2021, 06:39:46 pm »
I know very little about php, and I grabbed a bit of code to put into a CMS page (of an old version of Concrete5) and am getting an error. In looking where to go next, here is the code

Code: [Select]
<?php
   $area
= new Area('Main');
if (
$c->isEditMode()) {
    
$area->display($c); 
} else {
    
$blocks $page->getBlocks('Main');
    
shuffle($blocks);
    foreach (
$blocks as $b){$b->display();}
}
    
?>

and the error says

Fatal error: Call to a member function getBlocks() on null in ***/public_html/packages/theme_officespace/themes/officespace/left_sidebar.php on line 44

Line 44 is the one in the code after the } else { line

Main is the name of an area on the page and the blocks are chunks of content that are to be displayed on the page
The code is supposed to randomly order the blocks before they are displayed. I'm guessing shuffle does this
EditMode is when the page is signed out for edit.

It is simpler than it looks.

Re: Help with php?
« Reply #1 on: 19 February, 2021, 06:45:46 pm »
The error is because $page isn't set to anything (hence null).

But there's nothing there that tries to set $page. Perhaps it should be $c instead? Or perhaps it's set in some other part of the template?

Re: Help with php?
« Reply #2 on: 19 February, 2021, 06:51:27 pm »
As above $page needs something assigned to it, possibly a new instance of a PHP class containing the function getBlocks (which could also be a function encapsulated inside another function ).

Jaded

  • The Codfather
  • Formerly known as Jaded
Re: Help with php?
« Reply #3 on: 19 February, 2021, 07:07:52 pm »
The error is because $page isn't set to anything (hence null).

But there's nothing there that tries to set $page. Perhaps it should be $c instead? Or perhaps it's set in some other part of the template?

Brilliant - it should be $c

Thank you!!
It is simpler than it looks.

vorsprung

  • Opposites Attract
    • Audaxing
Re: Help with php?
« Reply #4 on: 20 February, 2021, 09:50:36 pm »
is it 1999 again?

Re: Help with php?
« Reply #5 on: 20 February, 2021, 10:57:20 pm »
is it 1999 again?
Are we not using this season’s fashionable programming language?

Jaded

  • The Codfather
  • Formerly known as Jaded
Re: Help with php?
« Reply #6 on: 20 February, 2021, 11:32:28 pm »
is it 1999 again?

Do you find yourself you wondering why you are partying?
It is simpler than it looks.

vorsprung

  • Opposites Attract
    • Audaxing
Re: Help with php?
« Reply #7 on: 21 February, 2021, 10:16:45 am »
is it 1999 again?
Are we not using this season’s fashionable programming language?

TBH I always hated PHP
First used it for real production stuff in 1999
Last time I was using it was 2014

It's great for mini one page websites with a database
Also, if you are doing your own Systems Admin it's easy to install (insecurely of course)
So, back in the day of the first Internet boom (2000-ish) it was very popular

It's ungreat for anything bigger or cleverer

React or Angular play better with more recent developments and IMHO scale better.
If you want a simple website now, then a static site with something like Gatsby or Hugo would be a better choice