Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel without Blade - Controllers and Views

Tags:

laravel

I am more efficient at setting up my view logic with straight up php. Blade is cool but it's not for me. I am trying to translate all the Blade specific examples and docs to just php. I don't like the fact that I need to assign all the variables for my views in an array of View::make(). I did found all of this so far.

controllers/home.php:

class Home_Controller extends Base_Controller {

    public $layout = 'layouts.default';

    public function action_index()
    {
        $this->layout->name = 'James';
        $this->layout->nest('content', 'home.index');
    }

}

views/layouts/default.php:

// head code
<?php echo Section::yield('content') ?>
// footer code

views/home/index.php

<?php Section::start('content'); ?>
<?php echo $name ?>
<?php Section::stop(); ?>

I am greeted with this error: Error rendering view: [home.index] Undefined variable: name. I know that $this->layout->nest('content', 'home.index', array('name' => 'James')); works but that negates my point about having to send all my variables to an array. This can't be the only way.

The view templating docs doesn't seem to touch on doing variables with nested views from controllers.

like image 563
James Wagoner Avatar asked Dec 23 '12 10:12

James Wagoner


1 Answers

you can pass variables this way;

class Home_Controller extends Base_Controller {

    public $layout = 'layouts.default';

    public function action_index()
    {

        $this->layout->nest('content', 'home.index')
                ->with('name', 'James');
    }

}
like image 89
Laurence Avatar answered Oct 23 '22 14:10

Laurence