Re: Components vs Helpers vs Utilities

2013-01-25 Thread Michael Gaiser
I am having difficulty thinking of a time when I would need the same
function to be called in my model and my view. On my current project, I am
also needing to manipulate my dates as I have a non standard way of saving
them in the database. What I have done is manipulated them in the
controller using a Component so these functions can used in different
controllers. I get the data from the model, use the functions in
my component to manipulate the data and then pass that to the view, which
displays it as is.

Is that similar to what you are trying or am I misunderstanding your goals?

~Michael

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Components vs Helpers vs Utilities

2013-01-25 Thread lowpass
On Fri, Jan 25, 2013 at 4:53 PM, tron tken...@gmail.com wrote:
 Im trying to wrap my head around utilzing some functionality at all levels
 of MVC. Right now, I'm writing a component that performs several date
 functions for my app (the date utility is insufficient for what Im doing).
 The problem is I need the these functions in both my models and views as
 well. I'd imagine writing my own Utility is the best option as it can be
 used anywhere but they seem off limits as they are only contained within
 the Lib. I also cant find any information on writing a Utility. Yes, I could
 just go write one and add it to Lib/Utilities but I'm looking for some
 feedback on this issue as I've faced it several times. If you need to share
 functionality between all layers of the MVC, is using utilities the only way
 to do it without having to load a component/helper/behavior on the fly?

If CakeTime doesn't have what you want you could extend it.

app/Lib/Utility/MyTime.php :

App::uses('CakeTime', 'Utility');

class MyTime extends CakeTime {

public function foo($bar = null) {

}
}

In your controller/Model/View :

App::uses('MyTime', 'Utility');

...

$foo = MyTime::foo($bar);

But if all you want/need is a plain function (ie. no class) you could
just put in bootstrap.php

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: components

2010-06-10 Thread emanuele
yes It is. But I dunno why the behaviour is different. In my app it's like
the override of components happens and
only the 'local' components it is available. What's do u think about?

thanks in advance.

On Thu, Jun 10, 2010 at 3:48 PM, John Andersen j.andersen...@gmail.comwrote:

 I am not sure what you asked for, but I will give it a try anyway :)

 If you define a component in the AppController, then the component
 will be available for all Controllers.
 If you define a component in a specific Controller, then the component
 will only be available in that Controller. The components defined in
 the AppController will also be available to the Controller.

 Was this what you were asking for?
 Enjoy,
   John


 On Jun 10, 4:39 pm, emanuele emanuel...@gmail.com wrote:
  Hello fellows,
  I want to share same components between controllers and I want some local
 to
  single controller.  If I re-define $components locally to the controller,
  cake performs the override or the array_merge of the global and local
  components variable?
 
  thanks in advance
 
  --
  Emanuele Gringeri
  Computer Engineer
  University of Pisa
  Be my mirror, my sword and shield

 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+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en




-- 
Emanuele Gringeri
Computer Engineer
University of Pisa
Be my mirror, my sword and shield

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: components

2010-06-10 Thread John Andersen
Please show the code on how you define the components in both the
AppController and in a Controller in which you have this issue!
Enjoy,
   John

On Jun 10, 4:55 pm, emanuele emanuel...@gmail.com wrote:
 yes It is. But I dunno why the behaviour is different. In my app it's like
 the override of components happens and
 only the 'local' components it is available. What's do u think about?

 thanks in advance.

[snip]

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: components

2010-06-10 Thread emanuele
thanks dude. it works. damn it.
On Thu, Jun 10, 2010 at 6:17 PM, euromark dereurom...@googlemail.comwrote:

 its

 var $components = array('Session');

 and everything works fine (cake1.3)


 On 10 Jun., 17:27, emanuele emanuel...@gmail.com wrote:
  For instance:
 
  class AppController extends Controller {
  var $components = array('Cookie', 'Email');
  ...
 
  }
 
  class DummiesController extends AppController {
  var $components = 'Session';
 
  function beforeFilter() {
   parent::beforeFilter();
 
  }
 
  
 
  }
 
  On Thu, Jun 10, 2010 at 5:22 PM, John Andersen j.andersen...@gmail.com
 wrote:
 
 
 
   Please show the code on how you define the components in both the
   AppController and in a Controller in which you have this issue!
   Enjoy,
 John
 
   On Jun 10, 4:55 pm, emanuele emanuel...@gmail.com wrote:
yes It is. But I dunno why the behaviour is different. In my app it's
   like
