Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank Session ID in Module's BeforAction #7310

Closed
mtangoo opened this issue Feb 16, 2015 · 6 comments
Closed

Blank Session ID in Module's BeforAction #7310

mtangoo opened this issue Feb 16, 2015 · 6 comments

Comments

@mtangoo
Copy link
Contributor

mtangoo commented Feb 16, 2015

I have something like below and I get empty session id unless I add session_start() before getting ID
Is this by design or a bug?

class Module extends \yii\base\Module 
{    
    public function beforeAction($action)
    {
        if (parent::beforeAction($action)) 
        {    
            //session_start(); I have to uncomment it for session to work
            $sid = Yii::$app->session->id
            return true;
        }
        else
            return false;
    } 
 } 
@qiangxue
Copy link
Member

You have to start the session first Yii::$app->session->open().

@mtangoo
Copy link
Contributor Author

mtangoo commented Feb 17, 2015

Why is that? is there any way to automate session open() like we do in database component?

@dynasource
Copy link
Member

starting a session goes at cost of performance

@qiangxue
Copy link
Member

When you try to access session data, the session will be started automatically. For this session ID access, it will not do so because it is possible you want to check session ID before it is started.

@mtangoo
Copy link
Contributor Author

mtangoo commented Feb 17, 2015

so where session get started in module for example? AfterAction?

@qiangxue
Copy link
Member

You can do it in module's init() method if you want to force starting session for every module request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants