Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorsuthern
     

    In my controller I have two methods of saving data. One is through AJAX, and looks like this

    function ajax_add()
    {
        if(!empty($this->params['multiplier'])){
            $this->Multiplier->setAttributes($this->params['multiplier']);
            if ($this->Request->isPost() && $this->Multiplier->save()){
                $this->Person->setAttributes($_SESSION['user']);
                $this->alert_on_create();
                $this->renderWithALayout(array('partial'=>'existing_line'));
            } else {
                $this->renderText("<tr><td>Sorry, save did not complete. Try again.</td></tr>");
            }
        }
    }
    

    The only things you need to note is the 'alert_on_create' and then 'renderWithALayout'. The other way I save data in a regular ADD method is this

    function add()
    {
        $this->Person->setAttributes($_SESSION['user']);
        if(!empty($this->params['multiplier'])){
            $this->Multiplier->setAttributes($this->params['multiplier']);
            if ($this->Request->isPost() && $this->Multiplier->save()){
                $this->flash['notice'] = $this->t('Multiplier was successfully created.');
                $this->alert_on_create();
                $this->redirectTo(array('action' => 'show', 'id' => $this->Multiplier->getId()));
            }
        }
    }
    

    And here are the emailing functions (contained within the controller)

    function send_alert_email($type,$old_multiplier=null,$priority=null)
    {   // Email the alert email
        $this->Multiplier->vendor->load();
        $this->Multiplier->manufacturer->load();
    
        Ak::import_mailer('notifier'); 
        $Notifier =& new Notifier();
        $Notifier->deliver($type,array(
            'multiplier' => $this->Multiplier, 
            'person' => $this->Person,
            'old_multiplier' => $old_multiplier));
    }
    
    function alert_on_create()
    {   // we will create a NEW multiplier email, then email it.
        $this->send_alert_email('multiplier_added');
    }
    

    When doing a regular ADD, everything works fine, no errors. When doing an AJAX_ADD, the result which comes back is

    (User Error) Could not compile /web/apps/dmr/app/views/multiplier/_existing_line.tpl Could not find a helper to handle the method "multiplier_line" you called in your view....(with a bunch of backtrace stuff following it)
    

    Which is odd, because the ajax_add functions returns normally if I comment out $this->alert_on_create();. (the _existing_line.tpl works normally)

    Does anyone have an idea why the alert_on_create function somehow makes renderWithALayout confused? Somehow I am confusing akelos into looking at the wrong helper file.

    •  
      CommentAuthorbermi
     

    You're calling Calling renderWithALayout before helpers are loaded.

    You might load helpers by calling

    $this->instantiateHelpers()
    

    and perhaps just call

    $this->render(array('partial'=>'existing_line'));
    
    • CommentAuthorsuthern
     

    Thanks for your help! The solution was to insert the line

    $this->instantiateHelpers();
    

    just before the renderWithALayout call.

    Could this be a bug? The only thing that triggered the failure of the helpers in renderWithALayout, was firing off a notifier (which uses it's own helpers) just before the renderWithALayout.