• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get data arguments

#1
Hi, today I tried to follow the manual, in order to get data from the form, and did not quite understand how to correctly pass the parameter.

In my controller:
PHP Code:
$model->setParam([
 
'firstParam' => $this->request->getVar('firstParam'),
 
'secondParam' => $this->request->getVar('secondParam')
]); 

When I send 2 arguments in my model:
PHP Code:
public function setParam($firstParam$secondParam) {
 return $this->table('test')->protect(false)->insert([
 
 'title' => $firstParam,
 
 'text'  => $secondParam
 
]);

Get "Too few arguments to function ParamModel:ConfusedetParam(), 1 passed in Controllers/Param.php on line 457 and exactly 2 expected".

When I send 1 argument in my model, get "operand should contain 1 column(s)"... 
PHP Code:
public function setParam($firstParam) {
 return $this->table('test')->protect(false)->insert([
 
 'title' => $firstParam,
 
 'text'  => '$secondParam'
 
]);


Looking inside print_r($firstParam); getting Array ( [firstParam] => 67545647f [secondParam] => 654547547554d )

Tell me please what I missed. Thanks.
Reply

#2
You are calling your model method incorrectly.
Your setParam method has two conflicting signatures - one with a single parameter and one with two. Neither of them expects an array, just values.
Your call to the method passes an array of parameters as the only parameter.
Read your error message!
Reply

#3
(06-08-2018, 08:48 AM)ciadmin Wrote: You are calling your model method incorrectly.
Your setParam method has two conflicting signatures - one with a single parameter and one with two. Neither of them expects an array, just values.
Your call to the method passes an array of parameters as the only parameter.
Read your error message!

I noticed this when browsing and if I take them like this:
PHP Code:
$model->setParam([
 
'firstParam' => $this->request->getVar('firstParam')],[
 
'secondParam' => $this->request->getVar('secondParam')
]); 
then they are transferred and not problem...

But I wanted to learn how to correctly pass multiple values in CI4, because I'm not experienced (

Thanks for the answer!
Reply

#4
There's nothing special about passing arguments to php functions/methods.

Read this:

PHP - Function arguments
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(06-09-2018, 09:08 AM)InsiteFX Wrote: There's nothing special about passing arguments to php functions/methods.

Read this:

PHP - Function arguments

Thanks! I watched the controller in @lonnieezell "simple-forums" how is the information from the input fields transmitted there, but did not pay attention to getting the arguments to the model...
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.