On Feb 13, 2011, at 16:50, adam_g2000 wrote:
> On Feb 14, 11:48 am, adam_g2000 wrote:
>> However I still have the problem with redirect. It doesn't seem to be
>> sending the variable, or my controller is not reading it. When I
>> reference the variable in the view, I get the error "Notice 8:
>> Undefined variable: categoryID [APP/views/subcategories/index.ctp,
>> line 44]" Here is my revised code:
> 
> In case the index controller is useful, here it is.
> 
> function index($categoryID = null) {
>               if (!empty($categoryID)) {
>                       App::import('Model','Category');
>                       $cat = new Category();
>                       $category = $cat->field('title', array('id' => 
> $categoryID));
>                       $this->set('category', $category);
>                       $this->set('categoryID', $categoryID);
>                       $conditions = array(
>                                               'conditions' => array(
>                                                       'Category.id' => 
> $categoryID),
>                                               'order' => 'Subcategory.order 
> ASC'
>                                               );
>                       $subcategories = $this->Subcategory->find('all', 
> $conditions);
>               } else {
>                       $this->set('category', 'All');
>                       $conditions = array(
>                                               'order' => array(
>                                                       'Category.title' => 
> 'ASC',
>                                                       'Subcategory.order' => 
> 'ASC'
>                                                       )
>                                               );
>                       $subcategories = $this->Subcategory->find('all', 
> $conditions);
>               }
>               $this->Subcategory->recursive = 0;
>               $this->set('subcategories', $subcategories);
>       }
> 

Well, I see a path through this code that would result in categoryID not being 
set in the view. Do you? When function index is called without a parameter 
(i.e. when you access a URL without the id), then $this->set('categoryID', 
$categoryID) is not called, hence categoryID is not set in the view, hence PHP 
tells you that.

If you're going to set up your controller's index method that way (where the 
categoryID is optional), then you need to code your index template to allow 
categoryID to be optional as well.


-- 
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