replace $server and $get.

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
alex75
Registered User
Posts: 417
Joined: Sun Jun 10, 2012 9:09 am
Location: Italy
Name: Alessandro
Contact:

replace $server and $get.

Post by alex75 »

I wrote some time ago, a paging file that appeal to different custom pages. phpBB 3.1.x does not work because of these two variables no longer in use.
I was told to replace them with $request, but I have not figured out how. Can anyone help me replace them? Thanks.


this is the part of the file with the problem:

Code: Select all

<?php
// definiamo una costante per la pagina corrente
define("SELF", $_SERVER['PHP_SELF']);

// definiamo la classe
class Paging
{
  // definiamo la pagina di partenza
  function paginaIniziale($max_row)
  {
    if ((!isset($_GET['p'])) || ($_GET['p'] == "1"))
    {
      $parti_da = 0;
      $_GET['p'] = 1;
    }else{
      $parti_da = ($_GET['p']-1) * $max_row;
    }
    return $parti_da;
  }
This is my complete paging file:

Code: Select all

<?php
// definiamo una costante per la pagina corrente
define("SELF", $_SERVER['PHP_SELF']);

// definiamo la classe
class Paging
{
  // definiamo la pagina di partenza
  function paginaIniziale($max_row)
  {
    if ((!isset($_GET['p'])) || ($_GET['p'] == "1"))
    {
      $parti_da = 0;
      $_GET['p'] = 1;
    }else{
      $parti_da = ($_GET['p']-1) * $max_row;
    }
    return $parti_da;
  }

  // contiamo le pagine e stabiliamo quanti records devono essere impaginati 
  function contaPagine($conta, $max_row)
  {
    $pgg = (($conta % $max_row) == 0) ? $conta / $max_row : floor($conta / $max_row) + 1;
    return $pgg;
  }

  // mostriamo l'elenco delle pagine
  function listaPagine($p_corrente, $pgg)
  {
    $listapgg = "";
    if (($p_corrente != 1) && ($p_corrente))
    {
      $listapgg .= " <a href=\"".SELF."?p=1\">Prima pag.</a> ";
    }
    if (($p_corrente-1) > 0)
    {
      $listapgg .= "<a href=\"".SELF."?p=".($p_corrente-1)."\"><</a> ";
    }
    for ($i=1; $i<=$pgg; $i++)
    {
      if ($i == $p_corrente)
      {
        $listapgg .= "<b>".$i."</b>";
      }else{
        $listapgg .= "<a href=\"".SELF."?p=".$i."\">".$i."</a>";
      }
      $listapgg .= " ";
    }
    if (($p_corrente+1) <= $pgg)
    {
      $listapgg .= "<a href=\"".SELF."?p=".($p_corrente+1)."\">></a> ";
    }
    if (($p_corrente != $pgg) && ($pgg != 0))
    {
      $listapgg .= "<a href=\"".SELF."?p=".$pgg."\">Ultima pag.</a> ";
    }
    $listapgg .= "</td>\n";
    return $listapgg;
  }

