Wednesday, December 30, 2009

RE: Conceptual problem Model on View ..

Not sure if I follow 100% but why not just grab the data where its OPEN?

$this->find('all', array('conditions' => array('MODEL_A.status' =>
'open')));

Or if you need to grab all the data then add the "close" link to OPEN cases
do the foreach
Controller: (or better yet make a function in the MODEL)
$this->set('cases', $this->find('all'));

VIEW:

Foreach ($cases as $case)
{
if ($case['Model']['status'] = 'open')
{

$case_status = "button code here";


} else {

$case_status = 'Case Closed';


}


Your looped data / html <?php echo $case_status; ?> so if its open it will
add the button,if not "Case Closed" will be there


}

Not 100% ure of the question but hope that helps. Maybe someone else has a
different idea.

Dave

-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Bottazzo
Sent: December-30-09 10:31 AM
To: CakePHP
Subject: Conceptual problem Model on View ..

Hi guys, im don't speak english but ill try to explain my problem for u. So,
sorry for my poor english.

Ok, let imagine that I have an Model named MODEL_A that have an status field
( OPENED and CLOSED )..
I have an method on MODEL_A named can_close() that return true if i can
close the element..

I want to show a list of MODEL_A elements in the page.. so in the controller
I call a MODEL_A->find(all).. ok.. get all instances...and $this->set to
view... nice!

Ok, now i have all my MODEL_A elements on VIEW... and I want to do
this: foreach element check .. if MODEL_A->can_close() == true...
show button CLOSE .. on the side of element name.. if can_close() == false..
hide it.


So... a ill need to import my model to the view.. to call can_close method..
right? but.. call model on view is the worst sin for MVC pattern ahn??

So.. what I do now friends?

Thank you for all..

Check out the new CakePHP Questions site http://cakeqs.org and help others
with their CakePHP related questions.

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
cake-php+at http://groups.google.com/group/cake-php?hl=en
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.722 / Virus Database: 270.14.122/2590 - Release Date: 12/30/09
03:57:00

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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: