Re: How to set the incoming $id to be the last post entered

2012-04-11 Thread PaulW
Well that's exactly what I thought (and had actually tried) but when I
added that I got an error message appearing at the top of my view if I
visit the URL without an id...

Then it struck me that $id = $this->Post->find('first', array('order'
=> array('Post.id DESC'))); is returning an array not just the id!

I changed my 'if' to be...

if (empty($id)) {
$latestid = $this->Post->find('first', array('order' =>
array('Post.id DESC')));
$id = $latestid['Post']['id'];
}

...and now it works.

Cheers for the help

PW

On Apr 11, 12:22 am, CrotchFrog  wrote:
> I would think to just put it in an "if" construct and execute the statement
> if the expression evaluates to true, no?
>
> function mypage($id = null) {
>      if (empty($id)){
>           $id = $this->Post->find('first', array('order' => array('Post.id
> DESC')));
>      }
>         $this->Post->recursive = 0;
>         $this->set('posts', $this->paginate());
>         $this->set('mainpost', $this->Post->read(null, $id));
>
> }
>
> HTH,
> ED
>
>
>
>
>
>
>
> On Tuesday, April 10, 2012 6:35:54 PM UTC-4, PaulW wrote:
>
> > Hi
>
> > I'm on CakePHP 1.3
>
> > I have an action in my posts_controller.php that gets a list of latest
> > posts and the data for a particular post if the $id is set...
>
> > function mypage($id = null) {
> >         $this->Post->recursive = 0;
> >         $this->set('posts', $this->paginate());
> >         $this->set('mainpost', $this->Post->read(null, $id));
> > }
>
> > I then use this to display a column or recent posts and the main post if
> > an $id is supplied.
>
> > What I would like to do is set the incoming $id to be the last post
> > entered if a specific $id isn't already set in the URL. ie: run this code
> > if $id is null...
>
> >         $id = $this->Post->find('first', array('order' => array('Post.id
> > DESC')));
>
> > But I'm not sure how to combine these two bits of code together in one
> > function. Assuming that 's the right way to go about what I'm trying to
> > achieve?
>
> > PW

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: How to set the incoming $id to be the last post entered

2012-04-10 Thread CrotchFrog
I would think to just put it in an "if" construct and execute the statement 
if the expression evaluates to true, no?

function mypage($id = null) {
 if (empty($id)){
  $id = $this->Post->find('first', array('order' => array('Post.id 
DESC')));
 }
$this->Post->recursive = 0;
$this->set('posts', $this->paginate());
$this->set('mainpost', $this->Post->read(null, $id));
} 

HTH, 
ED 

On Tuesday, April 10, 2012 6:35:54 PM UTC-4, PaulW wrote:
>
> Hi
>
> I'm on CakePHP 1.3
>
> I have an action in my posts_controller.php that gets a list of latest 
> posts and the data for a particular post if the $id is set...
>
> function mypage($id = null) {
> $this->Post->recursive = 0;
> $this->set('posts', $this->paginate());
> $this->set('mainpost', $this->Post->read(null, $id));
> }
>
> I then use this to display a column or recent posts and the main post if 
> an $id is supplied.
>
> What I would like to do is set the incoming $id to be the last post 
> entered if a specific $id isn't already set in the URL. ie: run this code 
> if $id is null...
>
> $id = $this->Post->find('first', array('order' => array('Post.id 
> DESC')));
>
> But I'm not sure how to combine these two bits of code together in one 
> function. Assuming that 's the right way to go about what I'm trying to 
> achieve?
>
> PW
>
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


How to set the incoming $id to be the last post entered

2012-04-10 Thread Paul Willis
Hi

I'm on CakePHP 1.3

I have an action in my posts_controller.php that gets a list of latest posts 
and the data for a particular post if the $id is set...

function mypage($id = null) {
$this->Post->recursive = 0;
$this->set('posts', $this->paginate());
$this->set('mainpost', $this->Post->read(null, $id));
}

I then use this to display a column or recent posts and the main post if an $id 
is supplied.

What I would like to do is set the incoming $id to be the last post entered if 
a specific $id isn't already set in the URL. ie: run this code if $id is null...

$id = $this->Post->find('first', array('order' => array('Post.id 
DESC')));

But I'm not sure how to combine these two bits of code together in one 
function. Assuming that 's the right way to go about what I'm trying to achieve?

PW

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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