two things..

1. If the view can see it, so can the element
2. if this is an element you are going to use all over the place
(multiple controllers) you might as well just add the helper to
app_controller class.

On Jan 7, 4:22 pm, DrLaban <[EMAIL PROTECTED]> wrote:
> Hello all!
>
> I've been doing some Cake'ing for a while and find it lots of fun to
> work with seeing that it's quite fast and has a lot going for it so
> far.
> I'm having a bit of a headache with elements and helpers though, I've
> seen some notions about it but never quite figured it out so I thought
> I'd give this a shot to see if anyone can help me clear things up.
>
> What I'm trying to accomplish is quite simple; I have a sidebar to the
> left of my page where I'd like to add/edit/delete small notices (one
> short caption along with a short string of text).
> I've managed to make the entire site working insofar that every
> section on the page with editing capabilites does what it should. I
> can add/edit/delete users, add/edit/delete quotations, and so forth.
> The sidebar is stationary on the leftside of the page at all times and
> I haven't figured out a better or nicer way of adding this sidebar's
> contents other than an element, but here's where the troubles start;
> I've been trying for a few hours to sort this thing out but I can't
> make one of my helpers accessible to the element.
> From what I've read here on the group it could be that it's not
> possible by design, but the answers have been a bit vague, so I'm not
> really sure of what to do. Here's the principle layout in wordings
> (I've copied the files contents to the bottom of this post);
>
> The following exists; Model -> Controller -> View (layout). The view
> uses renderElement() to invoke the element. The element contains a
> helper function call. The Controller has $helpers=[myHelper] defined.
> Problem: The helper isn't availbable in the Element.
>
> This is my file structure containing just the necessary (I think)
> information about my element and helper (btw, I'm not Cake-savvy in
> the least so there might be horrible errors or flaws, but I've also
> omitted alot of code to keep things a little less bloated);
>
> -----[Model: notice.php]-----
> class Notice extends AppModel {
>   var $name = 'Notice';
>
> }
>
> -----[Controller: notices_controller.php]-----
> class NoticesController extends AppController {
>   var $name = 'Notices';
>   var $components = array('mysql');
>   var $helpers = array('Tools');
>
>   function index() {
>     $notices = $this->Notice->findAll();
>     if(isset($this->params['requested'])) {
>       return $notices;
>     }
>     $this->set('notices', $notices);
>   }
>
>   function add() {
>     if(!empty($this->data)) {
>       if($this->Notice->save($this->data)) {
>         $this->flash('Notice added!', '/');
>       }
>     }
>   }
>
>   function edit($id = null) {
>     if(empty($this->data)) {
>       $this->Notice->id = $id;
>       $this->data = $this->Notice->read();
>       $this->set('notice', $this->Notice->read());
>     } else {
>       if($this->Notice->save($this->data['Notice'])) {
>       $this->flash('Notice updated!', '/');
>     }
>   }
>
> }
>
> -----[View: default.thtml]-----
> <?php echo $this->renderElement('notices'); ?>
>
> --[Element: notices.thtml]--
> <?php $notices = $this->requestAction('notices/index'); ?>
> <?php foreach($notices as $notice): ?>
>     <div class="shortcaption"><?php echo $notice['Notice']
> ['caption']; ?></div>
>     <div class="shortmessage"><?php echo $notice['Notice']['text']; ?></div>
>
>     <?php echo $tools->getNoticesEdit($id); ?>
> <?php endforeach; ?>
>
> -----[Helper: tools.php]-----
> var $helpers = array('Html');
>
> function getNoticesEdit($id) {
>   {conditional statements, etc, etc}
>   $return = somestring;
>   return $return;
>
> }
--~--~---------~--~----~------------~-------~--~----~
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