This is IMHO a total mix up of terms. Yes, MVC preaches that view and
business logic shall be separated for all eternity. But what Craig was
saying is totally valid. You should be able to call methods on your
model. MVC says the business logic should be in the model. Exactly!

He only wants to CALL the methods from the view, which is perfectly
fine. This does not contradict MVC in any way. In Ruby on Rails you
can do this. The reason this doesn't work in Cake PHP is simply one of
it's shortcomings. The ActiveRecord pattern is not done
'correctly' (i.e. not all aspects are implemented). A row should
correspond to an object. ( http://en.wikipedia.org/wiki/Active_record_pattern
)

So Craig, yes you should be able to do this but its not possible in
cake PHP. Coming from the Java world you might want to check out Ruby
on Rails, to not make your head hurt so much when you come across
PHP's limited ability of OO.

On Jun 5, 2:32 pm, "Chris Hartjes" <[EMAIL PROTECTED]> wrote:
> This isn't Java... :)
>
> MVC supercedes typical OO practices because the goal is to separate
> business logic from display logic, right?
>
> On 6/5/07, Craig <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > thanks cook,
>
> > after find worked.... I find it interesting that it is discouraged to
> > access model form view.. I have been working in Java for many many
> > years (More than I want to remember a dinosaur like me goes back
> > before J2EE)..
>
> > In general OO methodology object behaviour should be programmed in the
> > object... NOt externally then stored in the model... either way after
> > find works Thanks Again.
>
> > Craig.
>
> > On Jun 5, 12:12 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > > Craig,
>
> > > Firstly, $event['event']->registerDate() will not work because
> > > $event['event'] is an array, not an object.
>
> > > Secondly, the MVC methodology used by the cakePHP developers
> > > discourages you from directly accessing the model from the view.
> > > Instead you should call canRegister and registerDate from the
> > > controller and then pass the information onto the view, or use a
> > > helper. Read the manul for more info about helpers.
>
> > > That said, many people are not satisfied with that degree of
> > > separation. There are several threads about this topic. Here is a
> > > recent
> > one:http://groups.google.com/group/cake-php/browse_thread/thread/57bca638...
> > > The entry by "Felix Geisendörfer" (IMHO) describes the best route for
> > > accessing model functions from the view. Do some searching and you
> > > will find many other related threads.
>
> > > For you particular case, I would recommend using the afterFind method
> > > in your model. That way the registration data will always be available
> > > to you.
> > > class Event extends AppModel{
> > >    ...
> > >    function afterFind($results) {
> > >        foreach ($results as $result) {
> > >           //add code here to add your registration data to the output
> > > array.
> > >        }
> > >        return $results;
> > >    }
> > >    ...
>
> > > }
>
> > > Look at the afterFind method in the manual (http://manual.cakephp.org/
> > > chapter/models) and in the api (http://api.cakephp.org/
> > > class_model.html#21de65cdbc08ce706a9413b4c73f28c5).
>
> > > Good luck,
> > > cook
>
> > > On Jun 4, 9:00 am, Craig <[EMAIL PROTECTED]> wrote:
>
> > > > Hi All,
>
> > > > I have searched and I can't find an answer anywhere so I ask the
> > > > question...
>
> > > > I would like to display and use derived values in a view....
>
> > > > The model knows how to calculate these values form it's own data.. but
> > > > how do I call these methods in a view..
>
> > > > For example I have a model called event I have defined 2 methods
> > > > canRegister and regsiterDate
>
> > > > Can register returns true if a user can register for the event and
> > > > registerDate returns the date that registrations open...
>
> > > > I would like the list (index.thtml) to display the regiser date if you
> > > > can't register and a link if you can...
>
> > > > however I can't see to call these methods from the view??
>
> > > > I tried echo $event['event']->registerDate()  but it didn't work...
> > > > I don't want to store the register date in the database as in the
> > > > event of a rule change I want to update the model and not have to
> > > > patch all the data for existing events.
> > > > an y help would be greatly appreciated.
>
> > > > Craig.
>
> --
> Chris Hartjes
>
> My motto for 2007:  "Just build it, damnit!"
>
> @TheBallpark -http://www.littlehart.net/attheballpark
> @TheKeyboard -http://www.littlehart.net/atthekeyboard


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to