I was doing some self-learning about cakephp (version 1.26).
I got a simple HTML input text field like this:
<input type="text" name="data[testing][name]" id="data[testing][name]">
The value from the Input text box field was checked against the database.
If the value matches the data stored in the database, it will return true.
Here is the code:
{
$t=$this->data;
$result=$this->User->findByname($t['testing']['name']);
if($result){ //doing something;}
}
I came across a question when I altered the code above with a little change,
but then it failed to work then:
{
$t=$this->data;
$result=$this->User->findByname($t['testing']['name']);
if($result===true){ //doing something;}
}
Could anyone help please?
You are using strict type comparison with === rather than ==, this implies that $result is actually not equal to true there by making the condition fail. Try to see what does come though in the $result variable:
var_dump($result);
Or try this condition with (==):
if($result == true){ //doing something;}
Or simply:
if ($this->User->findByname($t['testing']['name'])){ //doing something;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With