Sunday, February 28, 2010

Re: how to adress specific data from related models?

Shame it's only partially translated as the cookbook is far and away
the best resource.

We will do what we can to help you when you need it :)

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

Re: (views) Redirect where i came from

John

> You only use {$this->modelClass} when you want to use the model
> instance.

Thats it. Thanks very much! :)

If someone other wants to use this, here is my final code (add
function in app_controller):

[code]
function add()
{
if(!empty($this->data))
{
if($this->{$this->modelClass}->save($this->data))
{
$this->Session->setFlash('saved!');
$this->redirect($this->data[$this->modelClass]['referer']);
}
else
{
$this->Session->setFlash('fail!');
}
}
if (!$this->data[$this->modelClass]['referer'])
{
$this->data[$this->modelClass]['referer'] = $this->referer();
}
}
[/code]

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

Re: (views) Redirect where i came from

John

> You only use {$this->modelClass} when you want to use the model
> instance.

Thats it. Thanks very much! :)

If someone other wants to use this, here is my final code (add
function in app_controller):

[code]
function add()
{
if(!empty($this->data))
{
if($this->{$this->modelClass}->save($this->data))
{
$this->Session->setFlash('Speichervorgang erfolgreich!');
$this->redirect($this->data[$this->modelClass]['referer']);
}
else
{
$this->Session->setFlash('Speichervorgang fehlgeschlagen!');
}
}
if (!$this->data[$this->modelClass]['referer'])
{
$this->data[$this->modelClass]['referer'] = $this->referer();
}
}
[/code]

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

Re: (views) Redirect where i came from

You only use {$this->modelClass} when you want to use the model
instance.
In you data array, just use $this->modelClass without the curly
brackets!
Enjoy,
John

On Mar 1, 8:53 am, sebb86 <kahlc...@googlemail.com> wrote:
> Paul
>
> In my inventory-management, every table/model has the need of an add-
> function. The models are, for example: rooms, locations,
> hardware_groups, hardware_units, mobile_radio_units, ports ... and so
> on.
> Furthermore, the add functions are equal to each other, expect, if
> there is an foreign-key inside. So i'd like to create the add-function
> in the app_controller.
>
> Your code works, thanks! :)
> My last question is, do you know how to make this dynamical, because
> the code has to be inside the add_controller.
>
> [code]
>   function add()
>   {
>     if(!empty($this->data))
>     {
>       if($this->{$this->modelClass}->save($this->data))
>       {
>         $this->Session->setFlash('Speichervorgang erfolgreich!');
>         $this->redirect($this->data[{$this->modelClass}]['referer']);
>       }
>     }
>     if (!$this->data[{$this->modelClass}]['referer'])
>     {
>       $this->data[{$this->modelClass}]['referer'] = $this->referer();
>     }
>   }
> [/code]
>
> I've tryed: {$this->modelClass}
> I think the result of this is only the [code]class[/code] but i need
> [code]'class'[/code].
>
> And again, thank you very much for helping me in nearly all me topics!

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

Re: How to set "paginate -> limit" on the fly in my views?

Thanks for your answers but i think it's to difficult for me to solve
that.
But thanks a lot!

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

AW: Mod_rewrite with Ubuntu 9.10

Hi,

I have solved the problem:

As some suggested I looked in the error log (What an idea, to check the error log! That is absurd like reading the manual! *ggg*)
And the error was something like: To many redirects.

Then I looked up this error message on the inernet and someones else had the same problem and solved it by specifying the complete path relative to the server root. That is what I did and it worked!

So my server root is at /var/www/
My app (development installation) is at /var/www/budget/ (budget is the app)

In my .htaccess files I specified the path to the webroot as /budget/app/webroot/

And - o wonders - it worked and I spend half of Sunday happily coding away.

I hope this helps you, too.

Anja

-----Ursprüngliche Nachricht-----
Von: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] Im Auftrag von edmicman
Gesendet: Mittwoch, 24. Februar 2010 16:25
An: CakePHP
Betreff: Re: Mod_rewrite with Ubuntu 9.10

I'm having the exact same problem, I just posted about it last night on here. If you figure anything out, please update!

On Feb 24, 5:01 am, "Liebermann, Anja Carolin"
<anja.lieberm...@alltours.de> wrote:
> Hello,
>
> At home I upgraded my PC to ubuntu 9.10 and I try to get cake running
> again (development version).
>
> Mod_rewrite is loaded and works for the rest of the webserver. With
> cake I either get a html page with some text and not working links or
> I set allowOverride to "All" as suggested in a lot of tutorials and
> then I get an 500 error.
>
> Has anybody cakephp 1.2 running on a ubuntu 9.10 and could post me the
> apache2 settings or any suggestion what else I could configure?
>
> Thanks a lot in advance
>
> Anja

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

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

Re: (views) Redirect where i came from

Paul

In my inventory-management, every table/model has the need of an add-
function. The models are, for example: rooms, locations,
hardware_groups, hardware_units, mobile_radio_units, ports ... and so
on.
Furthermore, the add functions are equal to each other, expect, if
there is an foreign-key inside. So i'd like to create the add-function
in the app_controller.

Your code works, thanks! :)
My last question is, do you know how to make this dynamical, because
the code has to be inside the add_controller.

[code]
function add()
{
if(!empty($this->data))
{
if($this->{$this->modelClass}->save($this->data))
{
$this->Session->setFlash('Speichervorgang erfolgreich!');
$this->redirect($this->data[{$this->modelClass}]['referer']);
}
}
if (!$this->data[{$this->modelClass}]['referer'])
{
$this->data[{$this->modelClass}]['referer'] = $this->referer();
}
}
[/code]

I've tryed: {$this->modelClass}
I think the result of this is only the [code]class[/code] but i need
[code]'class'[/code].

And again, thank you very much for helping me in nearly all me topics!

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

Re: configuration and datasource

Hi

I would store the constants in the database but cache the query.
Here's an example

function getSettings($refresh = false) {
if ($refresh || !$settings = Cache::read('settings')) {
$settings = $this->find('list');
Cache::write('settings', $settings);
}
return $settings;
}

That will make sure that your db query is cached, so you won't have
the db overhead on every action. You'll just need to ensure that you
call a refreshed version of the settings table on every cud operation
to ensure that the data returned is up to date.

On Mar 1, 5:14 am, Roey <roeygr...@gmail.com> wrote:
> Hello all,
> My cakephp application uses a few custom configuration constants which
> I load from a configuration file.
> I would like to have some of the users to be able to change the
> settings of these constants.
> My first idea was to use a database table  which will contain these
> configuration constants, but then I thought that every call to every
> url would also create an extra call to a certain db table to fetch
> these config constants.
> I thought of another option which is creating a datasource which will
> be mapped to a configuraion file so when an update will be needed,
> this file will be re-written.
> Is it a good idea?
> How can I expose my configuration constants to be changed by some
> users without loosing performance ? The database is constantly being
> read and I don't want to add another read/write operation to it...
> Thanks very much,
> Roey

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

