Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthordanfrost
    • CommentTimeAug 22nd 2007
     

    HI,

    I want to talk about calling classes in template.

    I would like to call: Ak::t('this is a label')

    from the template. From looking around just now, I can see that AkPhpCodeSanatizer (which uses /vendor/PHPCodeAnalyzer/PHPCodeAnalyzer.php) prevents any classes being used statically.

    Would it be sensible to allow some classes to be called statically? For example: - label helpers - html helpers ??

    I see that these could do into $.._helper, but I would like to be able to copy and paste from any file more easily. Also, label helpers should work the same across the system.

    What do you think?

    dan

    • CommentAuthorsalavert
    • CommentTimeAug 22nd 2007
     

    Create at your current controller/action an instance of your helper or model

    require_once(path to your helper);
    $this->html_helper =& new HtmlHelper();
    

    and will be available into yor view

    $html_helper->yourMethod();
    

    there is no need for changes.

    •  
      CommentAuthorbermi
    • CommentTimeAug 22nd 2007
     

    Hi Dan, Just read your article on LF. Thank you very much for digging into Akelos before the screencast and the new site was up and running.

    For security reasons Akelos does not allow running static methods in the views by default, some work can be done around lib/AkActionView/AkPhpCodeSanitizer.php (130, 132) to modify the default behavior using a configuration constant.

    You can also have a look to the new way to call helpers from within sintags which might shorten helper calls.

    As salavert suggests you can also instantiate helpers from your controller and there is a simple mode to get this automatically for you by telling Akelos wich app/helpers to load using the "var $app_helpers"

    If all you needed was to call Ak::t('this is a label') you have these five ways of doing it so:

    _{this is a label}
    <%= _('this is a label') %>
    <%= translate 'this is a label' %>
    <?= $text_helper->t('this is a label') ?>
    <?= translate('this is a label') ?>
    
    • CommentAuthordanfrost
    • CommentTimeAug 23rd 2007
     

    Thanks - I will stick to the rules and use a proper helper!

    Cheers, dan

Add your comments
    Username Password
  • Format comments as