希望高手指點(diǎn)一二,·······我用的tp3.2.3的,誰能告訴我為啥不好使啊
<?php
//控制器中的代碼
namespace?Home\Controller;
use?Think\Controller;
use?Home\Model\IndexModel;???//這里試了好幾種情況都不行
class?IndexController?extends?Controller?{
????public?function?reponseMsg()(){
????????..........
????????if?(strtolower($postObj->MsgType=='text'?&&?trim($postObj->Content=='tuwen2'))){
????????????//實(shí)例化
????????????$index?=?new?IndexModel();???//這里也是
????????????$index->responseNews($postObj);
????}
}
//模型中的代碼
namespace?Home\Model;
//use?Think\Model;
class?IndexModel?extends?\Think\Model{
????public?function?responseNews($postObj){
????????.....與之前的視頻代碼相同,可以出現(xiàn)圖文消息
????}
????/*?public?function?responseText($postObj,$content){
????????//回復(fù)單文本
?????????
????}?*/
}
8 回答

震海聽風(fēng)
TA貢獻(xiàn)4條經(jīng)驗(yàn) 獲得超4個(gè)贊
還有兩點(diǎn)要注意:1、要建立mysql數(shù)據(jù)庫,隨便建一個(gè) ? ? ? 2、Controller控制器代碼中,new方法用D方法代替??刂破鞔a如下
<?php //控制器中的代碼 namespace?Home\Controller; use?Think\Controller; use?Home\Model\IndexModel;???//這里試了好幾種情況都不行 class?IndexController?extends?Controller?{ ????public?function?reponseMsg()(){ ????????.......... ????????if?(strtolower($postObj->MsgType=='text'?&&?trim($postObj->Content=='tuwen2'))){ ????????????//實(shí)例化 ????????????$index?=?D('Index');?//$index?=?new?IndexModel();???//這里也是 ????????????$index->responseNews($postObj); ????} }

震海聽風(fēng)
TA貢獻(xiàn)4條經(jīng)驗(yàn) 獲得超4個(gè)贊
兄弟,你上面的問題找出來了嗎。經(jīng)過不懈的困惑,我終于得到答案了。直接上代碼!
//模型中的代碼 namespace?Home\Model; //use?Think\Model; class?IndexModel?extends?\Think\Model{ ???//追加以下這一段,就行了,很神奇啊!也能寫進(jìn)數(shù)據(jù)庫 ????Protected?$autoCheckFields?=?false; ???public?function?__construct()?{ ????????????parent::__construct(); ????????????$this->$autoCheckFields; ????????} ???? ???? ????public?function?responseNews($postObj){ ????????.....與之前的視頻代碼相同,可以出現(xiàn)圖文消息 ????} ????/*?public?function?responseText($postObj,$content){ ????????//回復(fù)單文本 ?????????? ????}?*/ }
添加回答
舉報(bào)
0/150
提交
取消