Re: Apply https for a particular module

This should get you started:

http://book.cakephp.org/view/268/Usage

This works in 1.2 and 1.3 - I can't confirm that the same for 1.1 though.

Jeremy Burns


On 1 Mar 2010, at 04:28, SeeVik wrote:

> Hello all
>
> I am using Cakephp 1.1 for my webapp and I want to use https when the
> user logs in his user account. For guest users I want the simple http
> connection to be used.
>
> Can this be done by using some setting in cakephp or should it be set
> it in Apache configuration?
>
> Thanks and Regards
> ShiVik
>
> 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

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

Apply https for a particular module

Hello all

I am using Cakephp 1.1 for my webapp and I want to use https when the
user logs in his user account. For guest users I want the simple http
connection to be used.

Can this be done by using some setting in cakephp or should it be set
it in Apache configuration?

Thanks and Regards
ShiVik

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

AppModel schizophrenia

I have several models for which I want to list the latest entries in a
sidebar. All models have a title & slug, so to keep from repeating
code, I've put the method in AppModel.

AppModel:

public function getLatest($limit = 10)
{
$filters = array(
'limit' => $limit,
'order' => $this->alias . '.created DESC',
'fields' => array(
$this->alias . '.id',
$this->alias . '.created',
$this->alias . '.title',
$this->alias . '.slug'
),
'recursive' => -1
);

return $this->find('all', $filters);
}


default layout:

echo $this->element('news_items/latest', array('cache'=>'1 day'));
echo $this->element('posts/latest', array('cache'=>'1 day'));
echo $this->element('galleries/latest', array('cache'=>'1 day'));

views/elements/galleries/latest.ctp:

$latest_galleries = $this->requestAction('/galleries/getlatest/5');
...

PostsController:

public function getLatest($limit)
{
return $this->Post->getLatest($limit);
}

GalleriesController:

public function getLatest($limit)
{
return $this->Gallery->getLatest($limit);
}

(caching is disabled, btw, and everything has been deleted from tmp/
cache, anyway)

This works just fine except that the find() for Gallery is always
selecting from the posts table!

SELECT `Gallery`.`id`, `Gallery`.`created`, `Gallery`.`title`,
`Gallery`.`slug`
FROM `posts` AS `Gallery`
WHERE 1 = 1 ORDER BY `Gallery`.`created` DESC LIMIT 5


There's absolutely nothing in Gallery model that mentions Post. When I
save a Gallery, it's saved to the galleries table. Likewise, fetching
for the index or view actions is all correct. The problem only shows
up with these elements. And, if I re-order the elements in any way, I
get the same result--always the Gallery results are fetched from the
posts table.

If I remove the call to the posts element from the layout, the
galleries element is still wrong.

And notice that $this->alias is correct--'Gallery'--but the table is
wrong.

I've checked that the requestAction() does correctly call the
GalleriesController. The trouble seems to be with the model.

Ring any bells?

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

Re: ClassRegistry('init') more than once returns same Model id

The create() method appears to do exactly what I want to do.

The book says it perfectly:
"When calling save in a loop, don't forget to call create()."

Previously, I have not had to call create because I have only been
saving a single instance of a Model in each of my controller methods.

Thank you for this tip!
-Greg

On Feb 28, 2:30 pm, John Andersen <j.andersen...@gmail.com> wrote:
> In my opinion, there should only be one instance of the model! You
> just have to use it to create many new records!
>
> Use the models create method to ensure that each record is saved as a
> new record. See the CakePHP book at:http://book.cakephp.org/view/75/Saving-Your-Data
>
> So, still in my opinion, you should change your code as follows:
> [code]
> $UserBadge = ClassRegistry::init('UserBadge');
> foreach ($new_badges as $new_badge){
>    if ($new_badge){
>       $UserBadge->create();
>       $UserBadge->set('user_id', $check_in["User"]["id"]);
>       $UserBadge->set('check_in_id', $check_in["CheckIn"]["id"]);
>       $UserBadge->set('badge_id', $new_badge);
>       $UserBadge->save();
>       $awarded_badges[]=$UserBadge;
>       unset($UserBadge);
>    }}
>
> [/code]
>
> But I may be wrong, that you are not just saving the records (badges)
> but that you want to store the entire model in the $awarded_badges
> array for every badge?? :)
>
> Please enlighten me, enjoy,
>    John
>
> On Feb 27, 6:12 pm, Greg Marra <greg.ma...@gmail.com> wrote:
>
>
>
> > Hello,
>
> > I have a site where I am using ClassRegistry('init') to create
> > multiple new objects inside of a component. I want to save each one
> > into the database. Unfortunately, it seems that each time I call
> > ClassRegistry('init') I appear to get the same instance of the Model.
> > The net result is that instead of having two or three objects in my
> > database, it gets overwritten and overwritten and I end up with just
> > the most-recently-saved one.
>
> > Here is my code:
> > foreach ($new_badges as $new_badge){
> >                         if ($new_badge){
> >                                 $UserBadge = ClassRegistry::init('UserBadge');
> >                                 $UserBadge->set('user_id', $check_in["User"]["id"]);
> >                                 $UserBadge->set('check_in_id', $check_in["CheckIn"]["id"]);
> >                                 $UserBadge->set('badge_id', $new_badge);
> >                                 $UserBadge->save();
> >                                 $awarded_badges[]=$UserBadge;
> >                                 unset($UserBadge);
> >                         }
> >                 }
>
> > Any idea why this isn't working as expected?

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

Re: Showing selected values in a HABTM

Nevermind, I got it figured out, thank you for your help.

On Feb 28, 9:24 pm, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
> I'm not sure I am following. I see where you are setting the data that
> you have, but I am not seeing where you are using that data in the
> view at all? Or do you not need to use it anywhere, cake just does?
>
> On Feb 28, 4:11 am, John Andersen <j.andersen...@gmail.com> wrote:
>
> > This is what I do, a small view example:
> > [code]
> > <?php echo $form->create('Permit',array('action' => 'add')); ?>
> >    <?php echo $form->input('Activity',array('multiple' => 'checkbox',
> > 'label' => 'Activity')); ?>
> > <?php echo $form->end('Save'); ?>
> > [/code]
>
> > and to ensure that the Activity field is filled with the possible
> > values and the chosen ones are checked, here is the small controller
> > code example:
> > [code]
> >       $permits = $this->Permit->find(
> >          'first', array(
> >             'conditions' => array(
> >                'Permit.id' => 1
> >             ),
> >             'contain' => array(
> >                'Leader' => array('Country','ProvState'),
> >                'User',
> >                'RegistrationLocation',
> >                'Activity'
> >             )
> >          )
> >       );
> >       $this->data = $permits;
> >       $this->set('activities',$this->Permit->Activity->find('list',array('contain' => false)));
>
> > [/code]
>
> > Hope this helps you on the way ;)
> > Enjoy,
> >    John
>
> > On Feb 28, 10:37 am, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
>
> > > Hey everyone, I did try looking around here and on google for this
> > > issue, however I can only find data that relates to problems 3 years
> > > ago, which doesn't help as much as I'd like it to. I could likely use
> > > it, but I figured that by now, Cake must have a more elegant way of
> > > doing this.
>
> > > I want to show the data that was selected in a HABTM in my edit form.
> > > I can see that the data is populated in $this->data when I do a
> > > read(), however it doesn't seem to be populating the multi-select box
> > > I have created.
>
> > > This is the code for the multi-select box:
> > > echo $form->input('Activity', array('label' => false, 'type' =>
> > > 'select', 'options' => $dbactivities, 'multiple' => true));
>
> > > Can anyone tell me how to display what items are selected?

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

Re: falsefalse

Okay, well, I'm still not sure, because everything you did is the same
as me from what I can tell, except you didn't specify fields grabbed
in your models. I removed that info in mine, but that didn't change
anything.

I'm not sure, but I have a feeling this all relates to the fact that
contain doesn't seem to be grabbing anything that is two levels deep,
it grabs a model fine and it's associations fine, but it is not
grabbing the associations of the associations. This seems like a
recursive problem to me, but I tried setting the recursive property of
the model and that didn't help, but I might have done it wrong, I
haven't been able to find an example of doing it.

On Feb 28, 3:29 am, John Andersen <j.andersen...@gmail.com> wrote:
> Ok, have recreated your situation - and it just works!
>
> My result:
> [result]
> Array
> (
>     [Permit] => Array
>         (
>             [id] => 1
>             [created] => 2010-02-28 10:55:16
>             [user_id] => 1
>             [leader_id] => 1
>             [registration_location_id] => 1
>         )
>     [User] => Array
>         (
>             [id] => 1
>             [name] => user1
>         )
>     [Leader] => Array
>         (
>             [id] => 1
>             [name] => leader 1
>             [created] => 2010-02-27 10:53:57
>             [country_id] => 1
>             [prov_state_id] => 1
>             [user_id] => 1
>             [Country] => Array
>                 (
>                     [id] => 1
>                     [name] => country 1
>                 )
>             [ProvState] => Array
>                 (
>                     [id] => 1
>                     [name] => prov state 1
>                 )
>         )
>     [RegistrationLocation] => Array
>         (
>             [id] => 1
>             [name] => location 1
>         )
> )
> [/result]
>
> based on the Permit controllers find:
> [code]
>       $permits = $this->Permit->find(
>          'first', array(
>             'conditions' => array(
>                'Permit.id' => 1
>             ),
>             'contain' => array(
>                'Leader' => array('Country','ProvState'),
>                'User',
>                'RegistrationLocation'
>             )
>          )
>       );
>       debug($permits);
> [/code]
>
> Using only the following models:
> user.php
> leader.php
> permit.php
>
> Thus RegistrationLocation, Country and ProvState uses the AppModel as
> base.
>
> My models are defined as:
> [UserModel]
> class User extends AppModel {
>     var $name = 'User';
>     var $hasMany = array('Leader','Permit');}
>
> [/UserModel]
>
> [LeaderModel]
> class Leader extends AppModel {
>     var $name = 'Leader';
>     var $hasMany = array('Permit');
>     var $belongsTo = array('User','Country','ProvState');}
>
> [/LeaderModel]
>
> [PermitModel]
> class Permit extends AppModel {
>     var $name = 'Permit';
>     var $belongsTo = array('User','Leader','RegistrationLocation');}
>
> [/PermitModel]
>
> Please compare with your situation, maybe the above will help you on
> the way.
> Enjoy,
>    John
> On Feb 28, 10:46 am, John Andersen <j.andersen...@gmail.com> wrote:
>
> > Could be! I am trying to recreate your situation here at my place, to
> > confirm that I too can't retrieve the Country.
> > Will be back shortly :)
> >    John
>
> > On Feb 28, 10:40 am, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
>
> > > This is the only thing that is even remotely relevant in app_model:
>
> > > var $actsAs = array(
> > >                         'Containable'
> > >                 );
>
> > > Other then that, there are only 2 functions, one for validating phone
> > > numbers, and one for changing dates to a format I want.
>
> > > Like I have said previously, this is all working when I do the search
> > > on the model Leader, just not when I do the search on the model Permit
> > > and have a contain with Leader in it, and then a contain with the
> > > country data.
>
> > > So because it works for something, just not quite as deep, I have a
> > > feeling we are looking in the entirely wrong area.
>
> > [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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Re: Showing selected values in a HABTM

I'm not sure I am following. I see where you are setting the data that
you have, but I am not seeing where you are using that data in the
view at all? Or do you not need to use it anywhere, cake just does?

On Feb 28, 4:11 am, John Andersen <j.andersen...@gmail.com> wrote:
> This is what I do, a small view example:
> [code]
> <?php echo $form->create('Permit',array('action' => 'add')); ?>
>    <?php echo $form->input('Activity',array('multiple' => 'checkbox',
> 'label' => 'Activity')); ?>
> <?php echo $form->end('Save'); ?>
> [/code]
>
> and to ensure that the Activity field is filled with the possible
> values and the chosen ones are checked, here is the small controller
> code example:
> [code]
>       $permits = $this->Permit->find(
>          'first', array(
>             'conditions' => array(
>                'Permit.id' => 1
>             ),
>             'contain' => array(
>                'Leader' => array('Country','ProvState'),
>                'User',
>                'RegistrationLocation',
>                'Activity'
>             )
>          )
>       );
>       $this->data = $permits;
>       $this->set('activities',$this->Permit->Activity->find('list',array('contain' => false)));
>
> [/code]
>
> Hope this helps you on the way ;)
> Enjoy,
>    John
>
> On Feb 28, 10:37 am, "Arak Tai'Roth" <nielsen.dus...@gmail.com> wrote:
>
> > Hey everyone, I did try looking around here and on google for this
> > issue, however I can only find data that relates to problems 3 years
> > ago, which doesn't help as much as I'd like it to. I could likely use
> > it, but I figured that by now, Cake must have a more elegant way of
> > doing this.
>
> > I want to show the data that was selected in a HABTM in my edit form.
> > I can see that the data is populated in $this->data when I do a
> > read(), however it doesn't seem to be populating the multi-select box
> > I have created.
>
> > This is the code for the multi-select box:
> > echo $form->input('Activity', array('label' => false, 'type' =>
> > 'select', 'options' => $dbactivities, 'multiple' => true));
>
> > Can anyone tell me how to display what items are selected?

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