the override of components happens and
only the 'local' components it is available. What's do u think about?
 
thanks in advance.
 
   [snip]
 
   Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.com
 cake-php%2bunsubscr...@googlegroups.comcake-php%252bunsubscr...@googlegroups.comFor
 more options, visit this group at
  http://groups.google.com/group/cake-php?hl=en
 
  --
  Emanuele Gringeri
  Computer Engineer
  University of Pisa
  Be my mirror, my sword and shield

 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+unsubscr...@googlegroups.comcake-php%2bunsubscr...@googlegroups.comFor
  more options, visit this group at
 http://groups.google.com/group/cake-php?hl=en




-- 
Emanuele Gringeri
Computer Engineer
University of Pisa
Be my mirror, my sword and shield

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Components and Helpers route wrong

2008-09-06 Thread surf5502

All my routes just route my static pages to the Pages controller.
There is no issue with the Routing.admin (it is admin as it should be
to route my admin area).

Is there not some setting for the Router that decides to include or
not include the app folder name in the URL?

To clarify, /iny/ is my /app/ folder.


On Sep 4, 7:35 pm, Jaime [EMAIL PROTECTED] wrote:
 Try disabling all your routes in /config/routes.php. Also, check the
 value of 'Routing.admin' in /config/core.php.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Components and Helpers route wrong

2008-09-04 Thread Jaime

Try disabling all your routes in /config/routes.php. Also, check the
value of 'Routing.admin' in /config/core.php.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Components, how many is too many?

2008-04-29 Thread mixersoft

I just tried to create components that inherit from a common component
base class, and found that there were problems loading components --
especially when those components also use other components. It wasn't
that easy -- I'm not sure how you can load/declare components
dynamically in the var $controller attributes since that is static to
the class.

if I'm doing it wrong, I'd love to have someone point out a better
way. It there a reason why subclassing controllers works better than
subclassing components?

In my example above, my components are for importing photos from
Flickr/Facebook/etc, one each. And it always seems that most of the
code deals with either managing Sessions/Cookies/authentication keys
at those third party sites, or other state related issues like setting
variables for views, or testing for different form values before
sending the data to the model.



On Apr 27, 8:32 pm, djiize [EMAIL PROTECTED] wrote:
 and that's where MVC and OOP are very useful

 MVC because:
 I'm pretty sure some parts of your components can be turned in Model/
 Behavior/Datasource (gData, Flicker data access, ... are Model's
 logic)

 OOP because:
 why your ServicesController loads all components when it only needs
 some?
 Maybe you should separate in several controllers that inherit
 ServicesController (YahooServicesController,
 GoogleServicesController, ...)
 That way, each sub-ServicesController has its own $components list.

 Dont' forget that in CakePHP, there's still PHP ;-)

 On 27 avr, 10:31, Sam Sherlock [EMAIL PROTECTED] wrote:

  you have the option of importing them when you need and keeping generall
  required (heavily used comps in the controllers)

  *App::import*('*Component*'.$name)

  same goes for models etc

  at least thats as I understand.

  2008/4/27 mixersoft [EMAIL PROTECTED]:

   I am really wrestling with this one and wanted to know if others have
   established a best practice.

   My controllers are getting to be pretty big, and different actions may
   need different components. Also, in the name of DRY, I have a
   'services'  controller that performs a lot of standard utility
   functions -- which may need differnt components depending on who
   called it. (i.e. Flickr component for Flickr stuff, Facebook component
   for FB, Google component for Google, etc.)

   It really seems like Cake wants me to include all compoments in the
   controller var $compoments class attribute, so they can all be easily
   referenced as a class variable.  But I'm looking at my 'services'
   controller, and that could very well have a lot of very large
   components.

   I've tried to use App::import('Compoment', component) to load
   components on the fly, but when I do so I can't seem to access any
   components which those components need to use. (see post on Component
   Polymorphism).

   What do people do? Is the extra overhead so nominal that I should just
   include everything plus the kitchen sink? Is Cake smart enough only to
   actually load a component when it is actually required?  Has anyone
   else figured out how to properly load components on the fly?

   TIA.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Components, how many is too many?

2008-04-29 Thread djiize

You're right, it was a mistake to say ServicesController, etc...
I would say ServicesComponent, etc...

To load components in a component with $components member:
http://api.cakephp.org/1.2/class_component.html#1ffa81df593c314ae23143bb0834c8bc

