silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 719 forks source link

SessionServiceProvider not working correctly. #273

Closed Bieleke closed 12 years ago

Bieleke commented 12 years ago

$app->register(new Silex\Provider\SessionServiceProvider( array('name' => 'domain', 'lifetime' => 0, 'path' => '/', 'domain' => ".domain.com" )));

Seems not to do the trick, it still defaults to the server default name instead of taking the configged name.

And domain does not work anyway if the name is not used.

igorw commented 12 years ago

You do not set this by passing the options to the constructor. You must instead set the session.storage.options parameter, which you can do by passing an array of parameters as the second argument to app::register.

$app->register(new Silex\Provider\SessionServiceProvider(), array(
    'session.storage.options' => array('name' => 'domain', 'lifetime' => 0, 'path' => '/', 'domain' => '.domain.com'),
));
Bieleke commented 12 years ago

ah... that explains :-) i came up with this a day later...

$app->register(new Silex\Provider\SessionServiceProvider()); $app['session.storage.options'] = array('name' => 'domain', 'lifetime' => 0, 'path' => '/', 'domain' => '.domain.com');

So i think this is gonna fix my error for the forms not working too... as the session was never correct created.

However, which one of them is the wanted one ?

Same thing i did for the mysql-connection accepting utf-8 connections, as setting 'charset' => 'utf8' to my dbs.options did not worked, so somebody of the doctrine-chanel came up with something, which i have changed into...

// set the connection to utf-8, just setting charset in the dbs.options as a parameter for the connection does not work $app['db.event_manager']->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('utf8', 'utf8_general_ci'));

Is it me or are the docs of silex so unclear ?

db.options: Array of Doctrine DBAL options.

These options are available:
    driver: The database driver to use, defaults to pdo_mysql. Can be any of: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo_ibm, pdo_sqlsrv.
    dbname: The name of the database to connect to.
    host: The host of the database to connect to. Defaults to localhost.
    user: The user of the database to connect to. Defaults to root.
    password: The password of the database to connect to.
    path: Only relevant for pdo_sqlite, specifies the path to the SQLite database.

These and additional options are described in detail in the Doctrine DBAL configuration documentation.

Then the folowing from the doctrine documentation...

3.1.3.2. pdo_mysql

user (string): Username to use when connecting to the database.
password (string): Password to use when connecting to the database.
host (string): Hostname of the database to connect to.
port (integer): Port of the database to connect to.
dbname (string): Name of the database/schema to connect to.
unix_socket (string): Name of the socket used to connect to the database.
charset (string): The charset used when connecting to the database.

so that would mean... something like this....

$app->register(new Silex\Provider\DoctrineServiceProvider(), array( 'dbs.options' => array( 'serverOne_read' => array( 'driver' => 'pdo_mysql', 'host' => $Svr1Normal['Host'], 'dbname' => $Svr1Normal['Name'], 'user' => $Svr1Normal['User'], 'password' => $Svr1Normal['Password'], 'charset' => 'utf8', ), 'serverOne_write' => array( 'driver' => 'pdo_mysql', 'host' => $Svr1Admin['Host'], 'dbname' => $Svr1Admin['Name'], 'user' => $Svr1Admin['User'], 'password' => $Svr1Admin['Password'], 'charset' => 'utf8', ), ), 'db.dbal.class_path' => DIR.'/../vendor/doctrine-dbal/lib', 'db.common.class_path' => DIR.'/../vendor/doctrine-common/lib', ));

Should work right ? But it doesn't. Took me three days, to figure this out.

I am even banned from the silex irc channel because i thought a bot was answering my question and answered with nameofbot: shut up LOL, and the result was a ban, so i am completely shut-off of any help, why i am just trying to learn the system. On Symfony2 you mostely not have to ask, on doctrine they mostly have also no idea. I love symfony2 but the full stack framework is too heavy to directly migrate into, with silex you can do it step by step.

So is it possible to ask the mod of the silex irc channel to please unban me, it was just a joke man, i really thought that was a bot... not sure if you forgot to read the LOL but mostly that stands for Laughing Out Load, because beside of that the name of the person was that funny, turtle_hall_of_shame or something like that. And BAM they just banned me ???

The most stuff i have in meanwhile figured out myself, but it always come in handy to have the resource on irc, i can also tell me how it fixed my problem etc, just for feedback.

Anyway, thanks for your time.

Best Regards,

Patrick

stof commented 12 years ago

AFAIK, there is no IRC channel related to the Silex framework. The #silex channel was probably related to a totally different thing, which may explain why they banned you

Bieleke commented 12 years ago

Really ? LMAO :-) Ok, no problem then :-)