I'm using improvement['status'] e.g. Pending, Declined, Approved to display on screen for the user. I use the same value for the for a css class class="pending"
On Apr 2, 4:11 pm, Jimmy Bourassa <[email protected]> wrote: > Of course, it works. But that's not very MVC like in my opinion, the > color of the status only has to do with the way you'll view things, it > is in no way related to your data manipulations. > > You're also loading extra stuff in memory by adding that css class > value for every item of your find - not that it really matters but > still. > > On 2 avr, 10:06, rossjha <[email protected]> wrote: > > > Got what i'm looking for, afterFind function which is run via the > > model. > > > function afterFind($results){ > > foreach($results as $key => $val){ > > if(array_key_exists('Improvement', $val)){ > > > > $results[$key]['Improvement']['status'] = $this->getStatus > > ($results[$key]['Improvement']['status']); > > } > > } > > return $results; > > } > > > Works perfect and updates my array, will have great use for this, > > formatting my results. Going to use tinyint values in database now > > and give text for each status. I'll then use the status for css and > > field status. Still have a slight problem in that the array does not > > have index values so i'm receiving notices, but i will post a new > > message. > > > Ross > > > On Apr 1, 9:33 pm, rossjha <[email protected]> wrote: > > > > 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,JimmyBourassa<[email protected]> 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, "[email protected]" > > > > > <[email protected]> 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; > > > > > }- Masquer le texte des messages précédents - > > > - Afficher le texte des messages précédents - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
