I'm using routing with DRouter and I always need to get the data from such a store by slug , for that I need make 1 select
on all routes.
But I do not know how to get the id , name and slug from there SystemModel.php and there in index.php using the variable $dados
.
It says that the variable $dados
does not exist and that it is not an object.
index.php
$app = new DRouter\App();
$app->render->setViewsFolder(__DIR__.'/App/Views/');
require 'App/Controllers/SistemaController.php';
/* Login */
$app->get('/:slug/admin', function($slug){
SistemaController::dadosLoja($slug);
$this->render->load('lojista/loj_login.php', [
'id_loja' => $dados->id,
'nome_loja' => $dados->nome,
'slug_loja' => $dados->slug
]);
});
SystemController.php
require dirname(__FILE__) . '/../Models/SistemaModel.php';
class SistemaController
{
public static function dadosLoja($slug){
$dados = SistemaModel::slug($slug);
if($dados != false){
return $dados;
}
}
}
SystemModel.php
class SistemaModel
{
public static function slug($slug){
$dados = DB::conn()->prepare("SELECT * FROM 'admin_lojas' WHERE 'slug' = :slug");
$dados->bindValue(':slug', $slug, PDO::PARAM_STR);
$dados->execute();
if(count($dados) == 1){
return $dados;
}
}
}
DB.php
class DB
{
private static $conn;
public function __construct(){}
public static function conn(){
try {
if(is_null(self::$conn)){
self::$conn = new PDO('mysql:host='.HOST.';dbname='.BD.'',''.USER.'',''.PASS.'',
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
));
}
return (self::$conn) ? self::$conn : false;
} catch(PDOException $e) {
die("Error");
}
}
}