You need use PDO because of the line above that you have in your class, or you can do \PDO::PARAM_STR, but this would mean doing it multiple places if you use a PDO constant anywhere else.
Not to sound like a newbee to Slim OOP (which i am) can you provide a sample or link to one ?
This is how i do it right now hope thats what you mean …
$app->get('/black', function (Request $request, Response $response, array $args) {
$ipAddress = $request->getAttribute('ip_address');
$blackObj = new Security\BlackList($this->db);
$Success = $blackObj->check_ip_blacklist($ipAddress);
if ($Success == 1)
{
echo "user on black list";
}
else {
echo "Your Ip ".$ipAddress." is not blacklisted";
}
});
And my class look like this now
namespace Security;
use pdo;
final class BlackList
{
public $db;
public function __construct($db) {
$this->db = $db;
}
public function check_token($ip)
{
$sth = $this->db->prepare('CALL `user_info`.`sp_ip_blacklist`(?)');
$sth->bindParam(1, $ip, PDO::PARAM_STR, 20);
$sth->execute();
$todos = $sth->fetchAll();
return $todos;
}
You are pretty much doing it by passing $this->db to your class. So it is clear that your class needs the db in order to function. There is a good overview of this here Dependency Injection Factories for Slim Controllers with some code examples.