Category and Subcategory and Resources are three different Models.

Category is (currently) one of five titles (with an associated
photograph).

Category hasMany subcategories, Subcategory belongsTo Category,
Resources hasAndBelongsToMany Subcategories.

To keep things simple for our user, they will be entering at the
Category level, clicking on the title which passes the ID of the
category then filters the next page, the Subcategories are only
displayed if they belong to the clicked on Category.

They also have the option, of seeing a complete, unfiltered list at
any stage (most useful in resources).

What I am trying to do (in every instance, but Edit is the one I
started with that I cannot get to work) is always show the user which
category (and eventually when looking at Subcategories which
subcategory) they are in and when they finish viewing or editing, are
returned to a filtered list.

To do this each method of the subcategory and category classes pass
around the ID of the current whatever, to enable the filtering… Or
that's the idea.

The code above is the edit method from Subcategory.

So in reply to:

Krissy - I'm using categoryID to grab the category title from the
Category model in the first part of the function. It works. Setting
the variable there allows me to see it in the edit view.

Cricket - as in my reply to Krissy, the bit of code I use to display
the category title using the categoryID is functional, yet also my
debugging code. Knowing that that is working, do you still think
routing could be the trouble?

Jeremy - thanks for your help before and thanks again now. Has this
made the issue clearer?

On Feb 14, 8:27 pm, Jeremy Burns | Class Outfit
<jeremybu...@classoutfit.com> wrote:
> I know you've already had a few replies, but can you outline in a simple 
> non-code sentence exactly what you are trying to achieve (rather than why 
> your code isn't working)?
>
> Jeremy Burns
> Class Outfit
>
> jeremybu...@classoutfit.com
> (t) +44 (0) 208 123 3822
> (m) +44 (0) 7973 481949
> Skype: jeremy_burnshttp://www.classoutfit.com
>
> On 14 Feb 2011, at 06:28, adam_g2000 wrote:
>
>
>
> > The edit method in my controller is successfully being passed a
> > variable called $categoryID. I'm using the variable to query another
> > model, which happens successfully and the title field from the model
> > is displayed in the view via the variable defined here.
>
> > App::import('Model','Category');
> > $cat = new Category();
> > $category = $cat->field('title', array('id' => $categoryID));
> > $this->set('category', $category);
>
> > My problem arises in the second if statement in the method. By the
> > time I need the variable to pass through redirect it seems to have
> > fallen out of scope and I cannot figure out why - the variable appears
> > to be empty.
>
> > Here is the method.
>
> >    function edit($id = null, $categoryID = null) {
> >            App::import('Model','Category');
> >            $cat = new Category();
> >            $category = $cat->field('title', array('id' => $categoryID));
> >            $this->set('category', $category);
> >            if (!$id && empty($this->data)) {
> >                    $this->Session->setFlash(__('Invalid subcategory', 
> > true));
> >                    $this->redirect(array('action' => 'index'));
> >            }
> >            if (!empty($this->data)) {
> >                    if ($this->Subcategory->save($this->data)) {
> >                            $this->Session->setFlash(__('The subcategory has 
> > been saved',
> > true));
> >                            $this->redirect(array(
> >                                    'controller' => 'subcategories',
> >                                    'action' => 'index',
> >                                    $categoryID
> >                            ));
> >                    } else {
> >                            $this->Session->setFlash(__('The subcategory 
> > could not be saved.
> > Please, try again.', true));
> >                    }
> >            }
> >            if (empty($this->data)) {
> >                    $this->data = $this->Subcategory->read(null, $id);
> >            }
> >            $categories = $this->Subcategory->Category->find('list');
> >            $resources = $this->Subcategory->Resource->find('list');
> >            $this->set(compact('categories', 'resources'));
> >    }
>
> > Please be gentle, I've spent a couple of months now reading the
> > cookbook and a textbook and a series of tutorials - though I am a
> > newbie! If anyone can offer any assistance and point out why this
> > might be I'd be very grateful. Thanks in advance.
>
> > Adam.
>
> > --
> > Our newest site for the community: CakePHP Video 
> > Tutorialshttp://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to