  // permettiamo la navigazione per pagine precedenti e successive
  function precedenteSuccessiva($p_corrente, $pgg)
  {
    $impaginazione = "";
    if (($p_corrente-1) <= 0)
    {
      $impaginazione .= "Precedente";
    }else{
      $impaginazione .= "<a href=\"".SELF."?p=".($p_corrente-1)."\">Pag. precedente</a>";
    }
    $impaginazione .= " | ";
    if (($p_corrente+1) > $pgg)
    {
      $impaginazione .= "Prossima";
    }else{
      $impaginazione .= "<a href=\"".SELF."?p=".($p_corrente+1)."\">Prossima pag.</a>";
    }
    return $impaginazione;
  }
}
?>
User avatar
MuhClaren
Registered User
Posts: 126
Joined: Sat Feb 21, 2015 5:23 am

Re: replace $server and $get.

Post by MuhClaren »

In your extension you need to provide support for the request object. This is basically done by adding it to your arguments in your extension config file (the yaml one), declaring it as a class member in the class you're going to call it from, and add it as an argument in your constructor.

Once you have established access to the request object (service), you can use it in many different ways, for instance:

Code: Select all

$this->request->server('SERVER_VAR_HERE')
Also see: request_interface
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: replace $server and $get.

Post by javiexin »

Code: Select all

$parti_da = ($request->variable('p',1) - 1) * $max_row; // read it as integer, default value 1 

Code: Select all

$self = $request->server('PHP_SELF'); // not sure, but almost 
User avatar
alex75
Registered User
Posts: 417
Joined: Sun Jun 10, 2012 9:09 am
Location: Italy
Name: Alessandro
Contact:

Re: replace $server and $get.

Post by alex75 »

MuhClaren wrote:In your extension you need to provide support for the request object. This is basically done by adding it to your arguments in your extension config file (the yaml one), declaring it as a class member in the class you're going to call it from, and add it as an argument in your constructor.

Once you have established access to the request object (service), you can use it in many different ways, for instance:

Code: Select all

$this->request->server('SERVER_VAR_HERE')
Also see: request_interface
Thanks for your answer.
it is not an extension but a custom paging file
User avatar
alex75
Registered User
Posts: 417
Joined: Sun Jun 10, 2012 9:09 am
Location: Italy
Name: Alessandro
Contact:

Re: replace $server and $get.

Post by alex75 »

javiexin wrote:

Code: Select all

$parti_da = ($request->variable('p',1) - 1) * $max_row; // read it as integer, default value 1    

Code: Select all

$self = $request->server('PHP_SELF'); // not sure, but almost    
Thanks for your answer.
this works.

Code: Select all

$self = $request->server('PHP_SELF');

this keeps giving error.

Code: Select all

$parti_da = ($request->variable('p',1) - 1) * $max_row; // read it as integer, default value 1 
But perhaps, it is possible another simple solution ...
If I do I enable super_global solve the problem? how do I enable it?
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: replace $server and $get.

Post by javiexin »

alex75 wrote: this keeps giving error.

Code: Select all

$parti_da = ($request->variable('p',1) - 1) * $max_row; // read it as integer, default value 1 
What error?
User avatar
alex75
Registered User
Posts: 417
Joined: Sun Jun 10, 2012 9:09 am
Location: Italy
Name: Alessandro
Contact:

Re: replace $server and $get.

Post by alex75 »

javiexin wrote:
alex75 wrote: this keeps giving error.

Code: Select all

$parti_da = ($request->variable('p',1) - 1) * $max_row; // read it as integer, default value 1 
What error?
first error:

Code: Select all

Illegal use of $_SERVER. You must use the request class or request_var() to access input data. Found in C:\xampp\htdocs\vitarait\paginazione.php on line 3. This error message was generated by deactivated_super_global.
fixed by replacing line 3

Code: Select all

define("SELF", $_SERVER['PHP_SELF']);
with:

Code: Select all

$self = $request->server('PHP_SELF');
second error:

Code: Select all

Illegal use of $_GET. You must use the request class or request_var() to access input data. Found in C:\xampp\htdocs\vitarait\paginazione.php on line 14. This error message was generated by deactivated_super_global.
replacing line 14, gives me this error

Code: Select all

Fatal error: Call to a member function variable() on a non-object in C:\xampp\htdocs\vitarait\paginazione.php on line 14
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: replace $server and $get.

Post by javiexin »

alex75 wrote:
javiexin wrote:
alex75 wrote: this keeps giving error.

Code: Select all

$parti_da = ($request->variable('p',1) - 1) * $max_row; // read it as integer, default value 1 
What error?
first error:

Code: Select all

Illegal use of $_SERVER. You must use the request class or request_var() to access input data. Found in C:\xampp\htdocs\vitarait\paginazione.php on line 3. This error message was generated by deactivated_super_global.
fixed by replacing line 3

Code: Select all

define("SELF", $_SERVER['PHP_SELF']);
with:

Code: Select all

$self = $request->server('PHP_SELF');
second error:

Code: Select all

Illegal use of $_GET. You must use the request class or request_var() to access input data. Found in C:\xampp\htdocs\vitarait\paginazione.php on line 14. This error message was generated by deactivated_super_global.
replacing line 14, gives me this error

Code: Select all

Fatal error: Call to a member function variable() on a non-object in C:\xampp\htdocs\vitarait\paginazione.php on line 14
Would need to see all the code, but I will anticipate that you have NOT declared or imported $request in the second section of your code.
User avatar
alex75
Registered User
Posts: 417
Joined: Sun Jun 10, 2012 9:09 am
Location: Italy
Name: Alessandro
Contact:

Re: replace $server and $get.

Post by alex75 »

Complete paging file in the first post
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: replace $server and $get.

Post by javiexin »

Do you know any php?
User avatar
3Di
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: replace $server and $get.

Post by 3Di »

@alex: have a look here, read the whole Topic ..

viewtopic.php?f=461&t=2270496&p=1378029 ... #p13780291
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
Post Reply

Return to “Extension Writers Discussion”