CodeIgniter Forums

Full Version: Automatically passing controller action variables to the view
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like a way to automatically pass variables from a controller action to a view just by declaring a variable.

So instead of 

PHP Code:
<?php
class News extends CI_Controller {
        public function index()
        {
                $data['test'] = "hello";
        }

I can have


PHP Code:
<?php
class News extends CI_Controller {
       public function index()
       {
               $test "hello";
       }




And I can echo $test in the view and the word "hello" appears as the variable is passed automatically to the view without me having to manually pass it myself.

Ruby framework Ramaze has this feature, and it makes coding much more pleasant.
Rails (and other frameworks, like Laravel) do things in ways that are much more magical/implicit than CodeIgniter has been throughout it's history. Through the life of CI, it has always kept things light-weight and fairly explicit. We intend to keep it that way, mostly.

Besides the overhead required in making that work, that would mean that any temporary vars you set also show up in the view, which is a waste of resources.