登录

php - 关于return的值,就是得不到··

<?php
echo 'Now in helloModel<br/>';

//molde层必须要做2步骤。第一是检测参数;第二是得到参数并显示
class helloModel{

public function run(){
    $checkRes=$this->checkParam();
    var_dump($checkRes);
    if($checkRes){
        $res=$this->getResult();
        print_r($res);
    }
}
public function name(){
    echo '<br />我是吕布!!';
}
public function checkParam(){
    $param=$_REQUEST;
    print_r($param);
    if($param['weapon'] == 1){
        echo '<br />你得到方天画戟!!<br />';
    } else {
        echo'you have nothing!!';
    }
}
public function getResult(){
    $res="<br />duang!能力提升成功!!";
    return $res;
}

}

以上是逻辑层,下面是actionc
<?php

class hello extends BaseAction{

public function action(){
    require_once DIR .'/model/IndexHello.php';
    $hero= new helloModel();
    $hero->name();

// $hero->checkParam();
// $hero->getResult();

    $Res=$hero->run();
}

}

输出结果如下

好奇为有weapon=1的值,但是显示是null··
新手小白表示,需要各位前辈指点一二,感谢。

# PHP
高洛峰高洛峰2153 天前597 次浏览

全部回复(4) 我要回复

  • ringa_lee

    ringa_lee2017-04-11 08:59:18

    public function checkParam(){
        $param=$_REQUEST;
        print_r($param);
        if($param['weapon'] == 1){
            echo '<br />你得到方天画戟!!<br />';
            return true;
        } else {
            echo'you have nothing!!';
            return false;
        }
    }

    回复
    0
  • ringa_lee

    ringa_lee2017-04-11 08:59:18

    我修改下答案,确实是checkParam 方法没有返回值。

    回复
    0
  • 巴扎黑

    巴扎黑2017-04-11 08:59:18

    你的checkParam都没返回值

    回复
    0
  • ringa_lee

    ringa_lee2017-04-11 08:59:18

    $checkRes=$this->checkParam();

    就错在这里,$checkRes你觉得你什么时候赋值了呢。

    回复
    0
  • 取消回复发送