configuration and datasource

Hello all,
My cakephp application uses a few custom configuration constants which
I load from a configuration file.
I would like to have some of the users to be able to change the
settings of these constants.
My first idea was to use a database table which will contain these
configuration constants, but then I thought that every call to every
url would also create an extra call to a certain db table to fetch
these config constants.
I thought of another option which is creating a datasource which will
be mapped to a configuraion file so when an update will be needed,
this file will be re-written.
Is it a good idea?
How can I expose my configuration constants to be changed by some
users without loosing performance ? The database is constantly being
read and I don't want to add another read/write operation to it...
Thanks very much,
Roey

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

Controller Callback or Hooks when using additional class paths

Here is the setup. I am using cakePHP 1.2. I have a User/Content
Management System, at the same level of the cake core. Similar to
WildFlower CMS. I use cakePHP's additional class paths to include the
code. I have it up and working, but when I want to customize the
User Controller, I have to copy the whole controller into my app
directory, and modify the code. I want to be able to keep theUser/
Content Management completely seperate from my app, so I won't have
to diff the code everytime I make a change. How can I create a
callback system, that triggers before, or after an action in the
management system fires, and have it trigger a controller/method in
my App Directory. I found this code in the AppController of
WildFlower, but it still seems to not work. I guess it is still
under construction.

/**
* @TODO Under construction
*
* Launch callbacks if they exist for current controller/method
*
* Callback for controllers are stored in <code>app/controllers/
wildflower-callbacks/</code>.
* The name convencions is unserscored class that you want to plug
into with "_callback"
* suffix. Examples:
*
* - pages_controller_callback.php
* - comments_controller_callback.php
* - wildflower_app_controller_callback.php
*
* @param string $when Launch <code>before</code> or <code>after</
code> current action
*/
function wildflowerCallback($when = 'after') {
// app_controller
if (class_exists('AppControllerCallback')) {
$plugin = new AppControllerCallback;
foreach (array('beforeFilter', 'afterFilter') as $filter)
{
$method = $filter;
if (method_exists($plugin, $method)) {
$plugin->{$method}();
return;
}
}
}

$className = Inflector::camelize($this-
>params['controller']) . 'ControllerCallback';
if (class_exists($className)) {
$plugin = new $className;
$method = $when . '_' . $this->params['action'];
if (method_exists($plugin, $method)) {
$plugin->{$method}();
return;
}
}
}

I definitely can use help on this. Thank you.

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

Use Mobile Save Paper

Hello ,
Your friend Sridhar K N has joined the Idea Use Mobile Save Paper campaign and wants you to join in too.

Re: Order 2 arrays in one view

Nevermind, found the answer in another topic and got it, it was very
helpful, thanks anyway.

On 28 feb, 16:33, Alfonso <alfonso.ca...@gmail.com> wrote:
> I didn't know how to explain it in the subject but this is what I
> need to do with Cakephp, hope someone helps me.
>
> I have to tables/models lets say
>
> PARENTS
> id,name
> 1,joe
> 2,mary
> 3,mike
>
> SONS
> id,idparent,name
> 1,2,john
> 2,2,lisa
> 3,2,jack
> 4,3,martha
> 5,3,brad
>
> I want in a view to do this simple thing in a table, display the
> parent in a row, and then the following rows print the sons, then the
> next parent, and sons below and so on, maybe there is shorter way to
> do this than the ones that I've been thinking.
>
> example of final result in page:
>
> parent-mary
> son-john
> son-lisa
> son-jack
> parent-mike
> son-martha
> son-brad

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

Order 2 arrays in one view

I didn't know how to explain it in the subject but this is what I
need to do with Cakephp, hope someone helps me.

I have to tables/models lets say

PARENTS
id,name
1,joe
2,mary
3,mike


SONS
id,idparent,name
1,2,john
2,2,lisa
3,2,jack
4,3,martha
5,3,brad

I want in a view to do this simple thing in a table, display the
parent in a row, and then the following rows print the sons, then the
next parent, and sons below and so on, maybe there is shorter way to
do this than the ones that I've been thinking.

example of final result in page:

parent-mary
son-john
son-lisa
son-jack
parent-mike
son-martha
son-brad


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

Re: CakePHP 1.2.6 First Character Issue

Did you use saveAll()? I just came across the same issue. Luckily, I
remembered your post from a few days ago. Did you figure anything out?

My situation is that I have a Post model with an optional associated
Poll. I use $this->Post->saveAll() in the controller and, when I
checked the DB I saw this same corruption in my title & body fields.

mysql> select * from polls\G
*************************** 1. row ***************************
id: 1
created: 2010-02-28 15:10:39
modified: 2010-02-28 15:10:39
post_id: 0
active: 0
visible: 0
title: 2est
body: 2p>some other text</p>
1 row in set (0.00 sec)

The post_id did not get set, also.

In your case, the U suggested that this was related to the model name,
User. But this 2 is something else.

I changed the logic to use save() for my Post, then set $this-
>data['Poll']['post_id'] and used saveAll() for Poll (there are
associated PollChoices). The content looks fine.

I'm using 1.2.5. The Poll model has no behaviors.

On Feb 25, 1:32 pm, Andrew <and...@websitesthatdostuff.com> wrote:
> I'm working on retrieving a stack of data and for some reason some of
> the data gets corrupted. For instance, I've got some Post models that
> each are related to Comment models (hasMany), and each of the Comment
> models belongsTo a User. When retrieving the data, here's what I get
> from the database for the comments:
>
>         [Post] => Array
>         (
>         )
>
>         [Comments] => Array
>         (
>                 [0] => Array
>                         (
>                                 [content] => 2010 has definitely been a busy year!
>                                 [created] => 2010-02-10 13:47:15
>                                 [user_id] => 18
>                                 [post_id] => 1
>                                 [User] => Array
>                                         (
>                                                 [id] => U8
>                                                 [username] => Uace
>                                                 [first_name] => Uace
>                                         )
>
>                                 [_explicitType] => Comment
>                         )
>
>                 [0] => Array
>                         (
>                                 [content] => I can't wait...
>                                 [created] => 2009-12-10 13:57:36
>                                 [user_id] => 18
>                                 [post_id] => 1
>                                 [User] => Array
>                                         (
>                                                 [id] => U8
>                                                 [username] => Uace
>                                                 [first_name] => Uace
>                                         )
>
>                                 [_explicitType] => Comment
>                         )
>
>         )
>
> The first character of each of the Comments[i][User] arrays has been
> replaced with a capital U, though in each case it should be different
> (such as ID of 18, username of Jace, etc).
>
> I've checked the character encoding and found no issues. I have it set
> to UTF-8 in core.php, in database.php, and in the database itself. Any
> suggestions?

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

RE: Add to Cached data?

What I did was after the save read the array and for each push it back into
an array and add the newly saved data to the array and over-write the
original cache with original data plus the new record.

That worked best. But is there a way to actually just count the cache
records, add 1 to the count and simply insert the new set of data into the
original rather than looping thru it?

-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of John Andersen
Sent: February-28-10 6:44 AM
To: CakePHP
Subject: Re: Add to Cached data?

You should be able to read the cached data back, make you changes, and save
it in the cache again!
But it will not have been saved in the database, as you are not going
through the model!
Thus on the final change to the cached data, you will have to save the data
to your model, if you want it to persist longer than in just the current
session (correct me if I am wrong here!!).
Enjoy,
John

On Feb 28, 11:42 am, "Dave" <make.cake.b...@gmail.com> wrote:
> Is it possible to add to cached data for a user?
>
> User has a list of saved  "ads" for people selling / buying stuff
> classifieds type set up...then they bookmark a new "ad" can you add
> that data to the current cached data? Or you have to delete all and
> query all data again and save it?
>
> They can click "my ads" to view all the ones they saved but rather
> than running a query each time figure you could keep adding to the
> cache after each save rather than having to query ads they have saved over
and over.
>
> Thanks,
>
> Dave

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

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

Re: Missing Action

Have you copied/pasted the code directly from the controller into the
post?
If yes, then you have an error in your add function - this part is
missing a right-bracket!
[code]
$comments=$this->Comment->find(
'all',array(
'conditions'=>array(
'post_id'=>$this->data['Comment']['post_id']
),
'recursive'=>-1
);
[/code]

There should be one more bracket!!
Please correct me, should your code in the post not reflect the real
life code! :)
Enjoy,
John

On Feb 28, 7:08 pm, Chuck <chivalrys...@gmail.com> wrote:
> I'm working through a tutorial (Beginning CakePHP book) and am getting
> an error I don't understand. The error says "Error: The action vote is
> not defined in controller CommentsController" and "Error: Create
> CommentsController::vote() in file: app/controllers/
> comments_controller.php." However, this is what my app/controllers/
> comments_controller.php file looks like:
>
> <?
> class CommentsController extends AppController {
>         var $name = 'Comments';
>
>         function add() {
>                 if(!empty($this->data)){
>                         $this->Comment->create();
>                         if($this->Comment->save($this->data)) {
>                                 $comments=$this->Comment->find('all',array('conditions'=>array('post_id'=>$this->data['Comment']
>
> ['post_id']),'recursive'=>-1);
>                                 $this->set(compact('comments'));
>                                 $this->render('add_success','ajax');
>                         }else{
>                                 $this->render('add_failure','ajax');
>                         }
>                 }
>         }
>
>         function vote($type=null,$id=null) {
>                 if($id){
>                         $votes=$this->Comment->vote($type,$id);
>                         $this->set(compact('votes'));
>                         $this->render('votes','ajax');
>                 }
>         }}
>
> ?>
>
> I've confirmed that the add action works by loading /comments/add, so
> it's finding that action, why can't it find the vote action?
>
> The portion of the application that deals with this is in /app/views/
> posts/view.ctp, which looks like this:
>
> <?=$html->link('<h1>' . $post['Post']['name'] . '</h1>', '/posts/
> view/' . $post['Post']['id'],
>                null, null, false); ?>
> <p>Author: <?=$post['User']['firstname']; ?> <?=$post['User']
> ['lastname']; ?></p>
> <p>Date Published: <?=$time->nice($post['Post']['date']); ?></p>
> <hr />
> <p><?=$post['Post']['content']; ?></p>
> <hr />
> <h2>Comments</h2>
> <div id="comments">
>   <? foreach ( $comments as $comment ): ?>
>   <div class="comment">
>     <div id="vote_<?=$comment['Comment']['id']; ?>">
>       <div class="cast_vote">
>         <ul>
>         <?=$ajax->link( '<li>up</li>',
>                         '/comments/vote/up/' . $comment['Comment']
> ['id'],
>                         array( 'update' => 'vote_' .
> $comment['Comment']['id'] ), null, false ); ?>
>         <?=$ajax->link( '<li>up</li>',
>                         '/comments/vote/down/' . $comment['Comment']
> ['id'],
>                         array( 'update' => 'vote_' .
> $comment['Comment']['id'] ), null, false ); ?>
>         </ul>
>       </div>
>       <div class="vote"><?=$comment['Comment']['votes']; ?></div>
>     </div>
>     <p><b><?=$comment['Comment']['name']; ?></b></p>
>     <p><?=$comment['Comment']['content']; ?></p>
>   </div>
>   <? endforeach; ?>
>   <?=$ajax->form( array( 'type' => 'post',
>                          'options' => array( 'model' => 'Comment',
>                                              'update' => 'comments',
>                                              'url' =>
> array( 'controller' => 'comments',
>                                                              'action'
> => 'add' ) ) ) ); ?>
>   <?=$form->input( 'Comment.name' ); ?>
>   <?=$form->input( 'Comment.content' ); ?>
>   <?=$form->input( 'Comment.post_id', array( 'type' => 'hidden',
>                                              'value' => $post['Post']
> ['id'] ) ); ?>
>   <?=$form->end( 'Add Comment' ); ?>
> </div>
>
> Any help would be appreciated.
>
> Thanks,
> Chuck

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

Re: Getting distinct data from a psql function in a cake query

You can probably do it by using the fields option in the CakePHP find
method, see the book at:
http://book.cakephp.org/view/73/Retrieving-Your-Data

The first example show the fields option with DISTINCT. That should
help you a little on the way!

Have you considered denormalizing your table, so that you store not
only the date, but also two additional columns - year and month -
calculated from your date column.

That would make it easier for you to use CakePHP find to gather all
the years, and for each year, gather all the months.

See what you can with the fields option, then show us your resulting
code/problems :)
Enjoy,
John

On Feb 28, 5:21 pm, Bailey <baileys...@gmail.com> wrote:
> Hi all,
>
> Have a question surrounding cakephp database queries.
>
> I'm querying a psql database and the idea is I have a set of records
> with a date. I'm trying to provide a search option that allows you to
> select from a drop down lists on months and then a drop down list of
> years.
>
> In the drop down lists I only want to display a list of where a year
> is present in a record, and the same applies for months.
>
> So i have a record:
> ID=1,date="2010-02-01", data="blah blah blah";
> ID=2,date="2010-03-01", data="blah blah blah";
> ID=3,date="2017-04-01", data="blah blah blah";
> ID=1,date="2018-02-01", data="blah blah blah";
>
> So I want to produce two drop downlists that show:
>
> Years: 2010, 2017, 2018
>
> And when a year is selected: 2010=>(February, March), 2017=>(April)
> and 2018 =>(February).
>
> My query SQL is:
> SELECT DISTINCT extract(year from record_date) from table where
> user_id = 1;
>
> This works and brings up the exact list of years but it when I'd call
> the value from the drop downlist of years i would get the associated
> id and not the value... so i re-worked it like:
>
> $years = $this->Model->query('SELECT DISTINCT
>                         extract(year from record_date) AS "year" from table where user_id =
> '.$user1.';');
>
> $rYears = array();
>
> foreach ($dYears AS $dYear) {
>         $year= $dYear[0]['year'];
>         array_push($rYears ,array($dYear[0]['year']=>$year));}
>
> $this->set('years',$dutyYears);
>
> I can't quite model the 'DISTINCT extract(year from record_date)'
> which I think is causing me the problem when i try to use:
>
> $this->Model->findByuser_id($userID, 'DISTINCT extract(year from
> record_date'));
>
> Does anyknow know:
>
> a) how to switch from a query statement to a cake findBy statement? as
> i cant see if its possible to select a Distinct on the extract
> function... cake keeps trying to put: 'Duty.extract(year.....)';
>
> b) How i could build an options list for a form that works on the year
> with taking the months of each year... i've figured out the sql so far
> as:
>
> SELECT DISTINCT extract(month from record_date) from tablewhere
> extract(year from record_date) = YEAR AND user_id = 1;
>
> Many thanks for any help :-)

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

Re: ClassRegistry('init') more than once returns same Model id

In my opinion, there should only be one instance of the model! You
just have to use it to create many new records!

Use the models create method to ensure that each record is saved as a
new record. See the CakePHP book at:
http://book.cakephp.org/view/75/Saving-Your-Data

So, still in my opinion, you should change your code as follows:
[code]
$UserBadge = ClassRegistry::init('UserBadge');
foreach ($new_badges as $new_badge){
if ($new_badge){
$UserBadge->create();
$UserBadge->set('user_id', $check_in["User"]["id"]);
$UserBadge->set('check_in_id', $check_in["CheckIn"]["id"]);
$UserBadge->set('badge_id', $new_badge);
$UserBadge->save();
$awarded_badges[]=$UserBadge;
unset($UserBadge);
}
}
[/code]

But I may be wrong, that you are not just saving the records (badges)
but that you want to store the entire model in the $awarded_badges
array for every badge?? :)

Please enlighten me, enjoy,
John

On Feb 27, 6:12 pm, Greg Marra <greg.ma...@gmail.com> wrote:
> Hello,
>
> I have a site where I am using ClassRegistry('init') to create
> multiple new objects inside of a component. I want to save each one
> into the database. Unfortunately, it seems that each time I call
> ClassRegistry('init') I appear to get the same instance of the Model.
> The net result is that instead of having two or three objects in my
> database, it gets overwritten and overwritten and I end up with just
> the most-recently-saved one.
>
> Here is my code:
> foreach ($new_badges as $new_badge){
>                         if ($new_badge){
>                                 $UserBadge = ClassRegistry::init('UserBadge');
>                                 $UserBadge->set('user_id', $check_in["User"]["id"]);
>                                 $UserBadge->set('check_in_id', $check_in["CheckIn"]["id"]);
>                                 $UserBadge->set('badge_id', $new_badge);
>                                 $UserBadge->save();
>                                 $awarded_badges[]=$UserBadge;
>                                 unset($UserBadge);
>                         }
>                 }
>
> Any idea why this isn't working as expected?

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

Re: Auto create new entry in database wenn model is saved

Hi Alex,

What does your datamodel look like? Based on your information I assume
you have the following models and associations/relationships:

User hasOne/belongsTo Car
Car belongsTo/hasMany Carmodel
Car belongsTo/hasMany Attribute
Car belongsTo/hasMany Misc

That means that one User may have one Car.
Each Car may be described by Carmodel, Attribute and Misc.

Do I understand your situation correctly?
Enjoy,
John

On Feb 28, 7:42 pm, alex bailey <v...@planet-generals.de> wrote:
> Hi folks,
>
> I recently started using cakephp for one of my projects and I already
> really like it, now I have a problem which I worked on for a while but
> couldnt solve it yet...
>
> Lets say I have a User model and a user has a related table like Car:
>
> User 1 -- 1 Car
>
> Now by using a Form I want to save the user and the car to the
> database but now comes my problem:
>
> Car also has relations to 3 other tables which must be also created
> when a new car is created for example:
>
>                            1 Carmodel table
> User1 -- 1 Car -- 1Attribute table
>                            1 Misc table
>
> Is there a way I can also create those 3 related tables for car when I
> save User and Car?
>
> Thanks in advance
>
> regards
>
> Alex

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

Re: New to cake

Hi Jerry,

Good that you want to use CakePHP in your final year project.

Do you mean to use the students registration number as a tables
primary key - the id column?

If that is your intentions, I will recomend you not to do that!

A primary key is the one that identifies a record at the database
level and should have no meaning at all.

If you use the primary key to hold the students registration number,
then suddenly the primary key has meaning - which can lead to problems
in the future, when for example a student changes the registration
number (administration had given the student a wrong number) - and now
you have to change not only the primary key but also every foreign key
in related tables.

I suggest you use a different named column to hold the students
registration number - for example "registration_number".
Enjoy,
John

On Feb 28, 3:31 pm, jerry <opolots...@gmail.com> wrote:
> Hey am very new to cakephp and am using it for creating a hospital
> management system for a school as my final year project.i want to use
> the student registration numbers  as their ids but i have meet a
> problem.when i use the scaffold feature i don't seem to be seeing the
> id field input box.it's only showed while listing.How do i go about
> displaying a text box that i can use for manually entering the IDs.
>
> Thanks

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

Polls component for CakePHP

Hello, I'm looking for a Polls component to embed in my CakePHP
project. I was unable to find any except Easy Poll (http://
cakeforge.org/projects/easypoll/) which seems unsupported and
unreliable for now.

Is there a ready solution I can use or I should write my own?

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

Auto create new entry in database wenn model is saved

Hi folks,

I recently started using cakephp for one of my projects and I already
really like it, now I have a problem which I worked on for a while but
couldnt solve it yet...

Lets say I have a User model and a user has a related table like Car:

User 1 -- 1 Car

Now by using a Form I want to save the user and the car to the
database but now comes my problem:

Car also has relations to 3 other tables which must be also created
when a new car is created for example:

1 Carmodel table
User1 -- 1 Car -- 1Attribute table
1 Misc table

Is there a way I can also create those 3 related tables for car when I
save User and Car?

Thanks in advance

regards

Alex

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

Re: Missing Action

$this->Comment->vote is pointing to the vote action in the Comment model. If you want to call the vote action in the controller, use $this->vote instead.

Jeremy Burns


On 28 Feb 2010, at 17:08, Chuck wrote:

> I'm working through a tutorial (Beginning CakePHP book) and am getting
> an error I don't understand. The error says "Error: The action vote is
> not defined in controller CommentsController" and "Error: Create
> CommentsController::vote() in file: app/controllers/
> comments_controller.php." However, this is what my app/controllers/
> comments_controller.php file looks like:
>
> <?
> class CommentsController extends AppController {
> var $name = 'Comments';
>
> function add() {
> if(!empty($this->data)){
> $this->Comment->create();
> if($this->Comment->save($this->data)) {
> $comments=$this->Comment-
>> find('all',array('conditions'=>array('post_id'=>$this->data['Comment']
> ['post_id']),'recursive'=>-1);
> $this->set(compact('comments'));
> $this->render('add_success','ajax');
> }else{
> $this->render('add_failure','ajax');
> }
> }
> }
>
> function vote($type=null,$id=null) {
> if($id){
> $votes=$this->Comment->vote($type,$id);
> $this->set(compact('votes'));
> $this->render('votes','ajax');
> }
> }
> }
> ?>
>
> I've confirmed that the add action works by loading /comments/add, so
> it's finding that action, why can't it find the vote action?
>
> The portion of the application that deals with this is in /app/views/
> posts/view.ctp, which looks like this:
>
> <?=$html->link('<h1>' . $post['Post']['name'] . '</h1>', '/posts/
> view/' . $post['Post']['id'],
> null, null, false); ?>
> <p>Author: <?=$post['User']['firstname']; ?> <?=$post['User']
> ['lastname']; ?></p>
> <p>Date Published: <?=$time->nice($post['Post']['date']); ?></p>
> <hr />
> <p><?=$post['Post']['content']; ?></p>
> <hr />
> <h2>Comments</h2>
> <div id="comments">
> <? foreach ( $comments as $comment ): ?>
> <div class="comment">
> <div id="vote_<?=$comment['Comment']['id']; ?>">
> <div class="cast_vote">
> <ul>
> <?=$ajax->link( '<li>up</li>',
> '/comments/vote/up/' . $comment['Comment']
> ['id'],
> array( 'update' => 'vote_' .
> $comment['Comment']['id'] ), null, false ); ?>
> <?=$ajax->link( '<li>up</li>',
> '/comments/vote/down/' . $comment['Comment']
> ['id'],
> array( 'update' => 'vote_' .
> $comment['Comment']['id'] ), null, false ); ?>
> </ul>
> </div>
> <div class="vote"><?=$comment['Comment']['votes']; ?></div>
> </div>
> <p><b><?=$comment['Comment']['name']; ?></b></p>
> <p><?=$comment['Comment']['content']; ?></p>
> </div>
> <? endforeach; ?>
> <?=$ajax->form( array( 'type' => 'post',
> 'options' => array( 'model' => 'Comment',
> 'update' => 'comments',
> 'url' =>
> array( 'controller' => 'comments',
> 'action'
> => 'add' ) ) ) ); ?>
> <?=$form->input( 'Comment.name' ); ?>
> <?=$form->input( 'Comment.content' ); ?>
> <?=$form->input( 'Comment.post_id', array( 'type' => 'hidden',
> 'value' => $post['Post']
> ['id'] ) ); ?>
> <?=$form->end( 'Add Comment' ); ?>
> </div>
>
> Any help would be appreciated.
>
> Thanks,
> Chuck
>
> 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

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

Re: custom Validation - message not shown

According to the CakePHP book, your validation code looks correct!
But I am not familiar with version 1.3, so I hope that someone else
can assist you :)
Until then, good luck with finding the right solution,
John

On Feb 28, 6:56 pm, mivogt-LU <c...@mivogt.net> wrote:
> hmmm .... I created the view using the bake shell ; cake 1.3ß used to
> be most up-to-date ... so it is some 'original' code
> and as I wrote, if I use a built in validation the error message is
> shown....
>
> On 28 Feb., 17:48, John Andersen <j.andersen...@gmail.com> wrote:
>
> > Hmm I don't actually see anything wrong with your validation
> > definition and function. But I wonder about your view!! As far as the
> > CakePHP book states, you should use the FormHelper using the $form
> > object in the view! I have no idea whether that could be the reason,
> > but have you tried to conform to the CakePHP way, by using $form
> > instead of $this->Form ...?
>
> > If you try it, do tell!
> >    John
>
[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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Missing Action

I'm working through a tutorial (Beginning CakePHP book) and am getting
an error I don't understand. The error says "Error: The action vote is
not defined in controller CommentsController" and "Error: Create
CommentsController::vote() in file: app/controllers/
comments_controller.php." However, this is what my app/controllers/
comments_controller.php file looks like:

<?
class CommentsController extends AppController {
var $name = 'Comments';

function add() {
if(!empty($this->data)){
$this->Comment->create();
if($this->Comment->save($this->data)) {
$comments=$this->Comment-
>find('all',array('conditions'=>array('post_id'=>$this->data['Comment']
['post_id']),'recursive'=>-1);
$this->set(compact('comments'));
$this->render('add_success','ajax');
}else{
$this->render('add_failure','ajax');
}
}
}

function vote($type=null,$id=null) {
if($id){
$votes=$this->Comment->vote($type,$id);
$this->set(compact('votes'));
$this->render('votes','ajax');
}
}
}
?>

I've confirmed that the add action works by loading /comments/add, so
it's finding that action, why can't it find the vote action?

The portion of the application that deals with this is in /app/views/
posts/view.ctp, which looks like this:

<?=$html->link('<h1>' . $post['Post']['name'] . '</h1>', '/posts/
view/' . $post['Post']['id'],
null, null, false); ?>
<p>Author: <?=$post['User']['firstname']; ?> <?=$post['User']
['lastname']; ?></p>
<p>Date Published: <?=$time->nice($post['Post']['date']); ?></p>
<hr />
<p><?=$post['Post']['content']; ?></p>
<hr />
<h2>Comments</h2>
<div id="comments">
<? foreach ( $comments as $comment ): ?>
<div class="comment">
<div id="vote_<?=$comment['Comment']['id']; ?>">
<div class="cast_vote">
<ul>
<?=$ajax->link( '<li>up</li>',
'/comments/vote/up/' . $comment['Comment']
['id'],
array( 'update' => 'vote_' .
$comment['Comment']['id'] ), null, false ); ?>
<?=$ajax->link( '<li>up</li>',
'/comments/vote/down/' . $comment['Comment']
['id'],
array( 'update' => 'vote_' .
$comment['Comment']['id'] ), null, false ); ?>
</ul>
</div>
<div class="vote"><?=$comment['Comment']['votes']; ?></div>
</div>
<p><b><?=$comment['Comment']['name']; ?></b></p>
<p><?=$comment['Comment']['content']; ?></p>
</div>
<? endforeach; ?>
<?=$ajax->form( array( 'type' => 'post',
'options' => array( 'model' => 'Comment',
'update' => 'comments',
'url' =>
array( 'controller' => 'comments',
'action'
=> 'add' ) ) ) ); ?>
<?=$form->input( 'Comment.name' ); ?>
<?=$form->input( 'Comment.content' ); ?>
<?=$form->input( 'Comment.post_id', array( 'type' => 'hidden',
'value' => $post['Post']
['id'] ) ); ?>
<?=$form->end( 'Add Comment' ); ?>
</div>

Any help would be appreciated.

Thanks,
Chuck

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

Re: custom Validation - message not shown

hmmm .... I created the view using the bake shell ; cake 1.3ß used to
be most up-to-date ... so it is some 'original' code
and as I wrote, if I use a built in validation the error message is
shown....

On 28 Feb., 17:48, John Andersen <j.andersen...@gmail.com> wrote:
> Hmm I don't actually see anything wrong with your validation
> definition and function. But I wonder about your view!! As far as the
> CakePHP book states, you should use the FormHelper using the $form
> object in the view! I have no idea whether that could be the reason,
> but have you tried to conform to the CakePHP way, by using $form
> instead of $this->Form ...?
>
> If you try it, do tell!
>    John
>
> On Feb 28, 6:29 pm, mivogt-LU <c...@mivogt.net> wrote:
>
> > Hi John,
>
> > I had a lokoup to the view code in the browser ... the message is not
> > contained in html code
>
> > some of the model code:
> > <?php
> > class BookingPosition extends AppModel {
> >         var $name = 'BookingPosition';
> >         var $displayField = 'id';
> >         //The Associations below have been created with all possible keys,
> > those that are not needed can be removed
>
> > //  var $validate = array(  'Lodging' => array(  'rule' =>
> > array('limitBelegung', 2, 99,99,99),  'message' => 'Das Zimmer ist
> > überbucht!!' ) );
> > //  var $validate  =array('Lodging' => array ('limitBelegung' =>
> > array('rule'=>'limitBelegung', 'message'=>'naja')));
>
> > //$a=debug($data);
>
> > var $validate=array
> > (
> > 'AnzahlErwachsene' =>        array('rule'=>'limitPersonen','message'=>'das
> > sind zu viele für das Bett'),
> > 'AnzahlJugendliche' =>       array('rule'=>'limitPersonen','message'=>'das
> > sind zu viele für das Bett'),
> > 'AnzahlKinder' =>            array('rule'=>'limitPersonen','message'=>'das sind
> > zu viele für das Bett')
> > );
>
> > .... ... ....
>
> >  function limitPersonen()
> >   {
> >         $E = $this->data['BookingPosition']['AnzahlErwachsene'];
> >         $J = $this->data['BookingPosition']['AnzahlJugendliche'];
> >         $K = $this->data['BookingPosition']['AnzahlKinder'];
>
> >        // $A = $this->query("SELECT Bettenanzahl FROM Lodgings WHERE
> > id=" . $this->data['BookingPosition']['lodging_id'] );
> >        // $max = (int)$A[0]['Lodgings']['Bettenanzahl'];
> >        // $numberOfBeds =(int)$max;
>
> >                 $Y1=$this->Lodging->find('first',array('conditions'=>array('Lodging.id'=>$this-
> > >data['BookingPosition']['lodging_id'])));
>
> >                 //debug($Y1);
> >         $numberOfBeds   =(int)$Y1['Lodging']['Bettenanzahl'];
>
> >                 echo $numberOfBeds      ;
>
> >         $X = (int)$E + (int)$J + (int)$K;
> >        return ((int)$X <= $numberOfBeds) ; //($AnzE + $AnzJ + $AnzK)<
> > $maxAnz;
> >   }
> > .... .... ....
> > and the view code for add is like this:
> > <div class="bookingPositions form">
> > <?php echo $this->Form->create('BookingPosition');?>
> >         <fieldset>
> >                 <legend><?php printf(__('Add %s', true), __('Booking Position',
> > true)); ?></legend>
> >         <?php
> >                 echo $this->Form->input('booking_id');
> >                 echo $this->Form->input('AnreiseDatum');
> >                 echo $this->Form->input('AbreiseDatum');
> >                 echo $this->Form->input('bookingstatus_id');
> >                 echo $this->Form->input('lodging_id');
> >                  // debug($this->data);
> >                 echo $this->Form->input('meal_id');
> >                 echo $this->Form->input('room_id');
> >                 echo $this->Form->input('material_id');
> >                 echo $this->Form->input('AnzahlErwachsene');
> >                 echo $this->Form->input('AnzahlJugendliche');
> >                 echo $this->Form->input('AnzahlKinder');
> >         ?>
> >         </fieldset>
> > <?php echo $this->Form->end(__('Submit', true));?>
> > </div>
>
> > so I have no idea why my message is not shown, but if i use a built in
> > one like requiered/notempty the message is shown.
>
> > Any hint so far?
>
> > TIA
>
> > Michael
>
> > On 28 Feb., 09:20, John Andersen <j.andersen...@gmail.com> wrote:
>
> > > Try to look at the source in the browser, maybe your CSS has limited
> > > the height of the DIV so that you message is not shown below the INPUT
> > > field!
>
> > > If that is not the case, please show your code for the view in which
> > > the errors should be displayed!
> > > Enjoy,
> > >    John
>
> > > On Feb 28, 12:51 am, mivogt-LU <c...@mivogt.net> wrote:
>
> > > > [cake 1.3ß | XAMPP 1.7.3|PHP 5.3.1|MySQL 5.1.41 | Win XP SP3]
>
> > > > Hi everybody,
>
> > > > I just has a little problem with my error-message in a custom
> > > > validation function.
> > > > If I use the built in functions like required the message is shown so
> > > > css and div seem to be ok
> > > > If I use my own function there is a red bar below the validated field
> > > > but no error message below it.
>
> > > > I call the validation like this:
> > > > var $validate=array
> > > > (
> > > > 'AnzahlErwachsene' =>        array('rule'=>'limitPersonen','message'=>'das
> > > > sind zu viele für das Bett'),
> > > > 'AnzahlJugendliche' =>       array('rule'=>'limitPersonen','message'=>'das
> > > > sind zu viele für das Bett'),
> > > > 'AnzahlKinder' =>            array('rule'=>'limitPersonen','message'=>'das sind
> > > > zu viele für das Bett')
> > > > );
>
> > > > The function itselfe just returns a true or false depending on a
> > > > numerical checkup.
> > > > The funciton works fine so far - but I miss my message (see above)
>
> > > > Is there someone who might tell me why I miss the message text?
>
> > > > Thanks in advance
>
> > > > Michael
>
> > > > [cake 1.3ß | XAMPP 1.7.3|PHP 5.3.1|MySQL 5.1.41 | Win XP SP3]

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