Welcome Guest, Not a member yet? Register   Sign In
My Codeigniter Observations
#11

[eluser]Newton Wagner[/eluser]
I agree with Negligence too.


@Edemilson,

It's not the same as $result_object(). Using fetch_object(), php generates a StdClass object, not a Costumer, as spib said.

I think both ways are ok, depends if you want to always work with objects or if you prefer handle arrays.

I prefer to work with objects.. there is what I don't like Helpers, because they are like the php core functions. Working that way will take more of the server (memory and load), but you will make code easier to understand.
#12

[eluser]James Spibey[/eluser]
Thanks to everyone for the comments. Like I said, this is the way I use codeigniter and it works for me. I think the reason I like everything to be in objects is because in my day job I write enterprise apps using object oriented design and so that's the way I think. As always YMMV.

Cheers

James
#13

[eluser]codex[/eluser]
Spib, please read this post: http://ellislab.com/forums/viewthread/69576/
#14

[eluser]Chris Newton[/eluser]
I really like the idea of validating at the model level. I currently validate at the controller level and it's pretty annoying having duplicate code here and there for similar operations. If anyone would be interested in posting an example model with validation built in & related controller, that'd be awesome.... I'd certainly appreciate it. I could probably figure it out with enough head pounding, but I'd rather stand on the shoulders of giants. Smile
#15

[eluser]Armorfist[/eluser]
Really nice post / responses.
I think the modified exceptions library should definitely go to the CI wiki, maybe even implemented in the upcoming releases of CI.
#16

[eluser]dcheslow[/eluser]
Transferring the data from a model to a library class seems like an extra (and often unnecessary) step.

I take a slightly different approach to models than some. Don't get me wrong, I am a HUGE fan of OOP... I just think it should be used in ways that make sense.

I picked this trick up during my days programming ColdFusion using Reactor and it still serves me well. It's a separation of models into Gateways and Records. Every table in the DB has both a Record and a Gateway.

Functions in a Record always return a single row of data. So I use something like

Code:
$thiscustomer = $this->customerrecord->get($id);
echo $thiscustomer->lastname;

Functions in a Gateway always return a resultset of DB rows. So I use it like

Code:
$allcustomers = $this->customergateway->get();
foreach($allcustomers->result() as $thiscustomer) { echo $thiscustomer->lastname;}

My base model classes (Record and Gateway) have default behaviour (Select *...) for methods like get() and insert() and delete(). The subclasses (like CustomerRecord) have the methods/functions that are particular to that Class of object.

I've found this arrangement of code makes it very easy to find the code that I'm looking for and uses a nice, clean syntax... your mileage may vary.

=dave=
#17

[eluser]Jopr[/eluser]
@beren

While working with your MY_Exception class (which is great btw!) I found a security problem.

When a route is not found a 404 will be returned using the exception class. The problem with this is that the config files are not loaded yet. PHP asumes that the constant is 'true' en a backtrace is printed below the 404. The solution is simple. Add the defined() statement to the condition like below:

Code:
if (@defined(DEBUG_BACKTRACE) && DEBUG_BACKTRACE)
#18

[eluser]sl3dg3hamm3r[/eluser]
I think Spib's input about proper encapsulation, or let's say, a domain model is spot on. Of course, if you have a simple Web-Application with a few tables and not much business-logic going on, you might overcomplicate things like that.
But I just recently developed a shop with very specific backend, where the products are assembled with many different single items, I'd wish afterwards I had implemented a proper domain model. I ended up with a quite complicated associative array for the final order. Sure, it also works like that, but it has reached a complexity where I would go more into enterprise patterns and put it into a domain model, maybe even garnished with some data access objects, which keeps everything independent from the persistent layer.

Well, interesting thread anyhow, keep going Smile




Theme © iAndrew 2016 - Forum software by © MyBB