wangqy010

wangqy010

这家伙有点懒,还没写个性签名!

  • 财富值10
  • 威望值0
  • 总积分20

个人信息

  • 赞了回答

    为什么不用yii\web\UploadedFile?

  • 赞了回答

    看着多了个空格。加上引号,或者把空格去掉,应该就可以了。

  • 2016-12-30 已签到
    连续签到1天,获得了5个金钱
  • 赞了评论

    <?php //控制器中
    namespace app\controllers;
    header('content-type:text/html;charset=utf8');
    use Yii;
    use app\models\Position;
    use yii\web\Controller;
    use yii\web\NotFoundHttpException;
    class PositionController extends Controller{

    ... ...其他代码... ...
    

    public function actionView($p_id){ //跳往修改页面

      //$id = Yii::$app->request->get('p_id');和括号里接值效果是一样的(因为前页是get传值)
    $arr=Position::find()->where(['p_id'=>$p_id])->with('company')->asArray()->one();
    return $this->render('view',$arr);//因为数据表Position字段和视图view.php文本框、单选框等等的标签名字完全一致,所以这里直接用了$arr,否则要用[’key’=>’value’]的形式。
    }
    public function actionUpdate(){    //执行修改
        $item=Yii::$app->request->post();  //接修改后的值
    	$query=new Position();
        $sign=$query->rewrite($item);    //封装好的方法
        if($sign==1){
            $this->redirect(['position/index']);
        }else{
            throw new NotFoundHttpException();
        }
    }
    

    }

    <?php //模型中
    namespace app\models;
    use yii\db\ActiveRecord;
    use Yii;
    use yii\data\Pagination;
    class Position extends ActiveRecord{
    ... ...其他代码... ...
    public function Rewrite($data){ //即使新值和旧值完全相同,依然可以提交并执行修改

    $res=Position::find()->where(['p_id'=>$data['p_id']])->one();
    $res->p_name=$data['p_name'];
    $res->p_time=time();
    $res->p_request=$data['p_request'][0];//数组需要处理成字符串
    $sign=$res->save();
    return $sign;
    

    }
    }

  • <?php //控制器中
    namespace app\controllers;
    header('content-type:text/html;charset=utf8');
    use Yii;
    use app\models\Position;
    use yii\web\Controller;
    use yii\web\NotFoundHttpException;
    class PositionController extends Controller{

    ... ...其他代码... ...
    

    public function actionView($p_id){ //跳往修改页面

      //$id = Yii::$app->request->get('p_id');和括号里接值效果是一样的(因为前页是get传值)
    $arr=Position::find()->where(['p_id'=>$p_id])->with('company')->asArray()->one();
    return $this->render('view',$arr);//因为数据表Position字段和视图view.php文本框、单选框等等的标签名字完全一致,所以这里直接用了$arr,否则要用[’key’=>’value’]的形式。
    }
    public function actionUpdate(){    //执行修改
        $item=Yii::$app->request->post();  //接修改后的值
    	$query=new Position();
        $sign=$query->rewrite($item);    //封装好的方法
        if($sign==1){
            $this->redirect(['position/index']);
        }else{
            throw new NotFoundHttpException();
        }
    }
    

    }

    <?php //模型中
    namespace app\models;
    use yii\db\ActiveRecord;
    use Yii;
    use yii\data\Pagination;
    class Position extends ActiveRecord{
    ... ...其他代码... ...
    public function Rewrite($data){ //即使新值和旧值完全相同,依然可以提交并执行修改

    $res=Position::find()->where(['p_id'=>$data['p_id']])->one();
    $res->p_name=$data['p_name'];
    $res->p_time=time();
    $res->p_request=$data['p_request'][0];//数组需要处理成字符串
    $sign=$res->save();
    return $sign;
    

    }
    }

  • 赞了回答

    1、把showAll方法增加static声明,然后可以用Cate::showAll()调用
    2、或者,先new,再用,既:

    $cate=new Cate();
    $cate->showAll();
    
试用期 等级规则
20/50
资料完整度
10/100
用户活跃度
0/100

Ta的关注

0

Ta的粉丝

1

Ta的访客

0