Welcome Guest, Not a member yet? Register   Sign In
Newbie Q - controller/view code for mixed query
#31

[eluser]osci[/eluser]
I don't use html helper or form_helper too, except for the automatic production of the csfr form_open, base_url, anchor modified to suit my needs (I want empty title, it doesn't), but that's about it.

But jmadsen you made me think a little deeper and proved me wrong.

I should be using these helper functions more, I should eliminate all real html in fact. What would be the benefit? I could make a user edited configuration of css classes to be used in the views through the usual $extra param. Such a theme could be more configurable from a user perspective. So it opens new perspectives.

So the helpers will make my coding life even happier.

Interesting point don't you think?

And as theprodigy stated I don't have to rely on them. My front could still be the same if it didn't really fit the need to use them.
#32

[eluser]srpurdy[/eluser]
I don't really understand the argument lol. They both work! Smile

Personally I use AR mostly because the code looks much cleaner. In a big application things can get too messy in SQL. I like AR for that reason quite a lot. Smile

I normally don't keep repeating $this->db over and over though.

More like something like
Code:
$my_query = $this->db
->where('if needed')
->select('columns here')
->from('table')
->join('if needed')
->limit('if needed')
->order_by('if needed')
->group_by('if needed')
->get();
return $my_query;

Can also stick a sub query in there too if needed. Smile I just find this very clean to look at. Smile

Just my 2 cents worth. Smile
#33

[eluser]jmadsen[/eluser]
A fine answer.

I get a little heated on this subject, because I really do feel that in the web developer world today, there are a great many very good front-end people who are solid with php; will stay up nights and weekends to add ruby, python, haskel, whatever to their arsenal; use every minify/pixel reduction/rebuild the server with node.js/whatever trick to squeeze every last ounce of performance out of their site; and then happily write

Code:
$this->db->where('id', $id)->get('users')


against a 50 field users table so they can display "Hello, jmadsen" at the top of their page. And not know why it's bad, or care. And go teach all their friends to do it that way, because it's "clean and easy". Because for some reason, a lot of web developers don't seem to feel that sql is really a part of their job, or whatever.

It's nothing to do with AR or CodeIgniter. AR doesn't force you to make mistakes, but I think it lets you get away with too much and not have to go out and dig for better answers.

I would really like - and perhaps I'll suggest this somewhere, to see if others like the idea - is a separate area in the forums to deal with sql/data questions, so people can learn what is really going on behind their AR functions and how to write better sql code, with or without AR.
#34

[eluser]jmadsen[/eluser]
[quote author="osci" date="1308547829"]I don't use html helper or form_helper too, except for the automatic production of the csfr form_open, base_url, anchor modified to suit my needs (I want empty title, it doesn't), but that's about it.

But jmadsen you made me think a little deeper and proved me wrong.

I should be using these helper functions more, I should eliminate all real html in fact. What would be the benefit? I could make a user edited configuration of css classes to be used in the views through the usual $extra param. Such a theme could be more configurable from a user perspective. So it opens new perspectives.

So the helpers will make my coding life even happier.

Interesting point don't you think?

And as theprodigy stated I don't have to rely on them. My front could still be the same if it didn't really fit the need to use them.[/quote]

Yes, you could. You could do that with AR - it is one of the ways AR is good.

But that's an advanced topic, don't you think? It's not for the guy using it because he doesn't know any html.

somehow this got turned into "jmadsen thinks anyone who uses AR does so because they don't know sql". I never said anything of the sort.

I think it helps beginners too much, and keeps intermediates from getting better. People spend all their energy trying to cram every answer into AR, and so limit themselves to how well they know AR, rather than how well they know sql.

"To the man with a hammer, everything looks like a nail", so to speak.
#35

[eluser]Basketcasesoftware[/eluser]
How about showing how you would give an optimized version of your code sample? Personally, for that small a db I'd start by loading it into an array at the start of a user session and use that for my "db" until the session ends. Smile
[quote author="jmadsen" date="1308549658"]A fine answer.

I get a little heated on this subject, because I really do feel that in the web developer world today, there are a great many very good front-end people who are solid with php; will stay up nights and weekends to add ruby, python, haskel, whatever to their arsenal; use every minify/pixel reduction/rebuild the server with node.js/whatever trick to squeeze every last ounce of performance out of their site; and then happily write

