在config session.js中我启用了redis 在此之前我已经安装了这两件事......
npm install connect-redis
npm install express
adapter: 'redis',
//
// on localhost is expected.
// Read more about options at: https://github.com/visionmedia/connect-redis
//
host: 'localhost',
port: 6379,
ttl: 3600,
db: 0,
pass: '',
prefix: 'sess:'
在控制器2中
//在会话中分配值并重定向到controller1 req.session.error =“未找到类别”;
//错误 TypeError:无法设置未定义的属性“错误”
module.exports = {
load_word: function(req, res){
var async = require('async');
var express = require('express');
var RedisStore = require('connect-redis')(express);
async.waterfall([
function(callback){
Category.findOne().where({keyword:req.param('keyword')}).done(function(err,category){
if(category==undefined){
req.session.error = "category Not found";
res.redirect('home');
}else{
category_id = category.id;
}
/*Word.findOne().where({id:category_id}).done(function(err,word){
});*/
});
},
控制器1
的console.log(req.session.error);
module.exports = {
/**
* Action blueprints:
* `/home/index`
* `/home`
*/
index: function (req, res) {
var async = require('async');
var express = require('express');
var RedisStore = require('connect-redis')(express);
var data = new Object();
console.log(req.session.error);
如何解决这个问题?
答案 0 :(得分:0)
检查类别是否未定义或未使用
if(typeof(category)!='undefined){}