To dynamically load components in a controller with
App::import('Component', 'YourComponent')
http://api.cakephp.org/1.2/class_app.html#2a84eb340fe947c7fdc753c3bf8cd053

On 29 avr, 14:49, mixersoft [EMAIL PROTECTED] wrote:
 I just tried to create components that inherit from a common component
 base class, and found that there were problems loading components --
 especially when those components also use other components. It wasn't
 that easy -- I'm not sure how you can load/declare components
 dynamically in the var $controller attributes since that is static to
 the class.

 if I'm doing it wrong, I'd love to have someone point out a better
 way. It there a reason why subclassing controllers works better than
 subclassing components?

 In my example above, my components are for importing photos from
 Flickr/Facebook/etc, one each. And it always seems that most of the
 code deals with either managing Sessions/Cookies/authentication keys
 at those third party sites, or other state related issues like setting
 variables for views, or testing for different form values before
 sending the data to the model.

 On Apr 27, 8:32 pm, djiize [EMAIL PROTECTED] wrote:

  and that's where MVC and OOP are very useful

  MVC because:
  I'm pretty sure some parts of your components can be turned in Model/
  Behavior/Datasource (gData, Flicker data access, ... are Model's
  logic)

  OOP because:
  why your ServicesController loads all components when it only needs
  some?
  Maybe you should separate in several controllers that inherit
  ServicesController (YahooServicesController,
  GoogleServicesController, ...)
  That way, each sub-ServicesController has its own $components list.

  Dont' forget that in CakePHP, there's still PHP ;-)

  On 27 avr, 10:31, Sam Sherlock [EMAIL PROTECTED] wrote:

   you have the option of importing them when you need and keeping generall
   required (heavily used comps in the controllers)

   *App::import*('*Component*'.$name)

   same goes for models etc

   at least thats as I understand.

   2008/4/27 mixersoft [EMAIL PROTECTED]:

I am really wrestling with this one and wanted to know if others have
established a best practice.

My controllers are getting to be pretty big, and different actions may
need different components. Also, in the name of DRY, I have a
'services'  controller that performs a lot of standard utility
functions -- which may need differnt components depending on who
called it. (i.e. Flickr component for Flickr stuff, Facebook component
for FB, Google component for Google, etc.)

It really seems like Cake wants me to include all compoments in the
controller var $compoments class attribute, so they can all be easily
referenced as a class variable.  But I'm looking at my 'services'
controller, and that could very well have a lot of very large
components.

I've tried to use App::import('Compoment', component) to load
components on the fly, but when I do so I can't seem to access any
components which those components need to use. (see post on Component
Polymorphism).

What do people do? Is the extra overhead so nominal that I should just
include everything plus the kitchen sink? Is Cake smart enough only to
actually load a component when it is actually required?  Has anyone
else figured out how to properly load components on the fly?

TIA.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Components, how many is too many?

2008-04-28 Thread [EMAIL PROTECTED]


On Apr 27, 1:32 pm, djiize [EMAIL PROTECTED] wrote:
 Dont' forget that in CakePHP, there's still PHP ;-)

That should be the next CakePHP t-shirt print!
I need to be reminded of this so often I should print this and stick
it to the top of my screen.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Components, how many is too many?

2008-04-27 Thread Sam Sherlock
you have the option of importing them when you need and keeping generall
required (heavily used comps in the controllers)

*App::import*('*Component*'.$name)

same goes for models etc

at least thats as I understand.

2008/4/27 mixersoft [EMAIL PROTECTED]:


 I am really wrestling with this one and wanted to know if others have
 established a best practice.

 My controllers are getting to be pretty big, and different actions may
 need different components. Also, in the name of DRY, I have a
 'services'  controller that performs a lot of standard utility
 functions -- which may need differnt components depending on who
 called it. (i.e. Flickr component for Flickr stuff, Facebook component
 for FB, Google component for Google, etc.)

 It really seems like Cake wants me to include all compoments in the
 controller var $compoments class attribute, so they can all be easily
 referenced as a class variable.  But I'm looking at my 'services'
 controller, and that could very well have a lot of very large
 components.

 I've tried to use App::import('Compoment', component) to load
 components on the fly, but when I do so I can't seem to access any
 components which those components need to use. (see post on Component
 Polymorphism).

 What do people do? Is the extra overhead so nominal that I should just
 include everything plus the kitchen sink? Is Cake smart enough only to
 actually load a component when it is actually required?  Has anyone
 else figured out how to properly load components on the fly?

 TIA.
 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Components, how many is too many?

