Menu

Struts-PHP + smarty

Help
Edgar
2005-02-07
2013-04-08
  • Edgar

    Edgar - 2005-02-07

    Como fao para ler variaveis no escopo PHP junto com variaveis do escopo SMARTY?

     
    • Tim Wagner

      Tim Wagner - 2005-02-24

      Sorry, but dont speak spanish. Write your message in english please.

      Thank you
      Tim

       
    • Edgar

      Edgar - 2005-03-12

      OK!

      Excuse me. I dont write very well.

      How can I do to read variables of php escope with variables into SMARTY escope? Mix.

      Thanks!

       
    • Anonymous

      Anonymous - 2005-03-12

      I don't know whether I have understood you correctly. Here one small example.

      struts4php ActionForm:
      <?PHP

      class PersSettings extends ActionForm {

          var $eMail;

          public function &geteMail() {
              return $this->eMail;
          }

          public function seteMail($eMail) {
              $this->eMail = $eMail;
          }

          public function reset( $actionMapping ) {
              $this->eMail = null;
          }

          public function validate( $actionMapping, &$request ) {}
      }

      ?>

      smarty form:
      {struts4php field='eMail'}
      or
      {struts4php field='eMail' assign='email'} to assign it to smarty's variable {$email}

      here the smarty plugin:
      <?PHP

      /*
      * Smarty plugin
      * -------------------------------------------------------------
      * File:     function.struts4php.php
      * Type:     function
      * Name:     struts4php
      * Purpose:  return the field's value
      * -------------------------------------------------------------
      */
      function smarty_function_struts4php($params, &$smarty)
      {
          global $request, $actionBanana;

          $field = $params['field'];
          $method = 'get%s';
          $method = sprintf($method, $field);

          $actionMapping = $actionBanana->findMapping($request->getAttribute(PATH));
          $actionForm = $request->getAttribute($actionMapping->getName());

          if (array_key_exists('assign', $params) and $params['assign']) {
              // we are assigning the data here
              $smarty->assign($params['assign'], $actionForm->$method());
          } else {
              // there was no assignment request, so return it raw
              return $actionForm->$method();
          }
      }

      ?>

      ralph

       

Log in to post a comment.

Monday.com Logo