Re: Url problem

2008-06-22 Thread brian_gaff

In dispatcher::dispatch(), this is where cake handles loading things.
This is also where cake detects if the url passed doesn't match up
with a controller.

On line 100:
  elseif(!class_exists($ctrlClass)){
 $missingController = true;
 }

I would do some additional logic here, for example, you might consider
setting $ctrlClass = ProfilesController; and manually rewriting the
url.

I'm not Cake guru, but that seems to be the most logical approach.

An easier approach would be to use a route such as /profile/user = /
profiles/view/user

Brian


On Jun 22, 9:55 pm, AbhinavZone [EMAIL PROTECTED] wrote:
 ok..

 I am developing a property management website, where sellers come,
 register there profile and post there properties.
 I need to create a URL for there public profile, such 
 ashttp://proprtysite.com/user-name

 but cakephp taking user-name as controller name. and raising error.
 I tried to add index function in page-controller class but nothing
 happened.

 and second problem is

 the URL of property page should 
 behttp://propertysite.com/property-heading.html

 On Jun 21, 7:15 pm, simonb [EMAIL PROTECTED] wrote:

  Whatever it is will most likely involve routes. You can do almost any
  form of redirect with that.

  Like Ian says, a little bit more information would help.

  On Jun 21, 2:41 pm, Ian Zepp [EMAIL PROTECTED] wrote:

   You are going to have to provide more context than that, sorry.

   AbhinavZone wrote:
hi.

I am working on website in cakephp. everything is going fine.
but I got stuck with an issue.

1. Client requirement is to rewrite all pages as
   http://websitename.com/xx/yy.html

2. Add back link to website such as
   http://websitename.com/username

please help me out .
--~--~-~--~~~---~--~~
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: Question about finding last record in the database

2008-02-09 Thread brian_gaff

If you just added the record then

$this-Model-getLastInserID(); //will give you the id you're looking
for