2008-04-27 Thread djiize

and that's where MVC and OOP are very useful

MVC because:
I'm pretty sure some parts of your components can be turned in Model/
Behavior/Datasource (gData, Flicker data access, ... are Model's
logic)

OOP because:
why your ServicesController loads all components when it only needs
some?
Maybe you should separate in several controllers that inherit
ServicesController (YahooServicesController,
GoogleServicesController, ...)
That way, each sub-ServicesController has its own $components list.

Dont' forget that in CakePHP, there's still PHP ;-)

On 27 avr, 10:31, Sam Sherlock [EMAIL PROTECTED] wrote:
 you have the option of importing them when you need and keeping generall
 required (heavily used comps in the controllers)

 *App::import*('*Component*'.$name)

 same goes for models etc

 at least thats as I understand.

 2008/4/27 mixersoft [EMAIL PROTECTED]:



  I am really wrestling with this one and wanted to know if others have
  established a best practice.

  My controllers are getting to be pretty big, and different actions may
  need different components. Also, in the name of DRY, I have a
  'services'  controller that performs a lot of standard utility
  functions -- which may need differnt components depending on who
  called it. (i.e. Flickr component for Flickr stuff, Facebook component
  for FB, Google component for Google, etc.)

  It really seems like Cake wants me to include all compoments in the
  controller var $compoments class attribute, so they can all be easily
  referenced as a class variable.  But I'm looking at my 'services'
  controller, and that could very well have a lot of very large
  components.

  I've tried to use App::import('Compoment', component) to load
  components on the fly, but when I do so I can't seem to access any
  components which those components need to use. (see post on Component
  Polymorphism).

  What do people do? Is the extra overhead so nominal that I should just
  include everything plus the kitchen sink? Is Cake smart enough only to
  actually load a component when it is actually required?  Has anyone
  else figured out how to properly load components on the fly?

  TIA.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Components loading components

2008-01-12 Thread lordG

ok, i sourced the problem down to...

1) the subsomponent does get loaded.
2) the reference to subcomponents is miss calculated if a sub
component is a PluginName.ComponentName... It tries to make the object
$PluginName.ComponentName, but natuarally in the $loaded array it only
exists as $ComponentName, so the reference gets lost.

So, this is what lines 75 - 85 (component.php) did read
-
foreach (array_keys($loaded) as $component) {
$tempComponent = $loaded[$component];
if (isset($tempComponent-components)  is_array($tempComponent-
components)) {
foreach ($tempComponent-components as $subComponent) {
$this-controller-{$component}-{$subComponent} =
$loaded[$subComponent];
}
}
if (is_callable(array($tempComponent, 'initialize'))) {
$tempComponent-initialize($controller);
}
}

Which is now

foreach (array_keys($loaded) as $component) {
$tempComponent = $loaded[$component];
if (isset($tempComponent-components)  is_array($tempComponent-
components)) {
foreach ($tempComponent-components as $subComponent) {

//needs to split the component if its a Plugin
if (strpos($subComponent, '.') !== false) {
list($tempPlugin, $subComponent) = explode('.', 
$subComponent);
}

$this-controller-{$component}-{$subComponent} =
$loaded[$subComponent];
}
}
if (is_callable(array($tempComponent, 'initialize'))) {
$tempComponent-initialize($controller);
}
}


So this fixed the problem should I post a bug ticket?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components loading components

2008-01-12 Thread lordG

ps. i;m running latest 1.2 release.

On Jan 12, 4:08 pm, lordG [EMAIL PROTECTED] wrote:
 Hi guys,

 I have a problem happening with the with plugin components.

 I have a plugin called cms, which holds a component called
 iAuthenticate. This component in term requires another component
 called iLanguage. Both these components are located within the plugins
 components directory.

 Now if I call the component when running within the plugins scope of
 controllers, the authenticate component loads 100% with the language
 component too.

 However, if the authenticate component gets required outside of the
 plugin scope, like with a pages plugin, it loads the authenticate
 component, but does not find or load the language component.

 I am sure this has something to do with how cake is loading component
 components and the directory in which it defaults to.

 Any ideas?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components loading components

2008-01-12 Thread Robby Anderson


If its a verifiable, repeatable bug (and it actually is a bug, not
something by design), go for it. :)

