سؤال

Model

 <?php

class Testrundetail extends Eloquent {

    protected $table = 'testrundetail';

    public static function getAll ()
    {
        $getAll = DB::table('testrundetail')
            ->orderBy('platform', 'asc')
            ->distinct()
            ->lists('platform');

            return $getAll;    
    }
}

Controller

class PageController extends BaseController {

        public function home ()
        {
            $var = Testrundetail::getAll();

        return View::make('hello')->with('var', '$var');

        }

        public function about ()
        {

        return View::make('about');
        }

    }

hello.blade.php

<!doctype html>

<html>

    <head>
        <meta charset="utf-8">
    </head>

    <body>

    <h1> Hello, {{$var}} </h1>

    </body>

</html>

The output of the getAll() is: ['2520','stack-Ar','2530','2530ya'] But in output I get 'Hello $var'

What am I doing wrong? Though, if I do hello{{$var[0]}}, I get the output 'Hello 2'

هل كانت مفيدة؟

المحلول

first of all

return View::make('hello')->with('var', '$var');

should become

return View::make('hello')->with('var', $var);

otherwise you will print '$var',

second you will pass an array of objects to the view, so in the view type something like:

@foreach($var as $item)
    <li> 
        {{$item->columnName}} 
    </li>
@endforeach

نصائح أخرى

you are using {{$var}}. {{ }} braces are used to echo php variable when we use blade templating. and if you are not using blade templating, then simply go with core php concept.

simply use

 var_dump($var);
 or print_r($var);

click here to know about blade templating.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top