Welcome Guest, Not a member yet? Register   Sign In
scaffolding do you have to call load->scaffolding in the class constructor?
#1

[eluser]jared4444[/eluser]
I realize that scaffolding is depricated, but I would still like to play with it.

I can get it to work if I create a class called Db, and call load->scaffolding in the constructor.

I would like to be able to call it from a sub function so I can have one function call for each table. My keyword is scaffolding, and I got the code from the tutorial video #2.

This works:
class Db extends Controller
{
function Db()
{
parent::Controller();
$this->load->scaffolding('size');
}
}

I would like to do this though:
class Db extends Controller
{
function size()
{
parent::Controller();
$this->load->scaffolding('size');
}
function item()
{
parent::Controller();
$this->load->scaffolding('item');
}
}

I have tried having a constructor which calls parent::Controller(), then calling each load in the functions, but that did not work.

It could also be the url I am using, not entirely sure.

This works with the first example and the constructor:
http://localhost/pcw2/index.php/db/scaffolding

I have tried both of these with the bottom example, and it does not work:
http://localhost/pcw2/index.php/db/scaffolding/size - 404 as I expected
http://localhost/pcw2/index.php/db/size/scaffolding - blank page
#2

[eluser]slowgary[/eluser]
You should use the [ code ] tag when you post code, it makes it much easier to read, and thus easier for people to help you.

I don't know if you can do it like that, because the scaffolding looks for the trigger in the second URI segment. Maybe you could pass a third URI segment and use a switch to test it and call the appropriate function, like this:
Code:
class Db extends Controller
{
  function Db()
  {
      parent::Controller();      
  }

  function index()
  {
      switch($this->uri->segment(3))
      {
           case 'item':     $this->item();
                            break;
           case 'size':     $this->size();
                            break;
      }
  }

  function size()
  {
      $this->load->scaffolding('size');
  }

  function item()
  {
      $this->load->scaffolding('item');
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB