DUDE!!! I Isaac, you are a life saver!!! Thank you so much for that link! You have no idea how long I poured over that issue yesterday!
Thank you very much for giving me the information to solve my problem! -Adam On Tue, Mar 16, 2010 at 1:02 PM, Isaac <[email protected]> wrote: > Hi Adam I found this link about HABTM relation in CakePHP, it might be > usefull: > > > http://mrphp.com.au/code/code-category/cakephp/cakephp-1-2/working-habtm-form-data-cakephp > > Regards > > > On Tue, Mar 16, 2010 at 11:04 AM, Adam Haymond <[email protected]> wrote: > >> I am working to build a job board with an admin side for adding jobs >> and categories, and a front end for browsing and searching. >> >> On the admin side I have a form for editing/creating jobs. >> >> Each job needs to be able to be assigned to multiple categories. I am >> assuming the best way to do this is through an HABTM association of >> the jobs and categories tables. So I have created the categories_jobs >> table and placed the HABTM associations along with joinTable >> properties in each of the jobs and categories models respectively. >> >> The following information is collected from the form: Title, >> Description, Location >> >> That information needs to be stored in the jobs table. >> >> Also, I have multiple checkboxes of categories on the form, these come >> from the categories table through the HABTM relation. >> >> When I try to save using $this->Job-save($this->data) I get an SQL >> error about saving an array. >> >> I need to be able to fill out the job data and then select multiple >> categories for the job to be associated with. >> >> >> Here is my action in the jobs_controller code: >> >> function edit($id=null) { >> $this->set('category', $this->Job->Category->find('list')); >> $data = $this->editOrCreate($id); >> if(!empty($this->data)) { >> $this->data['Category']['id'] = (array('category_id')); >> $this->User['User']['admin'] = 1; >> if($this->Job->saveAll($data)) { >> $this->Session->setFlash('The job has been saved'); >> $this- >> >redirect(array('action'=>'index',null,null,true)); >> } else { >> $this->Session->setFlash('The Job could not be saved. >> Please try again later.'); >> } >> } >> $categories = $this->Job->Category->find('list'); >> } >> >> >> and here is the view where the data is entered: >> >> <?php echo $form->create('Job');?> >> >> <div class="body"> >> >> <? if($editing): ?> >> <div class="floatRight"> >> <?php echo $html->link('Delete Job', >> array('action'=>'delete', >> $form->value('Job.id')), null, __('Are you sure you want to delete >> this job?', true).' '. $form->value('Job.name')); ?> >> </div> >> >> <h2>Edit Job - <?=$form->value('Job.name')?></h2> >> <?=$form->input('username',array('type'=>'hidden'));?> >> <? else: ?> >> <h2>Create New Job</h2> >> >> <? endif; ?> >> >> <?=$form->input('name', >> array('autocomplete'=>'off','label'=>'Title', >> 'style'=>'width: 175px;'));?> >> <?=$form->input('description', >> array('autocomplete'=>'off','label'=>'Description', 'style'=>'width: >> 175px;'));?> >> <?=$form->input('location', array('autocomplete'=>'off', >> 'label'=>'Location', 'style'=>'width: 175px;'));?> >> <?=$form->input('job_id', array('type'=>'hidden', >> 'value'=>'job_id'));?> >> <?=$form->input('category_id',array('options'=> >> $category,'multiple'=>'checkbox', 'label'=>'Categories'));?> >> >> </div> >> >> <?=$form->save('Job');?> >> >> <?php echo $form->end();?> >> >> >> Any help to overcome this problem would be GREATLY appreciated. I am >> pretty new at PHP and CakePHP, so if you could be verbose in your >> reply I would be grateful. >> >> _______________________________________________ >> >> UPHPU mailing list >> [email protected] >> http://uphpu.org/mailman/listinfo/uphpu >> IRC: #uphpu on irc.freenode.net >> > > _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
