Here's my function to register a campaign. I guess I need to somehow
get the charity name from the form and with it find the charity id
that corresponds with that name and then insert it into $this-
>data['Campaign']['charity_id']. I'm not sure how to do that though :(
function regcampaign() {
$alias = 'regcampaign';
if ($this->Acl->check($this->Session->read('user.email'),
$alias,
'create')) {
if (!empty($this->data)) {
$this->Campaign->create();
//make the currently logged in users id be the
user_id foreign key
for this campaign
$this->data['Campaign']['user_id'] =
$this->Auth->user('id');
if ($this->Campaign->save($this->data)) {
$user =
$this->Session->read('user.email');
$name =
$this->Session->read('user.name');
$parent =
$this->Acl->Aco->findByAlias('Campaigns');
$alias = $name . '_' .
$this->Campaign->id;
$aco = new Aco();
$aco->create();
$aco->save(array('alias' => $alias,
'model' => 'Campaign',
'foreign_key' => $this->Campaign->id, 'parent_id' => $parent['Aco']
['id']));
$this->Acl->allow('users', $alias,
'read');
$this->Acl->allow($this->Session->read('user.email'), $alias);
$this->Session->setFlash(__('The
campaign has been saved',
true));
$this->redirect(array('controller' =>
'campaigns', 'action' =>
'view'));
} else {
$this->Session->setFlash(__('The
campaign could not be saved.
Please, try again.', true));
}
}
} else {
$this->Session->setFlash(__('You don\'t have permission
to register
a new campaign'));
}
$users = $this->Campaign->User->find('list');
$charities = $this->Campaign->Charity->find('list',
array('fields'
=> array('Charity.id', 'Charity.charity_name')));
$this->set(compact('users', 'charities'));
}
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php