0

我在sfGuard使用 Symfony 应用程序获取令牌登录时遇到问题。Symfony 应用程序通过 WordPress 插件访问。WordPress 插件很简单,它iframe在 WP 控制面板中嵌入了带有令牌字符串的 a:

<iframe src="/app/index.php/api/authenticate/**token**" width="100%" height="100%">

这在实时服务器上运行良好。在挖掘了我的错误日志后,我发现了这个:

PDO Connection Error: SQLSTATE[28000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES), referer: http://****/wp-admin/admin.php?page=custom-sms.php 
PHP Fatal error: Call to a member function prepare() on a non-object in /var/www/vhosts/domain.com/sfapp/lib/vendor/symfony/lib/storage/sfPDOSessionStorage.class.php on line 162, referer: http://****/wp-admin/admin.php?page=custom-sms.php

奇怪的是,虽然我能够在网站前端写入/连接到数据库。什么可能导致应用程序不使用database.yml配置文件中设置的数据库用户名和密码?

app.yml文件:

all:
  security:
    #to auto-login to the SMS alert system from inside Wordpress admin
    token: **token**
    username: user@web.com

顺便说一句,我以前从未使用过 Symfony,而且我继承了这个网站,没有任何文档。

更新

database.yml文件:

# You can find more information about this file on the symfony website:
# http://www.symfony-project.org/reference/1_4/en/07-Databases

all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:host=localhost;dbname=db_name
      username: **username**
      password: **password**

第二次更新:

要添加,我手动将$env变量设置为在新服务器上prod进行测试。/web/index.php

factories.yml文件:

# You can find more information about this file on the symfony website:
# http://www.symfony-project.org/reference/1_4/en/05-Factories

prod:
  logger:
    class: sfAggregateLogger
    param:
      level: err
      loggers:
        sf_file_debug:
          class: sfFileLogger
          param:
            level: err
            file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log

staging:
  logger:
    class: sfAggregateLogger
    param:
      level: notice
      loggers:
        sf_file_debug:
          class: sfFileLogger
          param:
            level: notice
            file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log

test:
  storage:
    class: sfSessionTestStorage
    param:
      session_path: %SF_TEST_CACHE_DIR%/sessions

  response:
    class: sfWebResponse
    param:
      send_http_headers: false

  mailer:
    param:
      delivery_strategy: none

all:
  routing:
    class: sfPatternRouting
    param:
      generate_shortest_url:            true
      extra_parameters_as_query_string: true

  view_cache_manager:
    class: sfViewCacheManager
    param:
      cache_key_use_vary_headers: true
      cache_key_use_host_name:    true
4

1 回答 1

1

得到它的工作。所有的功劳都归于@j0k 的指针。

在新服务器上设置期间,我在会话存储中遇到了一些错误,因此我将存储类类型更改[app]/config/factories.ymlsfNoStorage. 恢复为sfPDOSessionStorage允许令牌登录工作。

all:
  storage:
    #http://www.designdisclosure.com/2009/11/symfony-doctrine-database-session-storage/
    class: sfPDOSessionStorage
    param:
      session_name: ugro
      database: doctrine
      db_table: session
      db_id_col: sess_id
      db_data_col: sess_data
      db_time_col: sess_time
于 2013-04-01T12:12:37.153 回答