Page 1 of 1

replace $server and $get.

Posted: Sat Jul 25, 2015 1:45 pm
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;
  }
}
?>

Re: replace $server and $get.

Posted: Sat Jul 25, 2015 3:57 pm
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

Re: replace $server and $get.

Posted: Sat Jul 25, 2015 4:01 pm
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 

Re: replace $server and $get.

Posted: Sun Jul 26, 2015 12:37 pm
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

Re: replace $server and $get.

Posted: Sun Jul 26, 2015 12:44 pm
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?

Re: replace $server and $get.

Posted: Sun Jul 26, 2015 12:49 pm
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?

Re: replace $server and $get.

Posted: Sun Jul 26, 2015 1:09 pm
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

Re: replace $server and $get.

Posted: Sun Jul 26, 2015 1:12 pm
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.

Re: replace $server and $get.

Posted: Sun Jul 26, 2015 1:15 pm
by alex75
Complete paging file in the first post

Re: replace $server and $get.

Posted: Sun Jul 26, 2015 2:32 pm
by javiexin
Do you know any php?

Re: replace $server and $get.

Posted: Sun Jul 26, 2015 6:00 pm
by 3Di
@alex: have a look here, read the whole Topic ..

viewtopic.php?f=461&t=2270496&p=1378029 ... #p13780291