PHP Class Help

Status
Not open for further replies.

brsy

nah mang
May 12, 2011
1,530
272
I have a template system that works perfectly. It's just that I wanted to be able to organize the files, so it would be much more neat. This code is throwing errors:
PHP:
public function getFile($file, $admin = 0) {
       
        global $pelican;
       
        if($admin = 1) {
            if(file_exists('_templates/'.$pelican['Site']['skin'].'/admin' . $file . '.tpl')) {
                ob_start();
                include('_templates/'.$pelican['Site']['skin'].'/admin' . $file . '.tpl');
                $this->tpl .= ob_get_contents();
                ob_end_clean();
            }
           
        }
       
        if(file_exists('_templates/'.$pelican['Site']['skin'].'/' . $file . '.tpl')) {
            ob_start();
            include('_templates/'.$pelican['Site']['skin'].'/' . $file . '.tpl');
            $this->tpl .= ob_get_contents();
            ob_end_clean();
        }
                else {
                    die("<br /><b>Templating Error:</b> Unable to get the file <b>'".$file."'</b> from the theme <b>".$pelican['Site']['skin']."</b>.");
                }
            }

The original code is:
PHP:
 if(file_exists('_templates/'.$pelican['Site']['skin'].'/' . $file . '.tpl')) {
            ob_start();
            include('_templates/'.$pelican['Site']['skin'].'/' . $file . '.tpl');
            $this->tpl .= ob_get_contents();
            ob_end_clean();
        }
                else {
                    die("<b>Templating Error:</b> Unable to get the file <b>'".$file."'</b> from the theme <b>".$pelican['Site']['skin']."</b>.");
                }
            }
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
YOu should know where the script executes from when you enter the address. Look in your .htaccess and see if you see any redirects.
 

brsy

nah mang
May 12, 2011
1,530
272
YOu should know where the script executes from when you enter the address. Look in your .htaccess and see if you see any redirects.
Didn't use any .htaccess
I am still trying to get used to Mac, and I have everything working properly. Plus, all I did was add if($admin = 1) { (same code, except get the .tpl from admin file) }
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
Run this code, see what throws you then you'll find the error.

PHP:
echo '_templates/'.$pelican['Site']['skin'].'/admin' . $file . '.tpl'; die;

Probably $pelican['Site']['skin'] returns null

OR

it needs to be: '_templates/'.$pelican['Site']['skin'].'/admin/' . $file . '.tpl'
 

brsy

nah mang
May 12, 2011
1,530
272
Okay, so it isn't throwing an error anymore; but now it's freaking only adding the footer, it isn't getting the stupid file.

Actually, it only works for one thing -- whether it's the main site, or the admin file directory. This is the current code that I have at the moment.

PHP:
public function getFile($file, $admin = null) {
     
        global $pelican;
     
     
        if($admin == 1) {
            if(file_exists('_templates/'.$pelican['Site']['skin'].'/admin/' . $file . '.tpl')) {
                ob_start();
                include('_templates/'.$pelican['Site']['skin'].'/admin/' . $file . '.tpl');
                $this->tpl .= ob_get_contents();
                ob_end_clean();
            }
        }
     
        if($admin == null) {
            if(file_exists('_templates/'.$pelican['Site']['skin'].'/' . $file . '.tpl')) {
                ob_start();
                include('_templates/'.$pelican['Site']['skin'].'/' . $file . '.tpl');
                $this->tpl .= ob_get_contents();
                ob_end_clean();
            }
        }
                else {
                    die("<br /><b>Templating Error:</b> Unable to get the file <b>'".$file."'</b> from the theme <b>".$pelican['Site']['skin']."</b>.");
                }
            }

If I put the if($admin == 1) part first, the Admin section doesn't work, and if I put if($admin == null) then the admin part works.
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
*sigh* lrn2phpd00d

PHP:
public function getFile($file, $admin = null) {
   
        global $pelican;
   
   
        if($admin == 1) {
            if(file_exists('_templates/'.$pelican['Site']['skin'].'/admin/' . $file . '.tpl')) {
                ob_start();
                include('_templates/'.$pelican['Site']['skin'].'/admin/' . $file . '.tpl');
                $this->tpl .= ob_get_contents();
                ob_end_clean();
            }
        }else{
            if(file_exists('_templates/'.$pelican['Site']['skin'].'/' . $file . '.tpl')) {
                ob_start();
                include('_templates/'.$pelican['Site']['skin'].'/' . $file . '.tpl');
                $this->tpl .= ob_get_contents();
                ob_end_clean();
            }else{
                    die("<br /><b>Templating Error:</b> Unable to get the file <b>'".$file."'</b> from the theme <b>".$pelican['Site']['skin']."</b>.");
            }
        }
            
 }
 

brsy

nah mang
May 12, 2011
1,530
272
Ugh, no errors, but it still dnt work . I have my files kinda like uberCMS, and i have it to add sets, so I would add footer, etc. Only the footer and header is added, meaning the getFile thingy is ignored.
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
Ugh, no errors, but it still dnt work . I have my files kinda like uberCMS, and i have it to add sets, so I would add footer, etc. Only the footer and header is added, meaning the getFile thingy is ignored.

Probably you're not outputting $this->tpl right or something. That function is perfect.
 
Status
Not open for further replies.

Users who are viewing this thread

Top