I'm Exhausted - Give me a hand here! - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: I'm Exhausted - Give me a hand here! (/showthread.php?tid=9819) |
I'm Exhausted - Give me a hand here! - El Forum - 07-09-2008 [eluser]developer10[/eluser] Well, although i knew moving from native PHP to CodeIgniter wasn't going to be an easy mission, i didn't expect not to be able to manage somewhat basic things. long story short, im rebuilding my site (native PHP) in CI. the site URLs are based on query strings. basically, these are examples of links and the same i want to achieve in CI: the site is BUSINESS DIRECTORY - filtering is possible by area of business (category), company city (city), company first letter (letter) and also, there's pagintion parameter (page) mysite.com/show.php?section=bizdirectory // all companies are listed mysite.com/show.php?section=bizdirectory&category=Banks // only banks are listed mysite.com/show.php?section=bizdirectory&category=Banks&letter=P // only banks beginning with "P" are listed mysite.com/show.php?section=bizdirectory&&category;=Banks&letter=P&page=2 // if there are many results, "page" gets involved The same goes for involving "city" parameter, i'll show some examples to get an idea mysite.com/show.php?section=bizdirectory&category=Banks&city=Sarajevo // only banks from Sarajevo are listed mysite.com/show.php?section=bizdirectory&category;=&city=Sarajevo // all companies from Sarajevo are listed (note empty value for the category parameter) etc, etc (adding "letter" and page parameters in any possible way) The main thing is that parameters go in this order: category, city, letter, page, and if needed, parameters (not only values) from the end can be omitted Basically, this is what i want to achieve in CI. So far, i managed to do this: mysite.com/index.php/bizdirectory EQUALS TO mysite.com/show.php?section=bizdirectory // all companies listed ( USING ONE FUNCTION within bizdirectory_model ) AND ( USING another FUNCTION within bizdirectory_model ) mysite.com/index.php/category/Banks (using routing) EQUALS TO mysite.com/show.php?section=bizdirectory&category=Banks // only banks listed Since i suppose there's an easy way to achieve everything i need/want in CI, please be so kind and give me some suggestions Thanks! I'm Exhausted - Give me a hand here! - El Forum - 07-09-2008 [eluser]taewoo[/eluser] If I understand you correctly, i think you're tryin to do this in a controller: Code: function show($category, $city, $letter, $page) I'm Exhausted - Give me a hand here! - El Forum - 07-09-2008 [eluser]developer10[/eluser] [quote author="taewoo" date="1215658046"]If I understand you correctly, i think you're tryin to do this in a controller: Code: function show($category, $city, $letter, $page) yes, i think that would be the way. i found some stuff about those parameters that get passed to a function but i dont fully understand it. consider this function for retrieving ALL companies from database: Code: function all_companies() { how do i incorporate those parameters into my query (with the option of using only some of them) and what URL/URI structure can you suggest? I'm Exhausted - Give me a hand here! - El Forum - 07-09-2008 [eluser]taewoo[/eluser] I suggest you watch the codeigniter tutorials... these are really really basic questions. You need to pass the variables from your controller to your model. Just like you would in regular, non-MVC php app. Code: $this->load->model('your_model'); I'm Exhausted - Give me a hand here! - El Forum - 07-09-2008 [eluser]developer10[/eluser] [quote author="taewoo" date="1215658928"]I suggest you watch the codeigniter tutorials... these are really really basic questions. You need to pass the variables from your controller to your model. Just like you would in regular, non-MVC php app. Code: $this->load->model('your_model'); you're right, im on it i thought models can only pass, not be passed anything. i imagined models being on one side, views on the other and controllers being as links and providers between them.. didn't know data can be passed in the opposite direction well, back to basics I'm Exhausted - Give me a hand here! - El Forum - 07-09-2008 [eluser]Colin Williams[/eluser] Here's a very basic example of MVC interaction that I posted for doug ealier: Here's the run down. The Blog Controller is called because the user enters our blog URL. We load the blog model to handle retrieving our data. We use the model to retrieve the data and pass it into the view. Our view loops through the result from the model and displays it in a manner we want. Excuse the brevity and shit HTML Also, if this is all our Blog controller did, ever, a model might be slight overkill (a framework might even be overkill for this!). But it is highly likely your App and its interaction with your database will be much more complex. Controller in controllers/blog.php Code: class Blog extends Controller { Model in models/blog_model.php Code: class Blog_model extends Model { View in views/blog/front.php Code: <html> I'm Exhausted - Give me a hand here! - El Forum - 07-09-2008 [eluser]taewoo[/eluser] So that's what SHTML stands for.. Shit HTML |