Re: Components and Database
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 ! 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']); } } ?> 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" 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 and Database
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 -~--~~~~--~~--~--~---
Components and Database
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 -~--~~~~--~~--~--~---