Code:
$this->db->where('id', $id)->get('users')


against a 50 field users table so they can display "Hello, jmadsen" at the top of their page. And not know why it's bad, or care. And go teach all their friends to do it that way, because it's "clean and easy". Because for some reason, a lot of web developers don't seem to feel that sql is really a part of their job, or whatever.

It's nothing to do with AR or CodeIgniter. AR doesn't force you to make mistakes, but I think it lets you get away with too much and not have to go out and dig for better answers.

I would really like - and perhaps I'll suggest this somewhere, to see if others like the idea - is a separate area in the forums to deal with sql/data questions, so people can learn what is really going on behind their AR functions and how to write better sql code, with or without AR.[/quote]
#36

[eluser]theprodigy[/eluser]
Well, to be honest, I was one of the people that somewhat took a “jmadsen thinks anyone who uses AR does so because they don’t know sql” stand, and it may be just how I read your replies. When you ask questions like:
Quote:And my genuine question is - why do you think that is different from relying on AR to write your queries?
It doesn't leave any room whatsoever for the people that DO know sql, but prefer to use AR when they can, and it tends to push people into defensive mode.

As for:
Quote:I would really like - and perhaps I’ll suggest this somewhere, to see if others like the idea - is a separate area in the forums to deal with sql/data questions, so people can learn what is really going on behind their AR functions and how to write better sql code, with or without AR.
why not just build a tutorial site? I've seen quite a few CI tutorial screencast/article sites, why not have a SQL site? That way, you can be in control over what lessons get taught, as opposed to a designer starting a new thread, telling all their buddies it's ok to do:
Code:
$this->db->where('id', $id)->get('users')
to get the user's name.
#37

[eluser]jmadsen[/eluser]
"why not just build a tutorial site?"

Because I believe in Open Source, and the "bazaar" concept, and don't feel the need to "control" everything?

Because I think the community as a whole should be seeking the best answers and then propagating that information as best practices?

Because there are ALREADY sql tutorials out there - the issue here is getting people to go read them instead of relying too heavily on AR?

Whatever. Write your code however you like. If it doesn't work, try adding a left outer join to it.
#38

[eluser]Nick_MyShuitings[/eluser]
[quote author="osci" date="1308540960"]
Quote: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.

And this discussion is completely what I was hoping for... its the first time its ever occurred after one of my "I don't like AR abstraction" comments... (also, those underscore magic functions are very interesting... time to rerun through my list of "impossible" SQL to produce with AR.)
#39

[eluser]Nick_MyShuitings[/eluser]
[quote author="jmadsen" date="1308546152"]And my genuine question is - why do you think that is different from relying on AR to write your queries?[/quote]

I think you just properly worded and condensed my entire point which I've never been able to get out of my mind.

My "Beef" with things like AR, the html library, the form library (have to see if I can get CSRF without having to use it), the jquery helper etc... is that I find them limiting and they dumb the majority of us down...( those of us discussing this are the minority that are willing to open up the file and see how it works) . I've led teams as a PM who were forced to work in Drupal... and they get into the mindset that they can write drupal and forget how to write PHP. I am concerned that we might begin to foster that type of mindset here.
#40

[eluser]theprodigy[/eluser]
Quote:I am concerned that we might begin to foster that type of mindset here.

Please don't think that I am discounting your concerns as I say this, but....

This same idea of 'Hey, I can [insert action here], because of [insert tool here]' type mindset has been the foundation for many different trades.

Men can 'cook' because someone else built a microwave.
People can do math, because someone else built a calculator.
Businesses can guarantee over night delivery, because someone else built a plane.
Some people can program, because Google built a search engine. ;-)

Are these tools fostering the wrong mindset, or are they just tools that businesses can use to get ahead (other than the lack of cooking ;-) )?

When all is said and done, does it really matter whether I use
Code:
<form action="[insert segments here]" method="post">
or if I use
Code:
<?php echo form_open('[insert segments here']'); ?>

If they both output the same thing, then what does it matter?




Theme © iAndrew 2016 - Forum software by © MyBB