Pass parameters in cakephp function - php

$this->requestAction("/survey/responsethereuser/qid:$qid,uid:$uid,sid:$sid");
In my controller
function responsethereuser($qid = null, $uid=null, $sid=null)
It is showing on taking value of qid
$qid=1,uid:3,sid:1
How to get all the parameter values correctly?

try this
$this->requestAction("/survey/responsethereuser/", array('qid'=>$qid, 'uid'=>$uid, 'sid'=>$sid));

Related

How to get integer value of a string type data

I have a url goes like this:
https://sitename.com/nhd/my_student/nhd?olympiad=4
And by using \Request::getQueryString(), I get this string value:
olympiad=4
Now I need to get only the number 4 from this string.
How can I do that?
use request query method
request()->query('olympiad');
or
$request->query('olympiad');
Also query($key = null, $default = null) method accept default value as second param.
To get all query params use $request->query() so you get all query params in array.
Ref: https://laravel.com/docs/8.x/requests#retrieving-input-from-the-query-string

Php global and show values

I need show this value in global var global $f_[$id];
In function i have this string
$f_[$id];
$f_ it´s the string and value inside [] change and assign using the function and the finally values can show as this $f_[0] , $f_[34] , etc , the problem it´s i need something as this :
global $f_[$id];
And i know it´s incorrect writte but for understand me , because i need this value in a global var
I hope understand me , thank´s for the help
Regards
I believe that you can only do
global $f_;
As the [$id] is an element of a variable, I am not aware you can only global 1 element.
If you want to ONLY pass $f_[$id] you could pass it as a reference
function dothis($value)
{
$value = '';//something new
}
dothis(&$f_[$id]);
and that will only the address for that single element.

CakePHP - passing multiple values from a view element to the controller

I want to pass some values to my controller from the view.
Actually I'm using the following code:
<?
echo $this->element('produtos-categoria', array(
'categoria_id' => $produtos['Produto']['categoriasproduto_id'],
'produto_id' => $produtos['Produto']['id']
));
?>
But I'm not able to get the second value in my controller, just the first value is coming:
public function list_categories($categoria_id = null, $produto_id = null ) {
pr($produto_id); exit; //empty
}
Anyone can help how to get the second value?
I donno what are you trying to achieve but to get the second variable you would need to set the second parameter to your method.
// If you want to set variable from a function and get it from an other function
public function an_other_function(){
$this->listacategorias(22, 333);
}
public function listacategorias($categoria_id = null, $produto_id = null ) {
var_dump($categoria_id);
var_dump($produto_id);
}
// If you want to set and get variable from url
host_or_domain_name/controller_name/listacategorias/22/33

Joomla: Passing a variable into getInput()

I'm building a backend component (1.6 / 1.7 / 2.5) where I need to pass a variable from another view into a field in a new record. Variable passing is working fine.
My problem is using getInput().
To start with different doc pages have different amounts and formatting of parameters - confusing! For example:
http://docs.joomla.org/API16:JForm/getInput: getInput($name, $group= '_default', $formControl= '_default', $groupControl= '_default', $value=null)
vs
http://docs.joomla.org/JForm::getInput/1.6:
public function getInput (
$name
$group=null
$value=null
)
The problem:
I just need to pass a variable as a default value, something like:
echo $this->form->getInput('id', $value=$this->userID );?>
The above code makes the input field disappear. If I take out the $value=$this->userID the input field shows up though obviously doesn't have any default value. I've also tried:
$value=$this->userID;
echo $this->form->getInput('id', $value );
And same problem, the input field goes away. I tried a few other variations but basically if I try to put anything else within getInput() it doesn't work nor can I find any good working examples of how to use these other parameters.
What am I doing wrong?
Thanks!
According to the source, this is the correct API:
getInput($name, $group = null, $value = null)
And getInput() just calls getField():
getField($name, $group = null, $value = null)
Which means you should be doing this to set a default value:
echo $this->form->getInput('id', null, $this->userID ); // Returns the $field->input String
Or:
$field = $this->form->getField('id', null, $this->userID ); // Returns the JFormField object

CakePHP array() is empty, but query seems to be getting the correct results

I am trying to extract ONLY the PlanDetails where PlanDetail.company_id = Company.id AND PlanDetail.id' => $id.. ( you can see the conditions in my controller below)..
Controller:
function pd_list_by_company($id = null) {
$this->recursive = 2; // I am going to use containable to trim this.
return $this->PlanDetail->find('all',
array('conditions' =>
array('AND' =>
array('PlanDetail.company_id' => 'Company.id',
array('PlanDetail.id' => $id)))));
}
Test View:
$planDetailsByCompany = $this->requestAction('/planDetails/pd_list_by_company');
debug($planDetailsByCompany );
Output result of my debug??
Array()
If I remove the conditions and just have the find all, I get all PlanDetails as expected, so I know the data is being passed.. SQL debug dump even shows the query:
WHERE ((`PlanDetail`.`company_id` = 'Company.id') AND (`PlanDetail`.`id` IS NULL))
And yes, I did notice the $id is NULL, and I know the value needs to be there.. So maybe my question is why is the $id value not being passed to the controller even though I can see the PlanDetail.id value on a find('all') w/ out the conditions??
Thanks for any tips.
Since $id seems to be null, I would assume that you call the function without the parameter. And you don't get an error message, because as far as PHP is concerned the parameter is optional. In this case it's clearly required, so you should make it a required parameter in your function declaration:
function pd_list_by_company($id) {
Also you could simplify the return statement, you do not need the AND:
return $this->PlanDetail->find('all',
array('conditions' =>
array('PlanDetail.company_id' => 'Company.id','PlanDetail.id' => $id)
)
);
To answer the question why is the $id not being passed is because you're not passing it
To pass say $id of 2 you need to do the following in your requestAction
$this->requestAction('/planDetails/pd_list_by_company/2');
Seems to me that your code should just be
return $this->PlanDetail->find('array('PlanDetail.id' => $id));
Assuming you have the $this->PlanDetail->recursive flag set to > 0, your Model should already know about and return the associated data for any 'Company' table.....
I'm used to an old (1.3) version of CakePHP but the find() function is pretty basic and is designed to only return one row.
and yes, you definitely need to call the function with the id appended to the url, eg.
$planDetailsByCompany = $this->requestAction('/planDetails/pd_list_by_company/999');

Categories