cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

DI::setParameter doesn't exists

Open iforp opened this issue 14 years ago • 3 comments

http://docs.phalconphp.com/en/0.7.0/reference/di.html Documentation telling I can use method \Phalcon\DI\FactoryDefault::setParameter, but it doesn't exists

var_dump(method_exists('\Phalcon\DI\FactoryDefault', 'setParameter')); 
// false

Also doesn't works

//Register a service "db" with a class name and its parameters
$di->set("db", array(
    "className" => "Phalcon\Db\Adapter\Pdo\Mysql",
    "parameters" => array(
          "parameter" => array(
               "host" => "localhost",
               "username" => "root",
               "password" => "secret",
               "dbname" => "blog"
          )
    )
));
// Warning: Phalcon\Db\Adapter\Pdo::__construct() expects exactly 1 parameter, 0 given

iforp avatar Nov 28 '12 18:11 iforp

Hi! You marked this issue as a bug. Does it means this is the docs bug, or setParameter is deprecated?

iforp avatar Nov 30 '12 16:11 iforp

Heya, this method must be there, but it looks it was removed by mistake :(

ghost avatar Nov 30 '12 17:11 ghost

This is now fixed, the correct syntax is:

<?php

$di->set('db', array(
    'className' => 'Phalcon\Db\Adapter\Pdo\Mysql',
    'arguments' => array(
        array(
            'type' => 'parameter', 
            'value' => array(
               "host" => "localhost",
               "username" => "root",
               "password" => "secret",
               "dbname" => "blog"
          )
        )
    )
));

ghost avatar Dec 29 '12 17:12 ghost