-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
请问为什么取不到$wechat呢 #2
Comments
请贴一下 |
$wechat = App::make('wechat'); |
贴一下整个控制器代码 |
items(function(){ return array( Message::make('news_item')->title('欢迎您,第'.$wechat->user->all($nextOpenId = null).'位关注者')->picUrl('http://www.baidu.com/images/1.jpg'), Message::make('news_item')->title('社保案例')->description('好不好?'), Message::make('news_item')->title('社保照片')->description('好不好说句话?')->url('http://baidu.com'), Message::make('news_item')->title('社保生活')->url('http://baidu.com/abc.php')->picUrl('http://www.baidu.com/demo.jpg'), Message::make('news_item')->title('社保代缴')->url('http://baidu.com/abc.php')->picUrl('http://www.baidu.com/demo.jpg'), ); }); }); return Wechat::serve(); } ``` } 请问安安,这样写对吗?这样的业务逻辑不就都在server这个function下了? |
<?php
$foo = 'bar';
$hello = 'world';
Wechat::on('event', 'subscribe', function($event){
// 这里是取不到变量$foo、$hello的
});
除非:
Wechat::on('event', 'subscribe', function($event) use ($foo, $hello, ... 其它你要在function内部用的变量){
//这里就可以使用use到的变量了,$foo,...
}); |
现在的问题是app::make的时候报错了。在controller下面那行,安安没遇到过这样的问题吗 |
@snoywing 没有,你先按我上面的写法纠正你的: Message::make('news_item')->title('欢迎您,第'.$wechat->user->all($nextOpenId = null).'位关注者')->picUrl('http://www.baidu.com/images/1.jpg'), 里的 |
另外: $wechat->user->all($nextOpenId = null) 返回的是数组,不是数字。。。 |
好的,收到 |
还是不行,问题是$wechat 获取不到。报[2015-04-19 04:30:38] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Http\Controllers\App' not found' in /var/www/wechat/app/Http/Controllers/WechatController.php:15 $wechat = App::make('wechat'); |
... 😞 命名空间的使用,不能命名空间需要引入:
然后才能 App::make |
OK,结贴结贴,3q,安安 |
@snoywing 不报错了? |
嗯,搞定了。 我以为在Illuminate 中加入以后这里就不用引用了呢。 |
谢谢安安啦 |
不客气,这些是PHP的语法问题,与框架无关,所以在任何地方用PHP命名空间都一样 |
$wechat = App::make('wechat');
$wechat->on('message', ...);
在laravel 5 中报错 :[2015-04-19 03:19:04] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Undefined class constant 'User'' in /var/www/wechat/app/Http/Controllers/WechatController.php:22
请问这是为什么呢?
The text was updated successfully, but these errors were encountered: