Welcome Guest, Not a member yet? Register   Sign In
Automatically passing controller action variables to the view
#1

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.
#2

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.
#3

Don't double post.




Theme © iAndrew 2016 - Forum software by © MyBB