Laravel:如何在同一控制器中将变量从一个函数传递给来自Ajax调用的另一个函数

时间:2018-06-25 08:17:27

标签: php laravel

我是laravel的新手,面临将变量从一个函数传递给另一个函数的问题,我想将getidvalue变量从questionquiz5传递给previousbtn函数?这是我的代码

public  function questionquiz5(Request $request){
  static $startscore=0;
  static $getscore;
  static $level;
  $var = "hi";

  $getidvalue = Input::get('getid');
  $getanswervalue = Input::get('getanswer');



  $dbscore = \DB::table('5question')->select('question_id','correct_answer','question_marks','question_level')->where('question_id','=',$getidvalue)->get();

  //// some code...........


  Session::push('getscoresession',$getscore);
  Session::push('level',$level);


  $getsession = [  'qid' => $getidvalue,  'answer' => $getanswervalue];

  Session::push('answer', $getsession);

  return response()->json(['qid'=>$getidvalue,'answer'=>$getanswervalue]);   

  return $this->previousbtn( $getidvalue);
  return $this->previousbtn( $getanswervalue);
}     


**previousbtn function:**


public function previousbtn(Request $request, $getidvalue)
{
  $prevbtnvalue = Input::get('page');  
  $getcompid = $this->getidvalue;
  echo "$getcompid";     
}

错误:

  

获取错误:类型错误:函数App \ Http \ Controllers \ scorecontroller :: previousbtn()的参数太少,已传递1个且恰好期望2个

1 个答案:

答案 0 :(得分:0)

就像错误指示一样,您传递的太少药品。

(a) ?- [s,u,b,s,t,i,t,u,t,e]=[H1,H2|T].
My answer  is H1=[s] ,H2=[u,b,s,t,i,t,u,t], T=[e]
(b)?- [substitute]=[H1|T].
My answer is wrong it cant be done
(c) ?- [[substitute]]=[H1|T].
My answer is H1=[substitute] T=[]
(d)?- [[s,u,b,s],[t,i,t,u,t,e]=[H1|T].
My answer is H1=[s,u,b,s] and T=[t,i,t,u,t,e]
(e)?- [[s,u,b,s], t,i,t,u,t,e]=[H1|T].
My answer is wrong the tail has issues
(f) ?- [[s,u,b,s],[t,i,t,u,t,e]]=[H1,H2|T].
My answer is H1=[s,u,b,s] H2=[t,i,t,u,t,e] T=[]
(g) ?- [[s,u,b,s],[t,i,t,u,t,e]]=[[H1,H2],H3|T].
My answer is wrong
(e)?- f1(a,Y,,f(Z,2))=f1[a,[1,2],f(1,Y)).
first time i see something like this i don't know
(h)?- f2(A,B,C)=f2(a,[1,2,f(1,Y)]).
same as here

应该是

return $this->previousbtn( $getidvalue);

或者,如果return $this->previousbtn($request, $getidvalue); 方法中未使用请求对象,则可以将其从参数中删除。

相关问题