Coder Social home page Coder Social logo

Comments (16)

overtrue avatar overtrue commented on July 1, 2024

请贴一下 WechatController.php:22 的代码。

from laravel-wechat.

snoywing avatar snoywing commented on July 1, 2024

$wechat = App::make('wechat');

from laravel-wechat.

overtrue avatar overtrue commented on July 1, 2024

贴一下整个控制器代码

from laravel-wechat.

snoywing avatar snoywing commented on July 1, 2024
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下了?

from laravel-wechat.

overtrue avatar overtrue commented on July 1, 2024
<?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,...
});

请参考:http://php.net/manual/zh/functions.anonymous.php

image

from laravel-wechat.

snoywing avatar snoywing commented on July 1, 2024

现在的问题是app::make的时候报错了。在controller下面那行,安安没遇到过这样的问题吗

from laravel-wechat.

overtrue avatar overtrue commented on July 1, 2024

@snoywing 没有,你先按我上面的写法纠正你的:

Message::make('news_item')->title('欢迎您,第'.$wechat->user->all($nextOpenId = null).'位关注者')->picUrl('http://www.baidu.com/images/1.jpg'), 

里的$wechat变量问题再试试看。

from laravel-wechat.

overtrue avatar overtrue commented on July 1, 2024

另外:

$wechat->user->all($nextOpenId = null)

返回的是数组,不是数字。。。

from laravel-wechat.

snoywing avatar snoywing commented on July 1, 2024

好的,收到

from laravel-wechat.

snoywing avatar snoywing commented on July 1, 2024

还是不行,问题是$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');

from laravel-wechat.

overtrue avatar overtrue commented on July 1, 2024

... 😞

命名空间的使用,不能命名空间需要引入:

use App;

然后才能

App::make

from laravel-wechat.

snoywing avatar snoywing commented on July 1, 2024

OK,结贴结贴,3q,安安

from laravel-wechat.

overtrue avatar overtrue commented on July 1, 2024

@snoywing 不报错了?

from laravel-wechat.

snoywing avatar snoywing commented on July 1, 2024

嗯,搞定了。 我以为在Illuminate 中加入以后这里就不用引用了呢。

from laravel-wechat.

snoywing avatar snoywing commented on July 1, 2024

谢谢安安啦

from laravel-wechat.

overtrue avatar overtrue commented on July 1, 2024

不客气,这些是PHP的语法问题,与框架无关,所以在任何地方用PHP命名空间都一样

from laravel-wechat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.