CodeIgniter Forums

Full Version: Parser error :(
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Lazos[/eluser]
Hi I have this array $directory that I am collecting data. The result of this array is not the same as the one they use in the User Guide of CI?

I am getting this error and I do not know why.
A PHP Error was encountered

Severity: Warning

Message: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 2

Filename: libraries/Parser.php

Line Number: 161

Any help?

My array.
Code:
$i = 0;
        while (false !== ($file = readdir($dh))){
            if(!in_array($file, $ignore)){  
                if(is_dir($path.'/'.$file)){
                    if ($file == '..' && (($path != $this->imagepath) || ($path != $this->root))) {
                    $directory['repeat'][$i]['I_DIRECTORY'] = '<a href="'.base_url().'index.php/admin/imagemanager?dir='.$back.'" title="Go Back">'.$this->CI->admin_theme->displayImage('images/admin/filemanager/32px/dir.png', 'Go Back', '','','').'</a>';
                    $directory['repeat'][$i]['V_FILENAME'] = $file;
                    $directory['repeat'][$i]['V_FILEOWNER'] = '&nbsp;';
                    $directory['repeat'][$i]['V_PERMS'] = '&nbsp;';
                    $directory['repeat'][$i]['V_SIZE'] = '&nbsp;';
                    $directory['repeat'][$i]['V_DATE'] = '&nbsp;';
                    $directory['repeat'][$i]['I_DELETE'] = '&nbsp;';
                    $directory['repeat'][$i]['I_CHANGEPERMS'] = '&nbsp;';
                    $directory['repeat'][$i]['I_DELETE'] = '&nbsp;';
                    $directory['repeat'][$i]['I_LOCK'] = '&nbsp;';
                    
                    }
                    if ($file != '..') {
                    $directory['repeat'][$i]['img'] = '<a href="'.base_url().'index.php/admin/imagemanager?dir='.$back.'" title="Go Back">'.$this->CI->admin_theme->displayImage('images/admin/filemanager/32px/dir.png', 'Go Back', '','','').'</a>';
                    $directory['repeat'][$i]['V_FILENAME'] = $file;
                    $directory['repeat'][$i]['V_FILEOWNER'] = '&nbsp;';
                    $directory['repeat'][$i]['V_PERMS'] = '&nbsp;';
                    $directory['repeat'][$i]['V_SIZE'] = '&nbsp;';
                    $directory['repeat'][$i]['V_DATE'] = '&nbsp;';
                    $directory['repeat'][$i]['I_DELETE'] = '&nbsp;';
                    $directory['repeat'][$i]['I_CHANGEPERMS'] = '&nbsp;';
                    $directory['repeat'][$i]['I_DELETE'] = '&nbsp;';
                    $directory['repeat'][$i]['I_LOCK'] = '&nbsp;';
                    }
                }        
        $i++;    }
        }


Code Igniter Example
Code:
$data = array(
              'blog_title'   => 'My Blog Title',
              'blog_heading' => 'My Blog Heading',
              'blog_entries' => array(
                                      array('title' => 'Title 1', 'body' => 'Body 1'),
                                      array('title' => 'Title 2', 'body' => 'Body 2'),
                                      array('title' => 'Title 3', 'body' => 'Body 3'),
                                      array('title' => 'Title 4', 'body' => 'Body 4'),
                                      array('title' => 'Title 5', 'body' => 'Body 5')
                                      )
            );

$this->parser->parse('blog_template', $data);

My Template
Code:
{repeat}
    <tr class="row1">
        <td valign="middle"><a href="{U_DIR}"><img height="32" style="border:0;" src="{I_DIRECTORY}" alt="directory" align="middle" /></a></td>
        <td valign="middle"><a href="{U_NAME}">{V_FILENAME}</a></td>
        <td style="padding-right:8px;" valign="middle">{V_FILEOWNER}</td>
        <td style="padding-right:8px;" valign="middle">{V_PERMS}</td>
        <td style="padding-right:2px;text-align:right;" valign="middle">{V_SIZE}</td>
        <td style="padding-right:8px;" valign="middle">&nbsp;</td>
        <td style="padding-right:8px;" valign="middle">{V_DATE}</td>
        <td valign="middle">
            <table cellspacing="0" border="0">
                <tr>    
                    <td valign="middle">{I_RENAME}</td>
                    <td valign="middle">{I_CHANGEPERMS}</td>
                    <td valign="middle">{I_DELETE}</td>
                    <td valign="middle">{I_LOCK}</td>
                </tr>
            </table>    
        </td>
        <td>&nbsp;</td>
    </tr>
    {/repeat}

El Forum

[eluser]NachoLabs[/eluser]
I realize this is old, but I just had the very same problem and I just solved it, so I thought i'd post the solution here, in case anybody else comes across this thread.

The problem in my case was that I was passing parse() this array:

Code:
$items = Array(0 => Array(...), 1 => Array(...), ...)

and trying to do:
Code:
{items}
   {name}
{/items}

while for that to work the correct array would have been:

Code:
$items = Array('items' => Array(0 => Array(...), 1 => Array(...), ...) )


In the case above, you probably were passing $directory['repeat'] as your array comparison, while it needed to be simply $directory. That was my mix up, at least.

Hope this was useful to somebody.