• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4

#3
Don't double post.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.