![]() |
Need Basic MVC Example - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Need Basic MVC Example (/showthread.php?tid=41271) |
Need Basic MVC Example - El Forum - 05-03-2011 [eluser]cupidleomanoj[/eluser] hi, am new to codeigniter as well as to MVC architecture, can any one help me to how the values are to be fetched from database and dispalyed, please i cant get it done. please give me a basic example. thanks in adavnce Need Basic MVC Example - El Forum - 05-03-2011 [eluser]oppenheimer[/eluser] I think the <a href="http://codeigniter.com/tutorials/">video tutorials<a> are very good at this. Need Basic MVC Example - El Forum - 05-03-2011 [eluser]cupidleomanoj[/eluser] thanks for your reply, I have tried something with CI, but i cant get the output. can you please help me. the following are the codes. model:- (file name : Helloworld_model.php) <?php class Helloworld_model extends CI_Model { public function __construct() { parent::__construct(); } function getData() { $query=$this->db->get('data'); if($query->num_rows() > 0) { } else { return $query->result(); } } } ?> controller:- (filename : helloworld.php) <?php class Helloworld extends CI_Controller { public function __construct() { parent::__construct(); // Your own constructor code } function index() { $this->load->model('helloworld_model'); $data['result'] = $this->helloworld_model->getData(); $data['page_title'] = "CI"; $this->load->view('helloworld_view',$data); } } ?> view:- (filename : helloworld_view.php) <html> <head> <title><?=$page_title?></title> </head> <body> <?php foreach($result as $row):?> <h3><?=$row->title?></h3> <p><?=$row->text?></p> <br /> <?php endforeach;?> </body> </html> ---------------------------------------------- I get error as A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: views/helloworld_view.php Line Number: 6 ------------------------------------------------- Need Basic MVC Example - El Forum - 05-03-2011 [eluser]oppenheimer[/eluser] Change your model with this return Code: return $query->result_array(); However, I wasn't familiar with this syntax in your view: Code: <title><?=$page_title?></title> I usually use: Code: <title><? echo $page_title; ?></title> Need Basic MVC Example - El Forum - 05-03-2011 [eluser]John_Betong_002[/eluser] Check your model... Code: class Helloworld_model extends CI_Model Need Basic MVC Example - El Forum - 05-04-2011 [eluser]cupidleomanoj[/eluser] hi friends thanks for your solutions i got my desired output. thank you... Need Basic MVC Example - El Forum - 05-04-2011 [eluser]cupidleomanoj[/eluser] hi oppenheimer, * your told that your are not familiar with the syntax <title><?=$page_title?></title>, there are "short_open_tag" in PHP, it is very common as of the <title><?php echo $page_title; ?></title>. * To use this shortcut syntax you need to enable the short_open_tag in the phpinfo(); follow the example: <?php $message1 = "<p>This is my primary message.</p>\n"; ?> <?php echo $message1; ?> //normal syntax <?=$message1?> //shortcut syntax |