in the model or in the controller.
To put the code in the model, do not use find('all') but create your
own method in the model, for example find_all_model_a. Now in this
function, call $r = $this->find('all'), then iterate through the
result array $r using a foreach and add a field called "can_close"
that is true or false based on your criteria. From the controller you
call $ma = $this->MODEL_A->find_all_model_a(). Then $this->set('ma',
$ma); and ma contains everything you need in the controller with logic
in the model.
On Jan 6, 4:13 pm, Bottazzo <eduardo.botta...@gmail.com> wrote:
> I ll up this post just one more time.. thanks.
>
> On 4 jan, 16:18, Bottazzo <eduardo.botta...@gmail.com> wrote:
>
> > Yes Dave, this is what I do now. But, if the condition can_close() is
> > more than check if the status fields == 'OPEN' ? .. for ie: check
> > status field + check parent model status + check created date .. (and
> > in the future add more instructions in can_close() )... so... i
> > really need to call the can_close() method .. right?
>
> > Can you understand my problem now man? Do what u say it's solving my
> > problem now.. but in the future.. can cause some problem to me..
>
> > :)
>
> > Thanks for the reply Dave!
>
> > On Dec 31 2009, 3:55 am, "Dave" <make.cake.b...@gmail.com> wrote:
>
> > > 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 sitehttp://cakeqs.organdhelpothers
> > > 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+athttp://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
No comments:
Post a Comment