Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Meteor中将收集项目添加为路由_Meteor_Collections_Routes_Iron Router - Fatal编程技术网

在Meteor中将收集项目添加为路由

在Meteor中将收集项目添加为路由,meteor,collections,routes,iron-router,Meteor,Collections,Routes,Iron Router,我有一个meteor项目,我的所有用户都有自己的个人资料页面设置,使用路由: 路线代码: Router.route('/@:username', { name: 'profile', controller: 'ProfileController' }); ProfileController = RouteController.extend({ template: 'profile', waitOn: function() { return Meteor.subscrib

我有一个meteor项目,我的所有用户都有自己的个人资料页面设置,使用路由:

路线代码:

Router.route('/@:username', {
  name: 'profile',
  controller: 'ProfileController'
});

ProfileController = RouteController.extend({
  template: 'profile',
  waitOn: function() {
    return Meteor.subscribe('userProfile', this.params.username);
  },
  data: function() {
    var username = Router.current().params.username;
    return Meteor.users.findOne({
      username: username
    });
  }
});
服务器代码:

Meteor.publish('users', function() {
  return Meteor.users.find({}, {fields: {username: 1, emails: 1, profile: 1, roles: 1}});
});

Meteor.publish('userProfile', function(username) {
  // Try to find the user by username
  var user = Meteor.users.findOne({
    username: username
  });
  // If we can't find it, mark the subscription as ready and quit
  if (!user) {
    this.ready();
    return;
  }
  // If the user we want to display the profile is the currently logged in user
  if(this.userId === user._id) {
    // Then we return the curresonding full document via a cursor
    return Meteor.users.find(this.userId);
  } else {

    return Meteor.users.find(user._id, {
      fields: {
        profile: 0
      }
    });
  }
});
Meteor.publish('pages', function() {
  return Pages.find({});
});

Meteor.publish('Page', function(_id) {
  // Try find the page by _id
  var page = Meteor.pages.findOne({
    _id: _id
  });
  // If we can't find it, mark the subscription as ready and quit
  if (!page) {
    this.ready();
    return;
  }
  // If the page we want to display is not claimed, display it
  if(true) {
    return Meteor.pages.find(this._id);
  } else {
    // Redirect to the page
  }
});
我想对我设置的页面集合做一些类似的事情。创建收藏有效,收藏页面有一个创建时生成的
\u id
字段

目前,该程序对于mysite.com/@工作的用户来说运行良好。现在,我想为mysite.com做同样的事情/&

我基本上尝试过用用户名做与上面代码中完全相同的事情,但没有成功。我已检查以确保我创建的集合项正常工作,并且它们正常工作。但不知何故,我不知道如何对集合做同样的事情,因为我对使用路由相对较新

这就是我所尝试的:

以下是我的路线:

var pageRoute = '/&:_id';
Router.route(pageRoute, {
  name: 'page',
  controller: 'PageController'
});

PageController = RouteController.extend({
  template: 'page',
  waitOn: function() {
    return Meteor.subscribe('Page', this.params._id);
  },
  data: function() {
    var _id = Router.current().params._id;
    return Meteor.pages.findOne({
      _id: _id
    });
  }
});
服务器代码:

Meteor.publish('users', function() {
  return Meteor.users.find({}, {fields: {username: 1, emails: 1, profile: 1, roles: 1}});
});

Meteor.publish('userProfile', function(username) {
  // Try to find the user by username
  var user = Meteor.users.findOne({
    username: username
  });
  // If we can't find it, mark the subscription as ready and quit
  if (!user) {
    this.ready();
    return;
  }
  // If the user we want to display the profile is the currently logged in user
  if(this.userId === user._id) {
    // Then we return the curresonding full document via a cursor
    return Meteor.users.find(this.userId);
  } else {

    return Meteor.users.find(user._id, {
      fields: {
        profile: 0
      }
    });
  }
});
Meteor.publish('pages', function() {
  return Pages.find({});
});

Meteor.publish('Page', function(_id) {
  // Try find the page by _id
  var page = Meteor.pages.findOne({
    _id: _id
  });
  // If we can't find it, mark the subscription as ready and quit
  if (!page) {
    this.ready();
    return;
  }
  // If the page we want to display is not claimed, display it
  if(true) {
    return Meteor.pages.find(this._id);
  } else {
    // Redirect to the page
  }
});
页面集合的架构:

_id:, createdAt:, CreatedBy:, claimedAt:, 请求人:

更新:

我已经确定了问题的范围,在控制台服务器端出现以下错误:

I20160202-11:16:24.644(2)? Exception from sub qrPage id 2kY6RKCTuCpBDbuzm TypeError: Cannot call method 'findOne' of undefined
I20160202-11:16:24.645(2)?     at [object Object].process.env.MAIL_URL [as _handler] (server/ecclesia.life_server.js:40:33)
I20160202-11:16:24.645(2)?     at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20160202-11:16:24.645(2)?     at [object Object]._.extend._runHandler (livedata_server.js:1023:17)
I20160202-11:16:24.645(2)?     at [object Object]._.extend._startSubscription (livedata_server.js:842:9)
I20160202-11:16:24.646(2)?     at [object Object]._.extend.protocol_handlers.sub (livedata_server.js:614:12)  
I20160202-11:16:24.646(2)?     at livedata_server.js:548:43                                                   
每当我尝试基于此网站指向mysite.com/&

时,就会出现此错误:

看起来在URL字符串中使用#被认为是不安全的字符。在上面的网页上,似乎有几个符号可以用作安全字符

我只是在我自己的机器上试过这个,我认为当在URL中引入#时Meteor不会很好地发挥作用。

基于此网站:

看起来在URL字符串中使用#被认为是不安全的字符。在上面的网页上,似乎有几个符号可以用作安全字符

我只是在我自己的机器上试过这个,我认为当在URL中引入#时,Meteor不能很好地发挥作用。

这让它起作用了

出版物:

Meteor.publish('qrpages', function() {
  return QRPages.find({});
});

Meteor.publish('qrPage', function(id) {
  // Try find the qrpage by _id
  var qrpage = QRPages.find({_id: id});
  // If we can't find it, mark the subscription as ready and quit
  if (!qrpage) {
    this.ready();
    return;
  }
  return qrpage;
});
路线:

var qrpageRoute = '/$:_id';
Router.route(qrpageRoute, {
  name: 'qrpage',
  controller: 'QRController'
});

QRController = RouteController.extend({
  template: 'qrpage',
  waitOn: function() {
    var id = this.params._id;
    return Meteor.subscribe('qrPage', id);
  },
  data: function() {
    var id = this.params._id;
    return QRPages.findOne({
      _id: id
    });
  }
});
这让它起作用了

出版物:

Meteor.publish('qrpages', function() {
  return QRPages.find({});
});

Meteor.publish('qrPage', function(id) {
  // Try find the qrpage by _id
  var qrpage = QRPages.find({_id: id});
  // If we can't find it, mark the subscription as ready and quit
  if (!qrpage) {
    this.ready();
    return;
  }
  return qrpage;
});
路线:

var qrpageRoute = '/$:_id';
Router.route(qrpageRoute, {
  name: 'qrpage',
  controller: 'QRController'
});

QRController = RouteController.extend({
  template: 'qrpage',
  waitOn: function() {
    var id = this.params._id;
    return Meteor.subscribe('qrPage', id);
  },
  data: function() {
    var id = this.params._id;
    return QRPages.findOne({
      _id: id
    });
  }
});

这是一件非常有帮助的事情,虽然它并没有改变我的结果,但我已经尝试过了,发布了一个编辑。我现在用的是&而不是#。不过,&不是一个保留字符吗?尝试或$或u.@符号工作正常,与&…属于同一类别。。。同样在$1的同一类别中,这是一件非常有帮助的事情,虽然它没有改变我的结果,但是发布了我尝试过的内容的编辑。我现在用的是&而不是#。不过,&不是一个保留字符吗?尝试或$或u.@符号工作正常,与&…属于同一类别。。。另外,在与$I相同的类别中,我应该提到用户名的功能非常好,我正在尝试让用户生成的页面集合正常工作。#指定一个内部页面锚。进一步考虑这个问题-默认Meteor帐户电子邮件确认路径以#开始。Sam Hatoum在他的回答中写到了如何解决这个问题,我将它从a#改为&,这不再是问题所在,一定是出了什么问题……我添加了一个更新,以更加关注根本问题……我应该提到用户名的功能非常好,我正在尝试让用户生成的页面集合正常工作。#指定一个内部页面锚定。进一步考虑-默认Meteor帐户电子邮件确认路径以#开始。Sam Hatoum在对我的回答中写到了如何解决这一问题,我将其从a改为&,这不再是问题所在,肯定还有其他问题……我添加了一个更新,以更加关注根本问题。。。。