Helper or Model Function?

View: New views
5 Messages — Rating Filter:   Alert me  

Helper or Model Function?

by dtirer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


So here's my scenario. On a particular page, I want to display a link.
However, I only want to display this link if a particular record
exists in the database.

Firstly, do helpers have access to DB/Model info?

If so, should I make a helper to check if the records exists in the
DB?

Whats the best way to do this?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Helper or Model Function?

by John Andersen-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Based on the information you provided (not enough):

One possible solution is to have a separate Element to create the
link, when the database contains the specific record.
The element will use requestAction to query the database for the
specific record, and display/not display the link depending on the
reply.

Turn on cache for the element, so that the requestAction is only used
once in each session.

Enjoy,
   John

On Nov 2, 5:40 pm, dtirer <dti...@...> wrote:

> So here's my scenario. On a particular page, I want to display a link.
> However, I only want to display this link if a particular record
> exists in the database.
>
> Firstly, do helpers have access to DB/Model info?
>
> If so, should I make a helper to check if the records exists in the
> DB?
>
> Whats the best way to do this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Helper or Model Function?

by dtirer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi John, thanks for the info.  I'll give that a whirl

A general question:  do helpers have access to Model data, or would
you need to import the Model into the helper to access data like
that?.

Im just getting into Helpers, Components, etc so I'm trying to figure
out when its best to use each

On Nov 2, 12:25 pm, John Andersen <j.andersen...@...> wrote:

> Based on the information you provided (not enough):
>
> One possible solution is to have a separate Element to create the
> link, when the database contains the specific record.
> The element will use requestAction to query the database for the
> specific record, and display/not display the link depending on the
> reply.
>
> Turn on cache for the element, so that the requestAction is only used
> once in each session.
>
> Enjoy,
>    John
>
> On Nov 2, 5:40 pm, dtirer <dti...@...> wrote:
>
> > So here's my scenario. On a particular page, I want to display a link.
> > However, I only want to display this link if a particular record
> > exists in the database.
>
> > Firstly, do helpers have access to DB/Model info?
>
> > If so, should I make a helper to check if the records exists in the
> > DB?
>
> > Whats the best way to do this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Helper or Model Function?

by John Andersen-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Helpers are used in Views and if you pass data from the Controller to
the View, then the Helper has access to the data.
The View has no direct access to Model data.

That is why I suggested using requestAction in an Element to get the
needed data.

Enjoy,
   John

On Nov 2, 7:50 pm, dtirer <dti...@...> wrote:

> Hi John, thanks for the info.  I'll give that a whirl
>
> A general question:  do helpers have access to Model data, or would
> you need to import the Model into the helper to access data like
> that?.
>
> Im just getting into Helpers, Components, etc so I'm trying to figure
> out when its best to use each
>
> On Nov 2, 12:25 pm, John Andersen <j.andersen...@...> wrote:
>
>
>
>
>
> > Based on the information you provided (not enough):
>
> > One possible solution is to have a separate Element to create the
> > link, when the database contains the specific record.
> > The element will use requestAction to query the database for the
> > specific record, and display/not display the link depending on the
> > reply.
>
> > Turn on cache for the element, so that the requestAction is only used
> > once in each session.
>
> > Enjoy,
> >    John
>
> > On Nov 2, 5:40 pm, dtirer <dti...@...> wrote:
>
> > > So here's my scenario. On a particular page, I want to display a link.
> > > However, I only want to display this link if a particular record
> > > exists in the database.
>
> > > Firstly, do helpers have access to DB/Model info?
>
> > > If so, should I make a helper to check if the records exists in the
> > > DB?
>
> > > Whats the best way to do this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Helper or Model Function?

by nurvzy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


If you have to load a model into your helper (not recommended) you can
use

ClassRegistry::init('ModelName')->find(...);

API: http://api.cakephp.org/class/class-registry#method-ClassRegistryinit

But I agree with John, use requestAction if you need to pull in data
from a view.  Here's a thought, is there a way to pass in the needed
flag record to your view?  In your controller action, maybe something
like:

$this->set('showLink', $this->Model->find(/*conditions for specific
record*/));

Then in your view you could just:
<? if($showLink):?> LINK <? endif; ?>

-Nick


On Nov 2, 10:50 am, dtirer <dti...@...> wrote:

> Hi John, thanks for the info.  I'll give that a whirl
>
> A general question:  do helpers have access to Model data, or would
> you need to import the Model into the helper to access data like
> that?.
>
> Im just getting into Helpers, Components, etc so I'm trying to figure
> out when its best to use each
>
> On Nov 2, 12:25 pm, John Andersen <j.andersen...@...> wrote:
>
> > Based on the information you provided (not enough):
>
> > One possible solution is to have a separate Element to create the
> > link, when the database contains the specific record.
> > The element will use requestAction to query the database for the
> > specific record, and display/not display the link depending on the
> > reply.
>
> > Turn on cache for the element, so that the requestAction is only used
> > once in each session.
>
> > Enjoy,
> >    John
>
> > On Nov 2, 5:40 pm, dtirer <dti...@...> wrote:
>
> > > So here's my scenario. On a particular page, I want to display a link.
> > > However, I only want to display this link if a particular record
> > > exists in the database.
>
> > > Firstly, do helpers have access to DB/Model info?
>
> > > If so, should I make a helper to check if the records exists in the
> > > DB?
>
> > > Whats the best way to do this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---