Tutorial − News section, help !!! |
[eluser]Kuglepen[/eluser]
Hey, I cant see where i have to use this code. From Tutorial The next thing to do is passing this data to the views! but what views are they talking about ? public function index() { $data['news'] = $this->news_model->get_news(); $data['title'] = 'News archive'; $this->load->view('templates/header', $data); $this->load->view('news/index', $data); $this->load->view('templates/footer'); }
[eluser]qcsites[/eluser]
The views that are created in the previous portion of the tutorial http://ellislab.com/codeigniter/user-gui...pages.html
[eluser]Kuglepen[/eluser]
arh okay, so its just another function in same controller.. ?
[eluser]qcsites[/eluser]
Sorry, not sure what you are asking. Code: public function index()
[eluser]Kuglepen[/eluser]
I dont know, where i have to use this function you are posting ? tutorials says i have to passing this data in to views..
[eluser]qcsites[/eluser]
The index function you posted originally does pass the data in to the view. I just added comments to it to try to show you what was happening in the code.
[eluser]Unknown[/eluser]
I am newbie in codeigniter and I also facing the problem in this tutorial in News Category. I did same as said in the tutorial. After added a news, all the news displayed correctly. But when I click on link, it redirects on the particular news page, but there it shows the following error.. Error Quote:A PHP Error was encountered view.php file Code: <h2><?php echo $news_items['title'] ?></h2> How to solve this problem ? Thanks in advance
[eluser]qcsites[/eluser]
Looks like you are not defining or passing the data from the controller. Do you have code similar to this in the view? Code: <?php foreach ($news as $news_item): ?> In the controller calling the view do you have this? Code: public function index() Also, do you have the model function and/or the table shown in the tutorial?
[eluser]Unknown[/eluser]
If you want variables to be available in your view, you have to make sure they are assigned in your controller. So since the standard way to pass the variables to the view is with the $data array, you should have something like this in your controller $data['news_items']['title'] = "Amazing Title"; $data['news_items']['text'] = "Lorem ipsum..."; When I started with CI that always confused me. Whatever you assign as $data['variable'] in the controller, is available as $variable in the view. So you could even avoid having multidimensional arrays by doing your variables like .. $data['news_item_title'] = "Amazing Title"; $data['news_item_text'] = "Lorem ipsum..."; Which would be available as $news_item_title and $news_item_text.
[eluser]InsiteFX[/eluser]
In the view if your passing the array all you need to do is php echo $title and $text. |
Welcome Guest, Not a member yet? Register Sign In |