0

I build css links with a function but if I don't do a var_dump on the end, the css will not work. What am I missing or not seeing?

The code:

private function buildCssLinks(){
    $files  =   $this->findFiles(dirname(dirname(__FILE__))."/css","css");

    foreach ($files as $id)
    {
        $pathInfo   =   pathinfo($id);
        $fileName   =   $pathInfo['basename'];

        $files[] = '<link rel="stylesheet" type="text/css" href="css/' . $fileName . '">';
    }
    return implode("",$files);
}

returns

1st return

but when I add a var dump in my code

    private function buildCssLinks(){
    $files  =   $this->findFiles(dirname(dirname(__FILE__))."/css","css");

    foreach ($files as $id)
    {
        $pathInfo   =   pathinfo($id);
        $fileName   =   $pathInfo['basename'];

        $files[] = '<link rel="stylesheet" type="text/css" href="css/' . $fileName . '">';
    }
    var_dump($files);
    return implode("",$files);
}

the 2nd return

2nd return

the code that calls the functions __construct

  public function __construct($header, $body, $footer)
{
    $this->header   =   $header;
    $this->body     =   $body;
    $this->footer   =   $footer;


    $this->buildHeader();
    $this->buildBody();
    $this->buildFooter();

    $js     =   $this->buildJsLinks();
    $css    =   $this->buildCssLinks();
    $this->header   =   $css;
    $this->footer   =   $js;
}
3
  • I get the feeling you need to echo buildCssLinks(). Commented Nov 26, 2016 at 22:38
  • can you show us the code that calls buildCssLinks? Commented Nov 26, 2016 at 22:40
  • @WEBjuju i added the call code Commented Nov 26, 2016 at 22:44

1 Answer 1

2

Your buildCssLinks is returning the html. But you must then put it into your html somehow. Perhaps

$css = $this->buildCssLinks();
$this->header .= $css;

or more likely you need to buildCssLinks first and pass that into header build:

$this->css = $this->buildCssLinks();
$this->buildHeader();  // within buildHeader echo your this->css
Sign up to request clarification or add additional context in comments.

4 Comments

what does the implode function then ?
it takes all of the elements of an array and concatenates them with the first argument to implode (which in your case is empty). so array(1,2,3) imploded is "123" and implode(",", array(1,2,3)) is "1,2,3", yo.
i added $js = $this->buildJsLinks(); $css = $this->buildCssLinks(); $this->header = $css; $this->footer = $js;
if this is solved, please mark the solution. if this is not solved, post your updated code and unexpected results, please.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.