Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Parser
  • Hi! I am trying to use Smarty through Parser package. I copied /packages/parser/config/parser.php to /app/config/parser.php and edited it, but the modifications are not used. If I modify the original file it works. Any idea why? Thanks!
  • mmmmmm ... it works for me ( I've tried to enable the caching ). Which configurations have you tried?
  • Are these issues ready for bug tracker? I don't want to post them there because I am just learning... so it could be my fault. I would appreciate some comments. I found two other things: 2) Smarty "section" only works with arrays that are sequential (keys: 0, 1, ...). Orm\Model::find('all') however doesn't return such arrays.
    For instance:
    class Controller_Post extends Controller_Template {
     public function action_index()
     {
      $this->template->content = View::factory('posts/index.smarty', array(
                      'posts'=>Model_Post::find('all'), // doesn't work!
                      //'posts'=>array_values(Model_Post::find('all')), // works ok.
                    ));
     }
    }
    
    // Smarty code:
      {section name=i loop=$posts}
        {$posts[i]->title}
      {/section}
    

    I can of course subclass Orm\Model, but would rather see it solved upstream. Is such fix sensible or is there a reason for keys that don't start with 0? (are they IDs?) 2) I had 1.0.1 at first and used scaffolding to create form "posts". I added a few records with titles "test<b>123</b>" for instance. Output filtering worked and it was displayed with < (correct).
    Then I upgraded to latest dev version and copied app/ over. However, now the titles display partially bold even though output filtering should be used!
    (Note: I am not using Smarty templates here, just normal views) I am still learning and it's difficult for me to tell what is a bug and what not... I would appreciate some hints.
  • Davide Bellini wrote on Thursday 8th of September 2011:
    Which configurations have you tried?
    I tried setting left and right delimiters (I prefer '{{' and '}}' so it doesn't interfere with JavaScript functions). This is my app/config/parser.php:
    return array(
     'extensions' => array(
      'php'       => 'View',
    //  'smarty'    => 'View_Smarty', // we want .tpl, not .smarty
      'tpl'      => array('class' => 'View_Smarty', 'extension' => 'tpl'),
     ),
     'View_Smarty'   => array(
      'include'       => APPPATH.'vendor'.DS.'Smarty'.DS.'libs'.DS.'Smarty.class.php',
      'delimiters'    => array('{{', '}}'),
      'environment'   => array(
       'compile_dir'       => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS,
       'config_dir'        => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS,
       'cache_dir'         => APPPATH.'cache'.DS.'Smarty'.DS,
       'caching'           => false,
       'cache_lifetime'    => 0,
       'force_compile'     => true, // debug!
       'compile_check'     => true,
       'debugging'         => false,
       'autoload_filters'  => array(),
       'default_modifiers' => array(),
      ),
     ),
    );
    

    The delimiters are ignored in above example. If I change them in packages/parser/config/parser.php however, they are used.
  • Found the bug:
    // packages/parser/config/parser.php:
      'delimiters'    => array('{%', '%}'),
    
    // app/config/parser.php
      'delimiters'    => array('{{', '}}'),
    
    // controller:
    var_dump(Config::get('parser.View_Smarty.delimiters'));
    
    // output:
    array(4) { 
      [0]=>  string(2) "{%" 
      [1]=>  string(2) "%}" 
      [2]=>  string(2) "{{" 
      [3]=>  string(2) "}}" 
    }
    

    It merges the array instead of replacing the values! I guess this is a bug, but is it Config or Parser bug? A different config style would solve this issue:
    // config/parser.php:
      'delimiters'    => array( 'left' => '{', 'right' => '}' ),
    
  • Unfortunately I don't use Orm so much ... but, at first impression, it can be a Smarty bug with objects ( but I'm not sure ). I've tried to use :
    $view->test = Model_Test::find('all'); // Orm
    $view->test1 = \DB::select()->from('test')->execute(); // Fuel DB Class
    

    With Smarty I get some errors but with Twig all works fine. Instead if I use arrays Smarty works :
    // Fuel Db Class
    $view->test1 = \DB::select()->from('test')->execute()->as_array();
    

    Can you check in Smarty forum if that cas be a bug or not?
    I had 1.0.1 at first and used scaffolding to create form "posts". I added a few records with titles "test<b>123</b>" for instance. Output filtering worked and it was displayed with < (correct).
    Then I upgraded to latest dev version and copied app/ over. However, now the titles display partially bold even though output filtering should be used!
    (Note: I am not using Smarty templates here, just normal views)

    Have you checked app/config/config.php for "Security settings"? Check "auto_encode_view_data".
  • Mmmm, I think it's a Parser bug.
  • Davide, thanks for helping me! :) 2) It's not a bug, it's a feature. ;)
    Smarty sections are a bit picky about the arrays. They must have arrays with incrementing numeric keys (array_values() returns such). As I said, I can help myself, but it is nicer if we can remove the "mines". 3) This is what it says:
    'auto_encode_view_data' => true,
    I have copied app/config/config.php from 1.0.1 installation.
    Does Parser take over normal Views too, could this be the reason for change?
  • @andy have your tried to use the View::forge() third parameter to force the auto_encode ( set to true )? Are you using the Fuel 1.1 dev now, right?
  • 3) Yes and yes. :)
    Ok, I debugged and this is also a bug. In app/config/config.php there should be another var:
      // inside 'security':
      'output_filter'   => array('htmlentities'),
    

    It would be even better to have some default sensible value (the same as in 1.0.1?) if it's not specified.
  • But have you copied and replaced all 1.1 config contents with the 1.0 config?? The config file content is different between this 2 versions.
    In 1.1, for security array, the output_filter use "'output_filter' => array('Security::htmlentities'),"
  • Argh. You are correct, of course. It looks like I downloaded 1.1 core and 1.0 fuel. :( I can't find a way to checkout the 1.1/develop from Github, how do I do that? I am more of a Mercurial fan myself... :) Sorry for false alarm. EDIT: figured it out:
    $ git clone -b 1.1/develop https://github.com/fuel/fuel.git Thanks for all the help, I appreciate it! :)
  • Andrew Black wrote on Thursday 8th of September 2011:
    Found the bug:
    // packages/parser/config/parser.php:
      'delimiters'    => array('&#123;%', '%}'),
    
    // app/config/parser.php
      'delimiters'    => array('&#123;&#123;', '}}'),
    
    // controller:
    var_dump(Config::get('parser.View_Smarty.delimiters'));
    
    // output:
    array(4) &#123; 
      [0]=>  string(2) "&#123;%" 
      [1]=>  string(2) "%}" 
      [2]=>  string(2) "&#123;&#123;" 
      [3]=>  string(2) "}}" 
    }
    

    It merges the array instead of replacing the values! I guess this is a bug, but is it Config or Parser bug? A different config style would solve this issue:
    // config/parser.php:
      'delimiters'    => array( 'left' => '&#123;', 'right' => '}' ),
    

    Also with 1.1 right config there's already this problem.
    Can you open an issue on Github?
  • I also submitted an issue for output_filter: https://github.com/fuel/core/issues/465 . I noticed only by chance that there is something wrong after the upgrade and the issue could lead to security vulnerabilities.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion