Difficulty Creating a Simple Variable Parser for Altorouter

Asked

Viewed 35 times

2

I did a Simple Check of Variable PHP, but it was developed in Mysqli Base, the fact and that I went through some problems and due to this, I was forced to pass all the code to PDO, the problem and that I’m having Difficulties to replace data from Mysqli to PDO in my Code, It presents me error in the following lines: 25, 40, 50, 51, I tried to make the changes, however I did not succeed for the fact of minimum knowledge, the functionality of this Class and for Altorouter, if someone can help me. Below Has my Code!

Class Parser:

class Parser
{
    public $get;
    public $post;

    public function __construct()
    {
        $this->parse_get();
        $this->parse_post();
    }

    public function parse_get($data = false)
    {
        $get   = $_GET;
        $count = 0;
        if ($data) {
            $get = array_merge($get, $data);
        }
        foreach ($get as $key => $value) {
            $this->get->{$key} = $this->sanitize($value);
            $count++;
        }
        $this->get->__total = $count;
        return $this;
    }

    public function parse_post($data = false)
    {
        $post  = $_POST;
        $count = 0;
        if ($data) {
            $post = array_merge($post, $data);
        }
        foreach ($post as $key => $value) {
            $this->post->{$key} = $this->sanitize($value);
            $count++;
        }
        $this->post->__total = $count;
        return $this;
    }

    public function sanitize($value)
    {
        global $db;
        if (is_array($value)) {
            return $value;
        } else {
            if (!$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)) {
                $sanitized = addslashes($db->prepare($value));
                $sanitized->execute();
            } else {
                $sanitized = addslashes($value);
            }
            return $sanitized;
        }
    }
}

The Altorouter Code is as follows In Case You Can Help Me With A Solution Where I Can Eliminate the Class Parser It would be Very Welcome!

Altorouter:

require_once 'init.php';

use TOR\Data;
use TOR\Parser;
use TOR\Plugins\AltoRouter;

$glo = new Parser();
$router = new AltoRouter();
$router->setBasePath(Data::BasePath(ADMINPATH));

$router->addRoutes(array(
    array('GET', '/', __DIR__ . '/pages/dashboard.php', 'dashboard'),
));


$match = $router->match();

if ($match) {
    if (is_readable($match["target"])) {
        $glo->parse_get($match["params"]);
        $glo->parse_get(array("param" => $match["name"]));
        require_once $match["target"];
    } else {
        require_once 'pages/add.php';
    }
} else {
    require_once 'pages/add.php';
}
  • "it presents me error in the following lines: 25, 40, 50, 51" what errors? You can leave a comment on the lines in question to mark?

  • I was analyzing, to see if I could, the biggest problem is in Function Sanitize, where, because I’m trying to make the function where I developed in mysqli turn into PDO, but I’m not getting

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.