How to call another controller? - 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: How to call another controller? (/showthread.php?tid=43507) Pages:
1
2
|
How to call another controller? - El Forum - 07-13-2011 [eluser]Near[/eluser] Hi, i'm a new user of code igniter. i was wondering if i can call another controller aside from the one declared at the routes.php? because when i try to call another controller the page cannot be found... thanks.. sorry for bad english.. cheers! How to call another controller? - El Forum - 07-13-2011 [eluser]John_Betong_002[/eluser] It is not straight forward and far easier to inherit from a common library. Try searching for "MY_Controller". How to call another controller? - El Forum - 07-13-2011 [eluser]Near[/eluser] is there any way to do this? this is the scenario.. when i click a button in a view naamed ocd_view it calls a function located at the default controller named ocd_controller. the controller loads another view. named highAndLow_view and when i click a button it calls another controller named hourlyheights_controller. but when i do that the page looks at the ocd_controller istead of looking at the hourlyheights_controller... please help. thanks sorry for bad english..thanks How to call another controller? - El Forum - 07-13-2011 [eluser]Near[/eluser] is there any easy way to do this? this is the scenario.. when i click a button in a view named ocd_view it calls a function located at the default controller named ocd_controller. the controller loads another view. named highAndLow_view and when i click a button it calls another controller named hourlyheights_controller. but when i do that the page looks at the ocd_controller istead of looking at the hourlyheights_controller... please help. thanks sorry for bad english..thanks How to call another controller? - El Forum - 07-13-2011 [eluser]John_Betong_002[/eluser] Try this: Code: // http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html edit renamed incorrect link. How to call another controller? - El Forum - 07-14-2011 [eluser]Near[/eluser] thanks.. that takes care of the different controller problem .. my new problem is why i get stucked at the highAndLow view when im sending a parameter as a third segment of the uri? the page loads but the uri looks like this... example.com/tides/ocd_controller/highAndLow_view/hourlyMonth instead of example.com/tides/ocd_controller/hourlyMonth How to call another controller? - El Forum - 07-14-2011 [eluser]John_Betong_002[/eluser] With the information you provide I will try three guesses. 1. Are you using the anchor function? 2. Have you set $config['base_url']? 3. Have you checked the script against another link that is working? I am not very good at guessing and reckon it will be far better if you supply the script. How to call another controller? - El Forum - 07-14-2011 [eluser]Near[/eluser] yes im using anchor tags and my $config['base_url'] are set to "http://localhost/Oceano"; heres my code _________________________________ TIDES CONTROLLER <?php Class Tides_Controller extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('tides_model'); $this->load->helper('form'); $this->load->helper('html'); } function Index() { $this->load->view('Index'); } //get the list of distinc stations in the database function getStation() { $data['query1'] = $this->tides_model->getStation(); $this->load->view('main',$data); } function hourlyQuery() { $this->load->view('hourlyHeights'); } function hourlyMonth() { $month = $_POST['month']; $year = $_POST['year']; $datum = $_POST['datum']; $hidden = $_POST['hidden']; $key = $_POST['key']; $date = $year."-".$month; $data2['query2'] = $this->tides_model->getMonthly($date,$datum,$hidden); $data2['key'] = $key; $data2['datum'] = $datum; $this->load->view('/viewers/hourly_viewer',$data2); } } ?> __________________________________________ TIDES_MODEL class Tides_model extends CI_Model { function Events_model(){ parent::__construct(); } function getStation(){ $query1 = $this->db->query('SELECT DISTINCT location FROM proc_tides'); return $query1; } function getMonthly($date,$datum,$hidden){ $query2 = $this->db->query("SELECT height FROM proc_tides where date_p like '$date%' and location='$hidden'"); return $query2; } function getHourlyYear($date,$location,$datum){ $query4 = $this->db->query("SELECT height FROM proc_tides where date_p like'$date%' and location ='$location'"); return $query4; } } _____________________________________ INDEX (VIEW) <?php echo anchor('tides_controller/getStation','Query Center')?> <br /> <br /> <?php echo anchor('tides_controller/call_database_main','Database'); ?> </body> </html> __________________________________ MAIN (VIEW) <html> <form action="category_view" method="post"> <select name="station"> <?php foreach ($query1->result() as $row) { ?> <option><?php echo $row->location; ?></option> <?php } ?> </select> <input type="submit" name="submit" value="SUBMIT"> </form> </html> _______________________ CATEGORY_VIEW <?php echo anchor('tides_controller/hourlyQuery/'.$station,'HOURLY HEIGHTS'); ?> <?php echo anchor('highlow_controller/test/' .$station, 'HIGH AND LOW TIDES'); ?> _____________________________ HOURLY_HEIGHTS (VIEW) <?php $station = $this->uri->segment(3)?> <?php echo 'Enter your Query for'.' '.$station?> <html> <h1>Monthly Query</h1> <form action="hourlyMonth" method="post"> <label for="year">Enter Year</label> <input type="text" name="year"> <label for="month">Enter month</label> <input type="text" name="month"><br><br> <label for="datum">Datum</label> <input type="text" name="datum" value="0"><br> <input type="submit" value="Submit Query"> <input type="hidden" name="hidden" value="<?php echo $station;?>"> <input type="hidden" name="key" value="1"> </form> my problem is when i click the submit button at hourly_Heights the page is loaded in the same page? How to call another controller? - El Forum - 07-14-2011 [eluser]John_Betong_002[/eluser] Try this: Code: <form action=“Tides_Controller/hourlyMonth” method=“post”> Please also note that the script I submitted is wrapped in code tags and makes reading the code easier. Try wrapping your script in code tags and notice the difference. How to call another controller? - El Forum - 07-14-2011 [eluser]Near[/eluser] ok sir.. thanks for your help. i will try this when i arrive our house. im only at computer shop.. i'm not an english speaking person. sorry for my poor english. |