Basic Tutorial Help |
I am working with the simple tutorial in the documentation.
Create a file at application/controllers/Pages.php with the following code. <?php class Pages extends CI_Controller { public function view($page = 'home') { } } And this I am not sure if it goes in the Pages.php file or a new one, and if new I don't see the name of it and where it goes, that is which folder. Also, I do not see a closing ?> php tag in any of this code. public function view($page = 'home') { if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); } $data['title'] = ucfirst($page); // Capitalize the first letter $this->load->view('templates/header', $data); $this->load->view('pages/'.$page, $data); $this->load->view('templates/footer', $data); } Sorry, I am very new to CodeIgniter and actually php to be honest. I have tried adding the code to the Pages.php file but only get error's. Is there a completed version somewhere so I can see what I am doing wrong? Thanks for any help!
It goes into the sane controller they are just showing you step by step how to add it in.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
It says error on line 12 which is this:
public function view($page = 'home') Here is my complete controller code in Pages.php: <?php class Pages extends CI_Controller { public function view($page = 'home') { } } ?> <?php public function view($page = 'home') { if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); } $data['title'] = ucfirst($page); // Capitalize the first letter $this->load->view('templates/header', $data); $this->load->view('pages/'.$page, $data); $this->load->view('templates/footer', $data); } ?> And complete errors: A PHP Error was encountered Severity: Warning Message: Cannot modify header information - headers already sent by (output started at /home/sportsd7/public_html/codeigniter/application/controllers/Pages.php:12) Filename: core/Common.php Line Number: 573 Backtrace: A PHP Error was encountered Severity: Parsing Error Message: syntax error, unexpected 'public' (T_PUBLIC) Filename: controllers/Pages.php Line Number: 12 Backtrace: Thanks for your help!
You do not need the closing php tag anymore remove it.
Headers already sent means you have output some data to the view or a space in the code before the php tag. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I got it working. Thanks for your help! Now to finish the rest of the tutorial! I am sure I will have more questions as I continue.
News Section tutorial I am working on. Can display news items manually input into the database, but can not add items through the Create form:
News.php Code: <?php News_model.php Code: <?php create.php (in the views/news folder) Code: <h2><?php echo $title; ?></h2> routes.php (changes from tutorial) Code: <?php All I get is a blank page when trying to insert a new record. I can manually add news items to the database through phpMyAdmin but not through the Create form! Here is the error as it is not connecting to the database: http://www.screencast.com/t/8NFaonzVBvW Thanks for your help! Update: It was the config base_url, and now is inserting data into the database via the create.php file, but the success message has an error I need to try and fix. I kind of figured it was something simple. Now to see if I can fix the new error. When or if I figure this one out, I'll let you know. Success Error: http://www.screencast.com/t/VASIK9juls All done. It helps if you include the success.php file. Everything working now. It's the little obvious things that always get me, having the wrong database name in the database.php file, not realizing the future code in the tutorial goes inside of the controller or model code, NOT below it. Not having the correct base_url in the config file, and not putting the success.php file in the views/news/ folder. Now to style it and see if I can come up with some changes to make my own. Thanks and good luck everyone new to PHP and CodeIgniter like I am.
You would need to create that yourself, should be almost like all the create stuff.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |