TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
I thought I had this... UNDEFINED VARIABLE
  • I have copied this code from code which works and just changed the variables, but it doesn't seem to be passing the variable to the view to be accessed:

    class Controller_Cast extends Controller_DefaultTemplate {

    protected $cast;

    public function before()

    //$this->request = Request::instance();
    $this->cast = new Model_Cast;

    public function action_index()
    $data = array();
    $data['cast_main'] = $this->cast->get_main_cast();

    $this->template->content = View::factory('pages/cast_index');

    * Get all the main characters
    * @return ARRAY
    public function get_main_cast()
    $query = DB::select('id', 'first_name', 'last_name')

    return $query;

    foreach ($cast_main as $mc)
    echo $mc['first_name'] ." ". $mc['last_name'];
    //echo Database::instance()->last_query;

    PS. The query functions correctly -- please help.

  • $data['cast_main'];

    This doesn't seem to be passed to your view.

    $this->template->content = View::factory('pages/cast_index')->set('cast_main', $this->cast->get_main_cast());

  • Thanks for the reply xenakis, but what you have put is not how the other one is set which works...

    $data['s1_episodes'] = $this->episode->get_s1_episodes();
  • Hi:

    I dont' know If I understand correctly, but you can do this:

    $data = array();
    $data['cast_main'] = $this->cast->get_main_cast();
    $data['s1_episodes'] = $this->episode->get_s1_episodes();

    $this->template->content = View::factory('pages/cast_index', $data);

    You can access the data by array key, ej:
    foreach ($cast_main as $mc) echo "loop1<br />";
    foreach ($s1_episodes as $ep) echo "loop2<br />";


  • Thanks for the reply xenakis, but what you have put is not how the other one is set which works...

    $data['s1_episodes'] = $this->episode->get_s1_episodes();

    You need to improve your debugging skills. Xenakis' analysis is correct. There is more to it than the line you quote here. It is a simple matter to compare code A with code B and deal with the differences.
  • Thanks blabla, I knew all I needed was another pair of eyes -- I was missing the $data when writing the view code in the controller.

    I realise that it was just a matter of debugging, but I do not post anywhere asking for help unless necessary, and I had been staring and comparing for a few hours while working on my actual job. All I was saying in my reply was that the example code was not the same as in the controller that worked.

    Thanks all.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion