Model associations causing problems in behaviors

2010-02-15 Thread DanCake
I have two associated models, Series (hasMany) and SeriesTitle
(belongsTo) each use the Searchable behavior.

While the association is active and I try to save to the SeriesTItle
model, all behaviors break as for some reason $this->model contains
the Series model rather than the SeriesTitle.
This only affects SeriesTitle and removing the association fixes the
problem.

Errors:

Notice: Undefined index: Series in D:...\app\models\behaviors
\searchable.php on line 80
Warning: Invalid argument supplied for foreach() in D:...\app\models
\behaviorssearchable.php on line 81

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Limiting find('threaded')

2010-01-24 Thread DanCake
What is the best way to limit find('threaded') by parent_id so
children aren't limited?

The following returns 4 parents and 6 children, so many children are
missing
$this->Comment->find('threaded', array('conditions' => array
('Comment.post_id' => 1), 'limit' => '0, 10'));

Is there any way to get 10 parents and all their children instead?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Revision system - Help improve my code

2009-10-09 Thread DanCake

Here it is on pastebin as it's fairly awkward to read. 
http://pastebin.com/m6e44f0b
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Revision system - Help improve my code

2009-10-09 Thread DanCake

A section of a site I am building needs a revision system and so
decided to keep it simple, similar to the one on stack overflow.

I quickly created the following which works although looks a little
messy. I know I can use beforeSave and afterSave but I have no idea
how I could implement it.

data))) {
$this->Session->setFlash('That Series does not exist', 
true, array
('class' => 'error'));
$this->redirect('/');
}

$revisions = $this->Revision->find('all', array('conditions' => 
array
('Revision.series_id' => $seriesId), 'order' => 'revision desc',
'contain' => false));
$this->set('revisions', $revisions);
}

/**
 * Create a new revision by editing the most recent one.
 * This seems very messy.
 */
function edit($seriesId = null) {
if ((!$seriesId && empty($this->data))) {
$this->Session->setFlash('That Series does not exist', 
true, array
('class' => 'error'));
$this->redirect('/');
}

if (empty($this->data)) {
$latest = $this->Revision->find('first', 
array('conditions' => array
('is_latest' => 1, 'series_id' => $seriesId)));
$this->data['Revision']['description'] = 
$latest['Revision']
['description'];
} else {
$this->data['Revision']['revision'] = 
$this->Revision->getNext
($seriesId);
$this->data['Revision']['series_id'] = $seriesId;
$this->Revision->create();
if ($this->Revision->save($this->data)) {
$this->Revision->setLatest($this->Revision->id, 
$seriesId);

$this->Session->setFlash('The edit has been 
saved.', true, array
('class' => 'success'));
$this->redirect(array('controller' => 'series', 
'action' =>
'view', $seriesId));
}
}

$this->set('seriesId', $seriesId);
}



/**
 * Creates a new revision using data from a previous one.
 * Currently clones the previous revision rather than
 * just referencing it. Will need to be changed.
 */
function rollback($seriesId = null, $revision = null) {
if (!$seriesId || !$revision) {
$this->redirect('/');
}

$this->data = $this->Revision->find('first', array
('conditions' => array('Revision.series_id' => $seriesId,
'Revision.revision' => $revision), 'contain' => false));

$this->data['Revision']['revision'] = $this->Revision->getNext
($seriesId);
$this->data['Revision']['is_rollback'] = 1;
$this->data['Revision']['rollback_rev'] = $revision;
unset($this->data['Revision']['id']);
$this->Revision->create();
if ($this->Revision->save($this->data)) {
$this->Revision->setLatest($this->Revision->id, 
$seriesId);

$this->Session->setFlash('The rollback has been 
saved.', true, array
('class' => 'success'));
$this->redirect(array('controller' => 'series', 
'action' => 'view',
$seriesId));
}
}

}
?>

 array('counterCache' => true));
var $actsAs = array('Containable');

function getCurrent($seriesId = null) {
if(!$seriesId) return false;

$series = $this->Series->find('first', array('conditions' => 
array
('Series.id' => $seriesId), 'contain' => false));
return $series['Series']['revision_count'];
}

function getNext($seriesId = null) {
if(!$seriesId) return false;

$revision = $this->getCurrent($seriesId);
return $revision + 1;
}

function setLatest($id, $seriesId = null) {
$this->updateAll(array('Revision.is_latest' => 0), array
('Revision.series_id' => $seriesId));

$this->id = $id;
$this->saveField('is_latest', 1);
}

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



Re: A few questions from a CakePHP newbie

2009-06-24 Thread DanCake

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



A few questions from a CakePHP newbie

2009-06-23 Thread DanCake

I've been experimenting with CakePHP for a few weeks now and I love
it. At the moment, I'm porting one of my current sites and not only
have I completed all of the basic features, I've also added a few more
which would've taken me much longer to complete.

I'm currently using the AutoLogin component (http://www.milesj.me/
resources/script/auto-login-component) which works great. If the
session expires and the user clicks on a link, they are automatically
logged back in although they are automatically redirected to whatever
is specified in Auth->loginRedirect. Is there anyway to redirect them
to the same place they were attempting to go to?

I also need to create something similar to http://www.animesuki.com/series.php
where there are a list of links each grouped by letter. I have
http://pastebin.com/m40dc6a3b which I created over a year ago and is
fairly basic but works well. Is there a better way to do this in cake?

Thanks for your time
Daniel

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