[eluser]Lister[/eluser]
Hi guys,
Just dipping my toe into CodeIgnitor. First time I've used a framework for web development and I'm running into a few queries regarding usage.
It is my understanding that Models should be used to represent data objects, so I have a "user" model which represents a user, and has members for name etc, and also functions for DB saving/loading.
My problem comes when I want to send this object to the client via JSON. Because my user object derives from Model, there is ten tonnes of crap in there that I don't want encoding.
eg, the JSON ends up looking like this:
Code:
[{"ID":"1","name":"fred","email":"","type":"0","_parent_name":"User","_ci_scaffolding":false,"_ci_scaff_table":false,"config":{"config":{"base_url":"http:\/\/blah.com\/","index_page":"index.php","uri_protocol":"AUTO","url_suffix":"","language":"english","charset":"UTF-8","enable_hooks":false,"subclass_prefix":"MY_","permitted_uri_chars":"a-z 0-9~%.:_\\-","enable_query_strings":false,"controller_trigger":"c","function_trigger":"m","directory_trigger":"d","log_threshold":0,"log_path":"","log_date_format"
etc etc
Am I going about this the right way? ie Am I using models correctly or should my data objects be seperate?
If I am using it correctly how do you guys encode to JSON? I could easily write a member function to spit out the required encoding, but it seems a bit silly when json_encode() already exists.
Cheers,
Lister