Dear all:
I would be grateful if you could help me on this issue what I have been
working on it few days:
my problem is: about passing multiple paramters from view (html helper:
link) to an action ($arg1 = null, $arg2 = null) that the passed parameter
became empty & null strings
1. First, the link in html is:
<?php echo
$this->Html->link($this->Andante->fetchLanguage('aside_addasfriend',
$opt_as), array('controller' => 'relationships', 'action' => 'addfriend',
'A_user_id' => $current_user['id'], 'B_user_id' =>
$user_data['User']['id']), array('class' => 'btn')); ?>
where the excepted values are: (for example)
'A_user_id' => $current_user['id'], 'B_user_id' => $user_data['User']['id']
$A_user_id = 1;
$B_user_id = 2;
2. And the action is like:
public function addfriend($A_user_id = null, $B_user_id = null) {
$A_user_id = $this->passedArgs['A_user_id'];
$B_user_id = $this->passedArgs['B_user_id'];
//check isset or not
if ($A_user_id = null || $B_user_id = null) {
$this->Session->setFlash('Invalid user id');
$this->redirect($this->referer());
} else {
//$A_user_id = intval($A_user_id);
//$B_user_id = intval($B_user_id);
//create entity in Table Relationships
if ($this->Relationship->save($data = array('A_user_id' => $A_user_id,
'B_user_id' => $B_user_id, 'relationship_created' => date("Y-m-d H:i:s"))))
{
$relationship_id = $this->Relationship->id;
//create entity in Table Relationshiplogs
if ($this->Relationshiplog->save($data = array('relationship_id' =>
$relationship_id, 'A_user_id' => $A_user_id, 'B_user_id' => $B_user_id,
'logtype' => 'A_addfriend', 'event_datetime' => date("Y-m-d H:i:s")))) {
//create entity in Table Notificationlogs
if($this->Notificationlog->save($data = array('user_id' => $B_user_id,
'type' => 'relationship', 'language_code' => 'relationship_addfriend',
'value1' => $A_user_id, 'value2' => $B_user_id, 'created' => date("Y-m-d
H:i:s")))) {
$this->redirect($this->referer());
} else {
$this->Session->setFlash('Could not send notification (step:3)');
$this->redirect($this->referer());
}
} else {
$this->Session->setFlash('Could not create log in table Relationshiplogs
(step:2)');
$this->redirect($this->referer());
}
} else {
$this->Session->setFlash('Could not save row in table Relationship
(step:1)');
$this->redirect($this->referer());
}
}
}
where the problem came out...
3. error
Database Error
Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column
'B_user_id' cannot be null
SQL Query: INSERT INTO `fortuneinn_renew`.`relationships` (`A_user_id`,
`B_user_id`, `relationship_created`) VALUES (*'', NULL*, '2012-08-08
08:43:31')
Notice: If you want to customize this error message, create
app\View\Errors\pdo_error.ctp
Stack Trace
CORE\Cake\Model\Datasource\DboSource.php line 461 →
PDOStatement->execute(array)
CORE\Cake\Model\Datasource\DboSource.php line 427 →
DboSource->_execute(string, array)
CORE\Cake\Model\Datasource\DboSource.php line 1009 →
DboSource->execute(string)
CORE\Cake\Model\Model.php line 1730 → DboSource->create(Relationship,
array, array)
APP\Controller\RelationshipsController.php line 30 → Model->save(array)
[internal function] → RelationshipsController->addfriend()
CORE\Cake\Controller\Controller.php line 485 →
ReflectionMethod->invokeArgs(RelationshipsController, array)
CORE\Cake\Routing\Dispatcher.php line 186 →
Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 161 →
Dispatcher->_invoke(RelationshipsController, CakeRequest, CakeResponse)
APP\webroot\index.php line 92 → Dispatcher->dispatch(CakeRequest,
CakeResponse)
The problem is that the passed parameter became empty & null strings... '',
null. I tried many ways (intval, isset...etc) but all in vain.
I googled many information about the format of passing multiple variables
but still don't get it.
Does anyone knows about the answer to my question? Thanks
Best Regards,
Andante Cheng
--
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.