Now, suppose you added the record a while ago, and you just want to
find the highest ID, then you can add the following to your app_model:

 function getHighestID()
 {
  $res = $this-query(Select `{$this-name}.id` from `{$this-name}`
ORDER BY `{$this-name}.id` DESC LIMIT 1;
  return $res[$this-name]['id'];
 }


Then from any controller you can do:

 $this-Model-getHighestID();

On Feb 9, 3:00 pm, Salam Fall [EMAIL PROTECTED] wrote:
 Just solved the problem
 Here is how I have done it
                          $ret = $this-Client-query(Select id from clients 
 order by id
 DESC LIMIT 1);
                          $newid=$ret[0]['clients']['id'] + 1;
                          $yr=date(y);
                          $account=$branch-$yr-00$newid;
                         $this-data['Client']['acct_numb'] = $account;
                         $this-Client-create();
                         if ($this-Client-save($this-data)) etc

 Now my other question is how do i create my own classes and make them
 available in the controller and the view??

 On Feb 9, 5:34 pm, Salam Fall [EMAIL PROTECTED] wrote:



  Here is what i have done so far but it's not working
                            $branch=SEN;

                          $ret = $this-Client-findBySQL(Select id from 
  clients order by id
  DESC LIMIT 1);
                          $lastId=$ret[0]['id'];
                           $act=$lastId + 1;
                          $yr=date(y);
                           $account=$branch-$yr-00$act;
                            $this-data['Client']['acct_numb'] =
  $account;
                          $this-Client-create();
                          if ($this-Client-save($this-data) etc

  On Feb 9, 5:31 pm, Salam Fall [EMAIL PROTECTED] wrote:

   Nubee here

   How do I find the last record in the database and have it's ID value
   in the controller and be able to manipulate it mathematically.

   Because all i want to do is put the ID of the last record of the
   Clients table add 1 to it and append the result to a string that will
   be used to create the Client account number.

   Also if I want to create my own custom functions or classes to add to
   my cake APP how do I do that.

   Thanks for your help.- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
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: Magento cart

2008-02-09 Thread brian_gaff

I was in the IRC Chan recently and someone had mentioned that they
were going to port Magneto to CakePHP, you might search the group for
Magneto, also drop in to the IRC Channel and ask, I dont remember
who it was.


On Feb 9, 10:16 am, cc96ai [EMAIL PROTECTED] wrote:
 I try on magento, which is pretty good,
 I wonder does cake have similar completed cart ?

 coz, i perfer cake rather than zf framework.
--~--~-~--~~~---~--~~
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: Creating form array variables using form-input

2008-02-05 Thread brian_gaff

I have to agree, form helper sometimes just doesn't bring enough to
the table to make it worthwhile.

If you really insist on using the form helper you can modify the
template it uses for field names. so instead of doing data[%s][%s],
you can just do %s.

I would either (a) create your own helper and use a similar function

function input($name=null,$options=array())
{
 if($name != null)
 {
   echo 'input type=text name=' . $name . ' ';
   foreach($options as $option=$value)
   {
 echo {$option}=\{$value}\ ;
   }
   echo '';
 }
}

$myHelper-input('name',array('style'='myStyle', 'size'='20');


Or, just modify cakes to suit your needs :0



On Feb 5, 12:57 am, boyracerr [EMAIL PROTECTED] wrote:
 Hello to all,

 I am trying to create a form which will pass an array style data
 structure through to the request via _GET.

 This should be of the format

 $search['variableName']=variableValue

 and might sometimes have arrays within the array, thus:

 $search['variableName'][] =variableValue1

 How can I achieve this? In the application I am converting, I was able
 to use:

 input name=search[variableName]

 in the HTML form, and the data would come through intact.

 However, now that I use in the view:

 ?php echo $form-input('search[variableName]', array('label' = ''));?



 This renders as:

 input name=data[ControllerName][search[variableName]]

 which seems to screw things up so that the resulting array is:

 Array
 (
 [search[variableName] = variableValue
 )

 Obviously Cake is doing some escaping stuff that interferes here.

 Is there a way I can get around this? I would rather do it the
 'proper' way using form-input than have to write it manually.

 Thanks,
 Benjamin
--~--~-~--~~~---~--~~
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: use different model in different controller.

2008-02-02 Thread brian_gaff

Anupom has already told you the correct way to do it; however, if you
really really want to do it like:

 $this-Category-find();

Then you need to add this line to the top of your Products controller:

 var $uses = array('Product', 'Category');


BRIAN

On Feb 1, 11:47 pm, Rgarg [EMAIL PROTECTED] wrote:
 Hi

 i am using two controller
 Products
 categories

 in index page i want to display all information about products as well
 as 'category name'.category name comes from Categories table.

 Model of Products is:

 ?php
   class Product extends AppModel
   {
 var $name = 'Product';
 var $belongsTo = array ('Category' = array('className' =
 'Category','conditions'='','order'='',
 'foreignKey'='category_id'));
   }
 ?

 controller is:

 class ProductsController extends AppController
 {
   //var $scaffold;
   var $name = 'Products';
 var $helpers = array('Html', 'Form', 'Tree' );
 var $components = array('Upload');

 function index() {
 $this-Product-recursive = 0;
 $this-set('products', $this-Product-findAll());

 }

 in index() i want to use

 $this-set('data', $this-Category-findAllThreaded(null, null,
 'parent_id'));
 $CategoryArray = $this-Category-generateList(null, 
 'parent_id');
 $this-set('CategoryArray', $CategoryArray);

 Please help me
 What to do for this.
--~--~-~--~~~---~--~~
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: Accessing cake session from outside

2008-02-02 Thread brian_gaff

Let me know if it works, i'm curious myself.



On Feb 1, 5:58 am, Paolo [EMAIL PROTECTED] wrote:
 Thank you very much, I'll try that.

 On 31 Gen, 06:29, brian_gaff [EMAIL PROTECTED] wrote:

  Now that I think about it, it's a little harder.

  Firstly, if you're storing your sessions via CAKE or DATABASE methods
  you're on your own.

  If you're storing your sessions via PHP method then just check /config/
  core.php and check what thesessionkey is being sent to the client
  as, usually it's CAKEPHP or something.

  Next you will probably need to do something like:

  /* this code should be run in a PHP file that's not tied to a cake app
  */

$CAKE_SESSION_COOKIE = 'CAKEPHP';

ini_set('session.use_trans_sid', 0);
ini_set('session.name', $CAKE_SESSION_COOKIE);
ini_set('session.cookie_path', _SAME_PATH_AS_RETURNED_IN_CAKE_FROM_
  $this-path);

  You'll need to find out where cake is storing it, so do a quick
  debug($this-path) and insert that above. Now you should be able to do
  session_start(); echo $_SESSION['variable'];

  I got this information from cake'sSession::_init();

  On Jan 28, 9:36 am, Paolo [EMAIL PROTECTED] wrote:

   Hi!

   How can I access cake variables from an external php file?

   Thanks
--~--~-~--~~~---~--~~
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: Producing nice url

2008-01-30 Thread brian_gaff

As far as I understand, /uploads/index is the same as /upload/, the
index action should be called by default.

But I guess you can always add a route too :)

Brian

On Jan 30, 12:40 am, Novice Programmer [EMAIL PROTECTED]
wrote:
 Hello guys,

 On my website i have given an upload feature to the user, as the user clicks
 on upload content link on my home page, it take him to index action of
 upload controller, like:
 a href = /uploads/index Upload Content /a

 But this way the url looks like :http://test.com/uploads/index

 but i want url to look likehttp://test.com/uploads

 Please help me if there is any way out. Routes is the one way i did this.
 Some other way is what i am looking for.

 --
 Thanks  Regards,
 Novice (http://ishuonweb.wordpress.com/).
--~--~-~--~~~---~--~~
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: Un-escaping sanitized data for display

2008-01-30 Thread brian_gaff

But, as far as I understand Cake already handles Sanitize::SQL for
you. So you shouldn't need to do that again. That might be why you
think you're getting stuff back in an unreadable format, you're likely
sanitizing twice.

Brian

On Jan 30, 9:04 pm, brian_gaff [EMAIL PROTECTED] wrote:
 Maybe something like this:

 var $swaps = array('\n','\r','\\');

 function unSanitize($str)
 {
   foreach($swaps in $item)
   {
 /* search for the item as \n or \r then put it in quotes for php
 to evaluate it and replace it back in */
 $str = str_replace($item, {$item}, $str);
   }

 }

 Something like that might work. I haven't tested it, but it might get
 you started.

 Brian

 On Jan 29, 1:05 am, senseBOP [EMAIL PROTECTED] wrote:

  Hey guys, hope I'm posting this in the right group and all...

  Unless there's another way to go about this, shouldn't the Sanitize
  class also include a method to un-escape sanitized data back into a
  readable, user-friendly, format? Otherwise, what's the point of having
  it sanitized?

  I'm no big expert, and there's probably a way for me to un-escape data
  from the database before displaying it back to the user, but so far, I
  have failed to find such a way. And to me, it only makes sense that
  the class that is responsible for re-formatting the data going into
  the DB will also be responsible to format it back to readable form
  once it is pulled from the DB.

  BWhat's your take on this?
--~--~-~--~~~---~--~~
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: Saving Related Model Data (I am confused)

2008-01-30 Thread brian_gaff

you might try:

/* make sure it knows we're making a new instance of Comment */
$this-Post-Comment-create();
$this-Post-Comment-save($this-data);



On Jan 29, 4:07 am, Raistlin Majere [EMAIL PROTECTED] wrote:
 I think you are right, but I wish I had a confirmation.

 Thanks, anyway! :-)

 On 28 jan, 22:30, Sam Sherlock [EMAIL PROTECTED] wrote:

  The first save is the Post the second the comment

  the post is save to return the post id required to save the linked comment

  as I understand anyway; someone with more cake knowledge may have something
  to add

  On 28/01/2008, Raistlin Majere [EMAIL PROTECTED] wrote:

   function add()
   {
   if (!empty($this-data))
   {
   // Here we save all post data.
   // If Comment is part of all post data, we save Comment.

   $this-Post-save($this-data);

   $post_id = $this-Post-getLastInsertId();

   $this-data['Comment']['post_id'] = $post_id;

   // Observe that Comment is part of Post.
   // Observe that Comment was saved and Comment is saved again.

   $this-Post-Comment-save($this-data);

   }
   }

   // Why save the Comment data twice?
--~--~-~--~~~---~--~~
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: Accessing cake session from outside

2008-01-30 Thread brian_gaff

Pretty sure it's just:

  $_SESSION['varname'];

From what I can tell from the cake source it doesn't salt variables or
anything, so it looks like you can just access it directly.

 $this-Session-write('name','brian');

and

 echo $_SESSION['name']; //should be brian

On Jan 28, 9:36 am, Paolo [EMAIL PROTECTED] wrote:
 Hi!

 How can I access cake variables from an external php file?

 Thanks
--~--~-~--~~~---~--~~
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: Accessing cake session from outside

2008-01-30 Thread brian_gaff

Now that I think about it, it's a little harder.

Firstly, if you're storing your sessions via CAKE or DATABASE methods
you're on your own.

If you're storing your sessions via PHP method then just check /config/
core.php and check what the session key is being sent to the client
as, usually it's CAKEPHP or something.

Next you will probably need to do something like:

/* this code should be run in a PHP file that's not tied to a cake app
*/

  $CAKE_SESSION_COOKIE = 'CAKEPHP';

  ini_set('session.use_trans_sid', 0);
  ini_set('session.name', $CAKE_SESSION_COOKIE);
  ini_set('session.cookie_path', _SAME_PATH_AS_RETURNED_IN_CAKE_FROM_
$this-path);

You'll need to find out where cake is storing it, so do a quick
debug($this-path) and insert that above. Now you should be able to do
session_start(); echo $_SESSION['variable'];

I got this information from cake's Session::_init();



On Jan 28, 9:36 am, Paolo [EMAIL PROTECTED] wrote:
 Hi!

 How can I access cake variables from an external php file?

 Thanks
--~--~-~--~~~---~--~~
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: hasOne association question

2008-01-26 Thread brian_gaff

Is this proper behavior? It seems like it should not return an Answer
array at all.

Yes. You can do something like

 if(isset($question['Answer']['id']))
 {
  /* do something with answer */
 }


You might consider reversing it and putting the foriegn key in the
questions table, and having each Answer haveOne question and each
Question belongTo an answer. If you do that you can do:

 $questionsWithNoAns = $this-Question-
findAll(array('Question.answer_id' = 0));




On Jan 25, 12:18 pm, Corie [EMAIL PROTECTED] wrote:
 Using Cake 1.2, when I perform a findAll() on a model with a hasOne
 association it's returning an array for the associated table even if
 there is no record.

 Here's an example.

 // question.php
 class Question extends AppModel
 {
         var $name = 'Question';
         var $hasOne = 'Answer';

 }

 // answer.php
 class Answer extends AppModel
 {
         var $name = 'Answer';
         var $belongsTo = 'Question';

 }

 // questions_controller.php
 class QuestionsController extends AppController
 {
         function index()
         {
                 $questions = $this-Question-findAll();
                 pr($questions);
         }

 }

 // outputs

 Array
 (
     [0] = Array
         (
             [Question] = Array
                 (
                     [id] = 4
                     [question] = why?
                     [created] = 2008-01-25 00:23:44
                     [ip] = 192.168.0.101
                 )

             [Answer] = Array
                 (
                     [id] =
                     [question_id] =
                     [answer] =
                     [created] =
                     [name] =
                 )
         )
 )

 Is this proper behavior? It seems like it should not return an Answer
 array at all.

 Anyways, another question is, how would I go about finding only
 questions which do not have answers?
--~--~-~--~~~---~--~~
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: $this-data variable not showing data passed on?

2008-01-26 Thread brian_gaff

if you do: (in the controller)
 debug(print_r($this-data,true));

It doesn't return anything?

On Jan 25, 10:55 pm, Darren884 [EMAIL PROTECTED] wrote:
 Is it my server? The data will save but when I used print_r to output
 the array it will not show the post data. The only data it shows is if
 the value is pass through like value=data in the input tag. If I try
 to use $this-data['att']['field'] it will not display any inputted
 data passed on through a post form... any ideas as to why this occurs?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Log controller

2008-01-07 Thread brian_gaff

Hi,
I have a website that is basically a shopping cart. It has Products,
Manufactures, Users, etc.

I've added a 'Notes' controller with the following fields:
 id
 user_id
 product_id
 manufacturer_id
 text

The idea is that I can set the respective foreign key so that I can
use the notes controller to add notes to any object. Is this the
correct way to do it?

My next question is, I want to automatically add a note when an
administrator does certain tasks, eg, modify a user account.

I was thinking about using the $controller-requestAction(), however,
if the note is fairly long it will be kind of weird to do this:

 /* this is just psuedo code, I do not actually store session
information like this */

 $ses = $this-Session-read('currentUser');
 $note = User account was suspended by {$ses['User']['username']};
 $this-requestAction('/admin/notes/add/' . $note);

It would seem weird to request an action with spaced text like that.
Is there another way to do it, i guess what I'm asking is...
requestAction is like GET, is there another way that's similiar to a
POST. Is it safe to do what I want to do this way?

--~--~-~--~~~---~--~~
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: Log controller

2008-01-07 Thread brian_gaff

How would you instantiate a note object? Can you please give me an
example?


Thanks.
Brian


On Jan 7, 8:28 pm, Robby Anderson [EMAIL PROTECTED] wrote:
 I would setup the notes one of two ways:

 id
 parent
 parent_id
 text
 created

 Where parent = the model name you want to link to  and parent_id is
 the foreign key. This allows you to link to any model that you want
 to, instead of just the ones you listed, and is a bit better design.
 (I'd also add a user_id column to link to the adding user.) However,
 this always limits a note to a single entity. You can also create
 notes with two tables:

 id
 text
 created

 and a second note_parent table

 id
 note_id
 parent
 parent_id

 Again, where parent = the model name you want to link to and parent_id
 is the foreign key. (And again, I'd add a user_id to the notes table.)
 This allows you to link a single note to multiple models (much like
 tags).

 As for auto-creating a note on certain actions, why note just
 instantiate a note object, pass it the data you want to save and save
 it right then and there?

--~--~-~--~~~---~--~~
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: Log controller

2008-01-07 Thread brian_gaff

But each Product, User, Manufacturer, Bid, Etc, hasMany Notes...

On Jan 7, 8:29 pm, aranworld [EMAIL PROTECTED] wrote:
 I think you will find that the system is more maintainable if you
 simply add a notes column to the Products, Manufacturers and Users
 tables.

 On Jan 7, 7:53 pm, brian_gaff [EMAIL PROTECTED] wrote:

  Hi,
  I have a website that is basically a shopping cart. It has Products,
  Manufactures, Users, etc.

  I've added a 'Notes' controller with the following fields:
   id
   user_id
   product_id
   manufacturer_id
   text

  The idea is that I can set the respective foreign key so that I can
  use the notes controller to add notes to any object. Is this the
  correct way to do it?

  My next question is, I want to automatically add a note when an
  administrator does certain tasks, eg, modify a user account.

  I was thinking about using the $controller-requestAction(), however,
  if the note is fairly long it will be kind of weird to do this:

   /* this is just psuedo code, I do not actually store session
  information like this */

   $ses = $this-Session-read('currentUser');
   $note = User account was suspended by {$ses['User']['username']};
   $this-requestAction('/admin/notes/add/' . $note);

  It would seem weird to request an action with spaced text like that.
  Is there another way to do it, i guess what I'm asking is...
  requestAction is like GET, is there another way that's similiar to a
  POST. Is it safe to do what I want to do this way?

--~--~-~--~~~---~--~~
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: Log controller

2008-01-07 Thread brian_gaff

I've completed this using Robby Anderson's suggestions. I found that
it would probably be easiest to create a Notes component to do the
tricker, here is all the code:


 NOTES COMPONENT

?php
class NoteComponent extends Object
{
var $note_model = 'Note';
var $parent_field = 'parent';
var $parent_id_field = 'parent_id';
var $text_field = 'text';

function saveNote($parent,$parent_id,$text)
{
//create a new note object
if (ClassRegistry::isKeySet($this-note_model))
{
$UserModel = ClassRegistry::getObject($this-
note_model);
}
else
{
loadModel($this-note_model);
$UserModel = new $this-note_model;
}
$arr = array($this-note_model =
array(

$this-parent_field = $parent,

$this-parent_id_field = $parent_id,

$this-text_field = $text
)
);
$UserModel-save($arr);

}
}
?


- NOTES MODEL

?php
class Note extends AppModel
{

var $name = 'Note';

var $belongsTo = array(
'Product' =
array('className' = 'Product',
'foreignKey' = 'parent_id',
'conditions' = Note.parent = 
'Product',
'fields' = '',
'order' = '',
'counterCache' = ''
),

'Manufacturer' =
array('className' = 'Manufacturer',
'foreignKey' = Note.parent = 
'Manufacturer',
'conditions' = '',
'fields' = '',
'order' = '',

'counterCache' = ''
),

);
}
?


- Product model (for example)

class Product extends AppModel {

var $name = 'Product';

var $hasMany = array(
'Note' =
array('className' = 'Note',
'foreignKey' = 'parent_id',
'conditions' = Note.parent = 
'Product',
'fields' = '',
'order' = '',
'limit' = '',
'offset' = '',
'dependent' = '',
'exclusive' = '',
'finderQuery' = '',
'counterQuery' = ''
),
);

}
?



Then this can be used very easily from any controller:

function admin_view($id = null) {
$this-Note-saveNote('Product',$id,'Product was viewed.');
}

Make sure to do $components = Array('Note');





I hope this helps someone!


Brian

--~--~-~--~~~---~--~~
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: Log controller

2008-01-07 Thread brian_gaff

I've completed this using Robby Anderson's suggestions. I found that
it would probably be easiest to create a Notes component to do the
tricker, here is all the code:


 NOTES COMPONENT

?php
class NoteComponent extends Object
{
var $note_model = 'Note';
var $parent_field = 'parent';
var $parent_id_field = 'parent_id';
var $text_field = 'text';

function saveNote($parent,$parent_id,$text)
{
//create a new note object
if (ClassRegistry::isKeySet($this-note_model))
{
$UserModel = ClassRegistry::getObject($this-
note_model);
}
else
{
loadModel($this-note_model);
$UserModel = new $this-note_model;
}
$arr = array($this-note_model =
array(

$this-parent_field = $parent,

$this-parent_id_field = $parent_id,

$this-text_field = $text
)
);
$UserModel-save($arr);

}
}
?


- NOTES MODEL

?php
class Note extends AppModel
{

var $name = 'Note';

var $belongsTo = array(
'Product' =
array('className' = 'Product',
'foreignKey' = 'parent_id',
'conditions' = Note.parent = 
'Product',
'fields' = '',
'order' = '',
'counterCache' = ''
),

'Manufacturer' =
array('className' = 'Manufacturer',
'foreignKey' = Note.parent = 
'Manufacturer',
'conditions' = '',
'fields' = '',
'order' = '',

'counterCache' = ''
),

);
}
?


- Product model (for example)

class Product extends AppModel {

var $name = 'Product';

var $hasMany = array(
'Note' =
array('className' = 'Note',
'foreignKey' = 'parent_id',
'conditions' = Note.parent = 
'Product',
'fields' = '',
'order' = '',
'limit' = '',
'offset' = '',
'dependent' = '',
'exclusive' = '',
'finderQuery' = '',
'counterQuery' = ''
),
);

}
?



Then this can be used very easily from any controller:

function admin_view($id = null) {
$this-Note-saveNote('Product',$id,'Product was viewed.');
}

Make sure to do $components = Array('Note');





I hope this helps someone!


Brian

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