Laravel define default layout from controller in good way

前端 未结 3 1439
予麋鹿
予麋鹿 2021-01-05 15:52

I googled two hours, but not found answer. Maybe you can help.

When I define in MyController:

class MyController extends Base_Cont         


        
3条回答
  •  感情败类
    2021-01-05 16:46

     class BaseController extends Controller {
    
    /**
     * Setup the layout used by the controller.
     *
     * @return void
     */
    
    /*Set a layout properties here, so you can globally
      call it in all of your Controllers*/
    protected $layout = 'layouts.default';
    
    protected function setupLayout()
    {
        if ( ! is_null($this->layout))
        {
            $this->layout = View::make($this->layout);
        }
    }
    

    }

    class HomeController extends BaseController {

    public function showHome()
    {   
        /*now you can control your Layout it here */
         $this->layout->title= "Hi I am a title"; //add a dynamic title 
         $this->layout->content = View::make('home');
    }
    

    }

    Ref: http://teknosains.com/i/tutorial-dynamic-layout-in-laravel-4

提交回复
热议问题