Wednesday, April 1, 2009

Re: Add to result array in controller

Thanks for getting back to me, just getting to grips witth MVC, so i
wasn't sure adding logic in the view would be the best thing. Thanks
a lot

Ross

PS i will be using css classes, just a quickie function for demo

On Apr 1, 6:36 pm, Jimmy Bourassa <jboura...@gmail.com> wrote:
> Your color really should be a CSS class. Since you only need the color
> in your views, I'd put that bit of logic in a view, where it truly
> belongs.
>
> You could just extend your app view with your getStatusColour function
> and call this function in whatever kind of loop you'll use in your
> views.
>
> I hope it could help,
>
> Jimmy
>
> On 1 avr, 12:18, "Ross.Hagg...@googlemail.com"
>
> <Ross.Hagg...@googlemail.com> wrote:
> > Hi
>
> > I have a number of posts which can be one of 3 states, pending,
> > approved, declined.  I want to add some colour to my view when
> > displaying all the posts and i'm not sure how to do it.  I have an
> > $improvement array and a getStatusColor function in the
> > app_controller.  How can i read each item in the array, in my
> > controller and then add the status colour for the view?
>
> > Any help would be appreciated.
>
> > improvements_controller.php
>
> >         function index() {
> >                 $user_id = $this->Auth->user('id');
> >                 $conditions = array(
> >                         'conditions' => array('Improvement.user_id' =>
> > $user_id),
> >                         'fields' => array('Improvement.id',
> > 'Improvement.user_id',
> > 'Improvement.title', 'Improvement.description', 'Improvement.status',
> > 'Improvement.created')
> >                 );
> >                 $this->set('user_improvements', $this->Improvement->find('all',
>
> > $conditions));
> >         }
>
> > app_controller.php
>
> >         function getStatusColour($improvement){
> >                 switch ($improvement) {
> >                         case 'Pending':
> >                                 $improvement = 'yellow';
> >                                 break;
> >                         case 'Approved':
> >                                 $improvement = 'green';
> >                                 break;
> >                         case 'Declined':
> >                                 $improvement = 'red';
> >                                 break;
> >                 }
> >                 return $improvement;
> >         }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: