Hello,

Assuming you have a newsletter Controller and a newsletter Model :
in NewsletterController (newsletter_controller.php) :

class NewsletterController extends AppController {
    var name = 'Newsletter';

   function archive_list(){
       $this->set('archives', $this->Newsletter->find('all',
array("Newsletter.publish_date" => "< NOW()"))
   }
}
In your archive list view (archive_list.ctp), you'll be able to
iterable over your archives through $archives.

or .. in your controller above, (assuming its not the
NewsletterController) just do :

 var uses = array('Newsletter');

function archive_list(){
        $this->set('archives', $this->Newsletter->getArchives());
}

in the Newsletter model, create a method for your archive list :

function getArchives(){
        $sql = 'SELECT id, to_char(publish_date, \'Mon, YYYY\') AS
month FROM newsletter '  . 'WHERE publish_date < NOW() ORDER BY
publish_date DESC';
        return $this->query($sql);
}

.. or simply correct the typo $this->Newsletter instead of $this-
>newsletter.


On Dec 23, 4:09 am, subtropolis <[EMAIL PROTECTED]> wrote:
> I'm a n00b here and have been redoing an existing site in order to
> learn the Cake way. I'm jumping straight into the 1.2 branch.This is
> my first cry for help.
>
> I have a section for an online newsletter. Several pages list links
> for the archived issues. From what i've read, i should use an element
> for this. I've created the file newsletter_archive_list.ctp in the
> elements dir with the following:
>
> $archive_list = $this->requestAction('newsletter/archive_list');
>
> // followed by markup to list the links
>
> The controller's archive_list method is simply:
>
>     function archive_list()
>     {
>         $sql = 'SELECT id, to_char(publish_date, \'Mon, YYYY\') AS
> month FROM newsletter '
>             . 'WHERE publish_date < NOW() ORDER BY publish_date DESC';
>
>         return $this->newsletter->query($sql);
>     }
>
> The thing is, as i understand it, it's better to place as much code in
> the model, rather than the controller (which seems quite sensible).
> However, i haven't been able to figure out how to then call the
> function from the model.
>
> With the method in the controller, i get this error:
>
> Undefined property:  NewsletterController::$newsletter [APP/
> controllers/newsletter_controller.php, line 25]
>
> My head is spinning. The manuals are really not very clear on this. I
> understood that the model ($newsletter) was available anywhere inside
> the controller. Can someone please point me in the right direction?
>
> (extra points for explaining how the new cache system, would work
> here :-)

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

Reply via email to