On Jan 12, 8:43 am, lordG [EMAIL PROTECTED] wrote:
 ok, i sourced the problem down to...

 1) the subsomponent does get loaded.
 2) the reference to subcomponents is miss calculated if a sub
 component is a PluginName.ComponentName... It tries to make the object
 $PluginName.ComponentName, but natuarally in the $loaded array it only
 exists as $ComponentName, so the reference gets lost.

 So, this is what lines 75 - 85 (component.php) did read
 -
 foreach (array_keys($loaded) as $component) {
         $tempComponent = $loaded[$component];
         if (isset($tempComponent-components)  
 is_array($tempComponent-components)) {

                 foreach ($tempComponent-components as $subComponent) {
                         $this-controller-{$component}-{$subComponent} =
 $loaded[$subComponent];
                 }
         }
         if (is_callable(array($tempComponent, 'initialize'))) {
                 $tempComponent-initialize($controller);
         }}

 
 Which is now
 
 foreach (array_keys($loaded) as $component) {
         $tempComponent = $loaded[$component];
         if (isset($tempComponent-components)  
 is_array($tempComponent-components)) {

                 foreach ($tempComponent-components as $subComponent) {

                         //needs to split the component if its a Plugin
                         if (strpos($subComponent, '.') !== false) {
                                 list($tempPlugin, $subComponent) = 
 explode('.', $subComponent);
                         }

                         $this-controller-{$component}-{$subComponent} =
 $loaded[$subComponent];
                 }
         }
         if (is_callable(array($tempComponent, 'initialize'))) {
                 $tempComponent-initialize($controller);
         }}

 

 So this fixed the problem should I post a bug ticket?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components array used opposed to extends?

2007-11-04 Thread Richard

Thank you.

On Nov 2, 3:10 pm, AD7six [EMAIL PROTECTED] wrote:
 On Nov 1, 2:46 pm, Richard [EMAIL PROTECTED] wrote:

  Hi,

  I have several component classes that need to extend a parent class.
  Which is the correct approach:

  class Availability extends Object
  {
  var $components = array('Parent');

  OR:

  class Availability extends Parent
  {

  Thanks in advance.

 It's up to you, depending on whether you want to use the functionality
 of the component named Parent or inherit it with some modifications.
 ensure that the Parent component is loaded if you do the latter.

 hth,

 AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components array used opposed to extends?

2007-11-02 Thread AD7six



On Nov 1, 2:46 pm, Richard [EMAIL PROTECTED] wrote:
 Hi,

 I have several component classes that need to extend a parent class.
 Which is the correct approach:

 class Availability extends Object
 {
 var $components = array('Parent');

 OR:

 class Availability extends Parent
 {

 Thanks in advance.

It's up to you, depending on whether you want to use the functionality
of the component named Parent or inherit it with some modifications.
ensure that the Parent component is loaded if you do the latter.

hth,

AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components, Controllers y Elements

2007-10-21 Thread laeffe

Hi, first of I think it's correct to talk about models since models
are an abstraction for the tables.

Second i think you can use loadModel() to get access to a model that's
not in the uses variabel, but you will have to instantiate the object
your self, $model = new Model();

Ps.
Can anyone plz comment me on this if it's wrong?

On Oct 19, 7:07 pm, Pinholecam [EMAIL PROTECTED] wrote:
 I've been looking for some answers to my problems but after a couple
 of hours of searching, I'll answer that.

 a)   I would need to query differents models form a component. How to
 do it?

 b)   Looking at the manual it seems that each model has one controller
 and one controller has one model. In addition, if I have some kind of
 assosiation between models, for one controller it's possible to query
 the other models associated. But if I don't have any association? How
 can I query other models? (When I talk about models, maybe I should
 talk about tables). I assume that it's possible to query directly by
 $this-Mymodel-query(), but I would use Cake DB functions.

 c)   Elements: this are pieces of code(view) that repeat in a part of
 your site, so in order to not to repeat it. I've also seen that it's
 not possible to query from elements directly to the database, but you
 get information from the function set of your controller. If the query
 and its bussiness logic is more than one line, you're also duplicating
 code, so the answer is: can you type a function from a component that
 sets the information to the view? So to set the information, just call
 the component's funtion from a controller/action.

 Thanks to all the help u can give me.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components, Controllers y Elements

2007-10-20 Thread the_woodsman

I can at least help with b)

Controllers can have access to many, unrelated models, by having more
than one item in the uses array.

Good luck with the other stuff!

