Newbie Q - controller/view code for mixed query |
[eluser]toopay[/eluser]
AR is just a simple helper, which help you have a less code in your model (by creating a short hand of SQL of course), but its not really change anything else on how you interact with your data(base). Some veteran developer i known, prefer have those "SELECT * FROM my_table ORDER BY ISNULL(field), field [ ASC | DESC ]" rather than using or creates a helper to minimalize the code. So whatsoever you did, with those AR statement, basicly theres no principe stuff that differentiate it from SQL. Its same thing, after all.
[eluser]jmadsen[/eluser]
I've heard this before, but that doesn't make much sense to me - "minimize the code". Go count characters it takes to write my query vs. AR -- be sure to include "$this->db->select". It's not less code. Same with "pre-compiling" - just break up the strings into variables when you need to. $sub_query = "...." No magic. "if you do know what you’re doing, it’s not bad to take shortcuts"...that's fine too, but how many web developers here thought to suggest to the original poster that he should not loop over all of his tasks and run a new query for each to get the comments? Without trying to sound boorish, when it comes to SQL, do you really know what you're doing? Did you think of - and could you write - the query I posted as a solution? I sometimes use AR myself - the point about jquery is valid. It can be a good shortcut. The reason I preach against it I know far too many web developers who can't write any sort of simple query and will do ANYTHING to avoid writing sql. AR gives them one more excuse to avoid learning something that is essential to their work, and so they write terrible code in their sites like huge loops around every table and think that that's okay. AR hides everything away, so they can't even notice when they've coded something backwards
[eluser]theprodigy[/eluser]
I'm not against knowing what you're doing. I'm actually quite the opposite. I think that you should know what the code does that your typing (even if using someone else's libraries). Whenever I use someone else's stuff (whether copied/pasted from a website, or downloaded library), I always read through it to see what it's doing. But, on the other hand, if you know what you're doing, then using AR, or ORM, or some other helper functions can save you a lot of time with both initial writing and maintaining. I agree with your thoughts about these tools allowing un-knowledgeable developers to be able to do things they normally would not be able to do, but I also know that that is exactly where the languages of the web are going. With the advent of jQuery (and other js frameworks), very user friendly sites are popping up everywhere by people that would not have been able to do it with straight javascript. With the advent of CI, Symfony, CakePHP, etc, robust websites are being created by people who don't know very much at all about php. Hell, how many WordPress sites are there now? Many of them being maintained by people that don't even know what php is. And it's not just php. Other backend programming languages are suffering from the same thing. Basically, the point is, I agree with you that you should know what you're doing, but for every 1 person I get to learn about it, 500 more are building sites using these tools that don't and never will understand it. Fight the good fight, but don't expect large results. Companies nowadays prefer results over knowledge. If you can do it, you're hired, who cares if you know why or how it works as long as it does.
[eluser]osci[/eluser]
Quote:Without trying to sound boorish, when it comes to SQL, do you really know what you’re doing? Did you think of - and could you write - the query I posted as a solution? That's what you think of? I never tried to give a solution to the topic. I "hijacked" because I read Nick_MyShuitings's post and as I read the same in another of his recent posts I couldn't resist arguing about it. Sorry @vinofilus. Also when you argued about the impossible since I've done it again before I just grabbed your code and showed you how I did it elsewhere (that should point a bit if I could) Its good you know advanced sql (not just simple queries) and even better that you put your mind down and wrote the sql to help vinofilus. But isn't that enough? Do you want to brag? And if you wanted btw couldn't you do it without getting personal? That's about the quote. Why I do it with AR? Because I like using such syntax. I like thinking of where add it, order by add it bla bla, that simple. I create most of my js in php code to use, for example Code: $this->js_lib->jquery_onload($this->js_lib->slidetoggle_element('#toggle_products', '500')); You could do it in a totally different way, right? But I like this way of syntax and if I can keep it like this with little impact (as translating the real sql that I write by hand in paper, or coverting my js customizations to php) I just do so. My only trouble about the above AR for now is that it's a _method and could change in future implementation. If I was given the option to have it as a normal method I'd be quite happy about it and could safely go.
[eluser]Basketcasesoftware[/eluser]
I agree. Unfortunately sometime I find myself in the boat where I have to work with a new technology even before I get the chance to fully understand it. I have enough of a background already that I'm usually able to wing it. I search around for a solution that meets the tech and the design goals and use it immediately. I do take the time later to understand what is happening and start refining things from there. Update: Sometimes being to much of a "purist" about initial technical skill gets in the way of development. Oftentimes those who have had no previous experience with a framework or technology can come up with surprisingly elegant solutions to a problem that those who've had either more formal train or experience simply miss because of their commitment to a particular paradigm.
[eluser]jmadsen[/eluser]
@osci - When I said "you", I meant "you, the reader", no you personally. This isn't any sort of attack on anyone - apologies if it came across that way. AR simply runs a series of functions to concatenate a bunch of strings. It is slower (by how much, I don't know - probably minimal), lacks important things you need to write serious queries, and sometimes (such as or_where() ) is misleading in what functions do and can lead to serious mistakes in conditions - which you won't even notice because you can't see the sql you are producing unless you intentionally look for it. Furthermore, it fills up this forum with "how do I force this bit of sql into these functions?"- type questions It is also rumored to kick puppies. The query I wrote was not advanced. Matter of fact, it's something I used to teach to beginner sql students as part of a database night school class. IMHO, anyone who looked at that query above and thought it was complicated or advanced should go out on the internet and study sql some more.
[eluser]osci[/eluser]
I'm glad it wasn't intentional. As for the advanced, (I 'm still glad it wasn't intentional) it should seem complicated to the 80-90% of the user forums, and I mean no personal offense to anyone too, it's because as suggested it is rummored to kick puppies and as I posted above people grab a framework to write code with minimal basic knowledge. BTW thanks jmadsen for pointing people to the right directions Quote:go out on the internet and study sql some more
[eluser]theprodigy[/eluser]
jmadsen, just out of curiosity, why do you find or_where() misleading? In your opinion, what SHOULD that function do, and how does that differ from what id DOES do?
[eluser]jmadsen[/eluser]
@theprodigy - I may be mistaken on which function it was - was trying to remember which one I had caused an error in my own code with once a while back because I assumed there would be some sort of grouping with ()'s, and there wasn't. Perhaps passing an array into that function? I'd have to go back and experiment. I'm just curious - people who like using AR, are your views created primarily from the html and form helpers? Do you use heading('Welcome!', 3); every time you want to put an h3 on your page? If I said, "Hi! I'm a web developer. I like Codeigniter because I don't know html very well, but CI can do it all for me", what would your reaction be? Would you think someone was obnoxious because they recommended that I go learn html if I want to build web applications? And my genuine question is - why do you think that is different from relying on AR to write your queries?
[eluser]theprodigy[/eluser]
OK, I'll play ;-) I like AR because of it's flexibility and ease of reading. Plain and simple. It has nothing to do with lack of knowing how to do it outright. As far as my views go, they are mainly html. I do use some of the form helper stuff (form_dropdown and form_open), and a few other functions (anchor, base_url, site_url), but for the most part, it's mainly just html. And yes, if you came to me and said that you used CI because you didn't know how to do anything without it, I would agree with anyone that POLITELY advised you to learn stuff on your own as well. It would make you a better developer, and open more doors for you (maintain a site that isn't built with CI). I would not agree with anyone that scolded you, made fun of you, or just plain out ignored you for not knowing the basic way of doing things. Sometimes you just get thrown into the middle of something without the proper time to learn things right. I myself can only do basic CSS. Nothing special, nothing fancy. If it wasn't for google, there would be a couple extra white background, black text sites out there. ;-) And just for the record, there is a difference between USING AR and RELYING ON AR to build your queries. I personally USE AR. I do not rely on it. |
Welcome Guest, Not a member yet? Register Sign In |