I started learning kohana and got stuck right away ... I can't load the file from views ... it gives an error. Here is the code

class Controller_Index extends Controller_Template { public $template = 'v_index'; public function action_index() { $this->template->title = 'Интернет-магазин'; $this->template->content = 'Главная страница'; } public function action_catalog() { $this->template->title = 'Интернет-магазин'; $this->template->content = View::factory("v_catalog");//тут проблема... } } 

File code v_catalog.php

 <h4><?= $title ?></h4> <table border='1' width='80%'> <thead> <tr>Наименоание</tr> <th>Цена</th> </thead> <tbody> <tr> <td>Товар 1</td> <td>100 руб</td> </tr> <tr> <td>Товар 2</td> <td>200 руб</td> </tr> </tbody> </table> 

Tell me what's the matter? Screenshot with an error here

alt text

  • What is this your problem? Kohana has such a wonderful conclusion of mistakes, and you have not copied a word from there. - xEdelweiss
  • please - zhekonya
  • another thing - xEdelweiss

2 answers 2

What a good example of always giving an error. What makes you think that your view does not load? Its text appears in the text of the error.

The problem is that you do not pass the $title variable to the display, which is what the Undefined variable trying to tell you.

Variable assignment is as follows:

 $this->template->content->title = 'Заголовок'; 
  • figured out ... thanks - zhekonya
  • one
    Good luck in learning. I apologize if it seemed rude. - xEdelweiss
  • one
    yes all the rules ... not sugar - zhekonya

Maybe the problem is in v_catalog.php :

 <h4><?= $title ?></h4> 

It would be more correct to:

 <h4><? echo $title; ?></h4> 

And this code will then work without problems:

 $this->template->title = 'Интернет-магазин'; $this->template->content = View::factory("v_catalog"); 
  • @Asad, you didn’t raise the most recent question that has already been answered correctly, judging by the author’s words, the answer. Yes, and it was written incomprehensibly that - replacing one type of tags with others will not do anything, for the reason that the $title property still remains without a value. - xEdelweiss