On Oct 19, 2:07 pm, Pinholecam [EMAIL PROTECTED] wrote:
 I've been looking for some answers to my problems but after a couple
 of hours of searching, I'll answer that.

 a)   I would need to query differents models form a component. How to
 do it?

 b)   Looking at the manual it seems that each model has one controller
 and one controller has one model. In addition, if I have some kind of
 assosiation between models, for one controller it's possible to query
 the other models associated. But if I don't have any association? How
 can I query other models? (When I talk about models, maybe I should
 talk about tables). I assume that it's possible to query directly by
 $this-Mymodel-query(), but I would use Cake DB functions.

 c)   Elements: this are pieces of code(view) that repeat in a part of
 your site, so in order to not to repeat it. I've also seen that it's
 not possible to query from elements directly to the database, but you
 get information from the function set of your controller. If the query
 and its bussiness logic is more than one line, you're also duplicating
 code, so the answer is: can you type a function from a component that
 sets the information to the view? So to set the information, just call
 the component's funtion from a controller/action.

 Thanks to all the help u can give me.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components, Controllers y Elements

2007-10-20 Thread Wayne Fay

To make that concrete...
class UsersController extends AppController {
   var $uses = array('Muppet', 'Fraggle', 'Smurf');
}

This is covered in the Cake manual too:
http://manual.cakephp.org/chapter/controllers

Wayne

On 10/20/07, the_woodsman [EMAIL PROTECTED] wrote:

 I can at least help with b)

 Controllers can have access to many, unrelated models, by having more
 than one item in the uses array.

 Good luck with the other stuff!

 On Oct 19, 2:07 pm, Pinholecam [EMAIL PROTECTED] wrote:
  I've been looking for some answers to my problems but after a couple
  of hours of searching, I'll answer that.
 
  a)   I would need to query differents models form a component. How to
  do it?
 
  b)   Looking at the manual it seems that each model has one controller
  and one controller has one model. In addition, if I have some kind of
  assosiation between models, for one controller it's possible to query
  the other models associated. But if I don't have any association? How
  can I query other models? (When I talk about models, maybe I should
  talk about tables). I assume that it's possible to query directly by
  $this-Mymodel-query(), but I would use Cake DB functions.
 
  c)   Elements: this are pieces of code(view) that repeat in a part of
  your site, so in order to not to repeat it. I've also seen that it's
  not possible to query from elements directly to the database, but you
  get information from the function set of your controller. If the query
  and its bussiness logic is more than one line, you're also duplicating
  code, so the answer is: can you type a function from a component that
  sets the information to the view? So to set the information, just call
  the component's funtion from a controller/action.
 
  Thanks to all the help u can give me.


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components and Database

2007-04-15 Thread Vincent

Thanks.

I have ended up doing the following using CakePHP 1.2.
I am using the getModel function that I created in a new common
components that I found on ThinkingPHP.org.

Then I created my Tracker component with one function Add that adds
the action and if the user is not in session creates the user record
as well and setting the user session.

I call this function in a Controller:
//track
$this-Tracker-add('ProductTags', $source, $section, $taglist);

Voila!

Code below...I am not sure this is a good practice !


?php

class trackerComponent extends Object
{
var $controller = true;
var $components = array('Common', 'Session');

function startup($controller)
{
  // This method takes a reference to the controller which is
loading it.
  // Perform controller initialization here.
  $this-controller = $controller;
}

function add($type, $parameter1 = '', $parameter2 = '',
$parameter3 = '')
{
if (!$this-Session-check('User'))
{
   //create user entry
   $newuser = $this-Common-getModel('User');
   $data['User']['ipaddress'] =  $_SERVER['REMOTE_ADDR'];
   $newuser-save($data['User']);
   $this-Session-write('User', $newuser-id);
 }

 // add new action
 $newaction = $this-Common-getModel('Action');
 $data['Action']['user_id'] = $this-Session-read('User');
 $data['Action']['type'] = $type;
 $data['Action']['parameter1'] = $parameter1;
 $data['Action']['parameter2'] = $parameter2;
 $data['Action']['parameter3'] = $parameter3;
 $newaction-save($data['Action']);
}
}

?

?php

class CommonComponent extends Object
{
var $controller = true;

function getModel($model)
{
  // Make sure our $modelClass name is camelized
  $modelClass = Inflector::camelize($model);
  // If the Model class does not exist and we cannot load
it
  if (!class_exists($modelClass)  !
loadModel($modelClass))
  {
  // Can't pass false directly because only
variables can be passed via reference
  $tmp = false;
  // Return false
  return $tmp;
  }
  // The $modelKey is the underscored $modelClass name for
the ClassRegistry
  $modelKey = Inflector::underscore($modelClass);
  // If the ClassRegistry holds a reference to our Model
  if (ClassRegistry::isKeySet($modelKey))
  {
  // Then make this our $ModelObj
  $ModelObj =
ClassRegistry::getObject($modelKey);
  }
  else
  {
  // If no reference to our Model was found in
trhe ClassRegistry, create our own one
  $ModelObj = new $modelClass();
  // And add it to the class registry for the next
time
  ClassRegistry::addObject($modelKey, $ModelObj);
  }
  // Return the reference to our Model object
  return $ModelObj;
}
}

?

On Apr 14, 1:31 am, Joshua Benner [EMAIL PROTECTED] wrote:
 Perhaps you could define a method on app/app_controller.php (class
 AppController) that will store the appropriate information, and have
 every action call that method ($this-method). Alternately, there may
 be some method on AppController you could override (and pass to
 parent) that actually calls the controller action methods.

 On Apr 13, 10:04 am, Vincent [EMAIL PROTECTED] wrote:

  Hello -

  I am kind of new to Cake and I am unsure about how to structure a
  piece of development I need to do.

  I want to create a Tracker feature whereby I will track users actions
  on my website. It is fairly simple:
  - when a user first arrive on the site, I record his IP in a session
  and on a user able (no authentication)
  - subsequently each time the user perform an action on the site
  (navigate through pages) I will record for that user an action : type
  of action , parameters for the action. For example the user selected a
  Tag to be displayed (action = select tag) and the tag is
  Sun (parameter = sun).

  I have 2 tables to implement this: user (id, ip adress...) and action
  (id, action, parameter, time, user_id).
  The user has many action.

  I was thinking of creating acomponentto implement this that I can
  call with all the controllers. Each controllers  will add actions to
  the tables.

  Thecomponentwill need to have access (essentially Write) to the two
  tables.

  My questions are:
  - how can I include a model (for my 2 tables) in acomponentAND is
  this the right thing to do?
  - is creating acomponentthe right solution?

  Many thanks!
  -Vincent


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 

Re: Components and Database

2007-04-13 Thread Joshua Benner

Perhaps you could define a method on app/app_controller.php (class
AppController) that will store the appropriate information, and have
every action call that method ($this-method). Alternately, there may
be some method on AppController you could override (and pass to
parent) that actually calls the controller action methods.

On Apr 13, 10:04 am, Vincent [EMAIL PROTECTED] wrote:
 Hello -

 I am kind of new to Cake and I am unsure about how to structure a
 piece of development I need to do.

 I want to create a Tracker feature whereby I will track users actions
 on my website. It is fairly simple:
 - when a user first arrive on the site, I record his IP in a session
 and on a user able (no authentication)
 - subsequently each time the user perform an action on the site
 (navigate through pages) I will record for that user an action : type
 of action , parameters for the action. For example the user selected a
 Tag to be displayed (action = select tag) and the tag is
 Sun (parameter = sun).

 I have 2 tables to implement this: user (id, ip adress...) and action
 (id, action, parameter, time, user_id).
 The user has many action.

 I was thinking of creating a component to implement this that I can
 call with all the controllers. Each controllers  will add actions to
 the tables.

 The component will need to have access (essentially Write) to the two
 tables.

 My questions are:
 - how can I include a model (for my 2 tables) in a component AND is
 this the right thing to do?
 - is creating a component the right solution?

 Many thanks!
 -Vincent


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Components not loading

2007-04-05 Thread bit

I've don't remember overriding the __construct method and I just
double-checked to confirm that. :-P

Tried printing out the contents of $this-components and all I got was
Session. Next I tried declaring the components array in AppController
and see if that changes anything. It did. No more errors from PHP but
then I find that the Session component is loaded and then the
components in my declared array gets loaded too - the Session
component is added twice.

And the weirdness doesn't stop there, I suddenly get a missing model
error too, even though I've declared the Uses array to use other
models - I created my own Pages controller - but Cake is now looking
for a Pages model (which doesn't exist).

Is it possible that a missing model DB table is causing this? I don't
have direct access to my server and my server sysad is sick and
missing so I can't check that right now.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components not loading

2007-04-05 Thread bit

 I wondered about that but forgot to directly ask/clarify. If you put
 code in your app controller that relies on something being present, it
 would be a *very good* idea to put what it relies upon in the same
 place ;).

I won't argue with you on that but I was hoping that I wouldn't have
to load components and helpers in controllers that didn't use 'em.
I've moved all of the Component and Helper declarations into
AppController and everything is now working as it should as far as I
can tell. :-)

Many thanks, AD!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components not loading

2007-04-05 Thread AD7six



On 5 abr, 11:03, bit [EMAIL PROTECTED] wrote:
 I've don't remember overriding the __construct method and I just
 double-checked to confirm that. :-P

 Tried printing out the contents of $this-components and all I got was
 Session. Next I tried declaring the components array in AppController
 and see if that changes anything.

Hi bit,

I wondered about that but forgot to directly ask/clarify. If you put
code in your app controller that relies on something being present, it
would be a *very good* idea to put what it relies upon in the same
place ;).

 It did. No more errors from PHP but
 then I find that the Session component is loaded and then the
 components in my declared array gets loaded too - the Session
 component is added twice.

You don't need to put Session in your own components array (any of
them, anywhere).

 And the weirdness doesn't stop there, I suddenly get a missing model
 error too, even though I've declared the Uses array to use other
 models - I created my own Pages controller - but Cake is now looking
 for a Pages model (which doesn't exist).

put in your pages controller var $users = false; or var $uses = null;
var $uses = array(); or some other negative permutation (I forget
which) that should go away.


 Is it possible that a missing model DB table is causing this?

Doubt it,

hth,

AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components not loading

2007-04-04 Thread AD7six



On 4 abr, 10:27, bit [EMAIL PROTECTED] wrote:
 I have this really weird bug in which my components aren't loading.
 The really weird thing is that when I remove a hasMany relationship in
 one of the models, this bug goes away.

If cake is about to present you with a missingX error, components
aren't loaded.

hth,

AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components not loading

2007-04-04 Thread bit

That's what I thought. I guess it'd be good to point out then that I'm
getting this error:
Fatal error: Call to a member function on a non-object

The line it refers to is: (in a private function that's called in
beforeFilter() of AppController)
return $this-Acl-check($user, $aco);

Another way I tested the components was by doing
if(!isset($this-Acl)) debug('No ACL!');

And when I tried it, I got that debug message.
Any ideas?

Thanks.


On Apr 4, 5:15 pm, AD7six [EMAIL PROTECTED] wrote:
 On 4 abr, 10:27, bit [EMAIL PROTECTED] wrote:

  I have this really weird bug in which my components aren't loading.
  The really weird thing is that when I remove a hasMany relationship in
  one of the models, this bug goes away.

 If cake is about to present you with a missingX error, components
 aren't loaded.

 hth,

 AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components not loading

2007-04-04 Thread AD7six



On 4 abr, 12:48, bit [EMAIL PROTECTED] wrote:
 That's what I thought. I guess it'd be good to point out then that I'm
 getting this error:
 Fatal error: Call to a member function on a non-object

 The line it refers to is: (in a private function that's called in
 beforeFilter() of AppController)
 return $this-Acl-check($user, $aco);

 Another way I tested the components was by doing
 if(!isset($this-Acl)) debug('No ACL!');

 And when I tried it, I got that debug message.
 Any ideas?

 Thanks.

I made an error in my previous message, partly due to an assumption on
my part of what you meant. Components are linked to the controller,
but their startup method isn't run for an error.

Have you overriden any __construct methods?
If you just do

echo $this-name.' controller has these components: ;
pr ($this-components);

what do you see when you are getting that error.

It may be caused by having a not-so-recent version of cake, but I
would guess that it doesn't work because you have overridden the
components array in a sub controller, and for reason unknown it isn't
getting merged with the array you are defining in the app controller
(it should, thanks to the work of cake).

Anyway after a bit of debugging I'm sure the cause will come clear.

hth,

AD




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Components

2006-05-16 Thread brandags

In your component, try this:
?php
class RecentPapersComponent extends Object
{
var $name = 'RecentPapers';
var $controller = true;

function init ($number = 5)
{
$Paper = new Paper;
$data = $Paper-findAll  (
null,
null,

'Paper.modified DESC',
$number
);
pr($data); // This is where it will spit out the
contents of the data. If you don't see anything, then you may have
nothing in your database.
$this-controller-set('recentpapers',$data);
}
}


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Components

2006-05-16 Thread Pierre

Thanks brandags... But i figured out the error... It was an incorrect
Sql query... Sorry to have wasted your time and good
night/morning/afternoon (i don't know where you're from ^^)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---