Welcome Guest, Not a member yet? Register   Sign In
MY_Model base CRUD
#11

[eluser]Staedtler[/eluser]
hi, liked the model extension, but it got some issues after loading the model that extend it i cannot load any other library..? always show some error in CI Library. But if i load it before the model it's no problem.

i use CI 1.7.2.
#12

[eluser]Mark Croxton[/eluser]
Weird; I have noticed some strange behaviour with CI's load class before (when using other libraries) - specifically, I've found you need to load libraries in a certain order - but I've never managed to track down why.

Could you let me know the error message and the version of PHP you are using?

Cheers,

Mark
#13

[eluser]Unknown[/eluser]
Hello Mark.
First of all, congratulations for your work. Smile

I'm new in CI development and i found your CRUD solution very attractive. I am developing a integration software in PHP for vTiger and SAGE Line50 integration.

Using your CRUD model, how can i work on it with two databases? Could you show me some short examples of the procedure?

Waiting your reply.
Best regards,
João Dias
#14

[eluser]Mark Croxton[/eluser]
Good question!

Assuming you have configured your database groups in application/config/database.php, you could add this to beginning of the model constructor:

Code:
$this->db = $this->load->database('my_database_group', TRUE);
#15

[eluser]Mark Croxton[/eluser]
Updated to v1.0.3 (see first post)
#16

[eluser]liri[/eluser]
Mark,

In a simple model I'm just doing in the constructor after calling the parent constructor
Code:
$this->load_table('user');

And in the controller performing:
Code:
$res = $this->users_model->get();

Which results in an error:
ErrorException [ Fatal Error ]: Error Number: 1096 / No tables used / SELECT *


Why is this happening?


On a side note, is it just me or is your MY_Model is considerably slower than normal due to it's show_columns operations and other similar methods?


Thanks,
Liran.
#17

[eluser]Mark Croxton[/eluser]
Hi liri,

get() requires at least one argument (an array of options). It doesn't by default do SELECT * on the current table. Would be very easy to add that to the function if you wanted it.

show_columns will add a small overhead which is why I would recommend using a cache library such as MP Cache in the way I described above.
#18

[eluser]liri[/eluser]
Hey Mark,

Thanks for the prompt reply.

What I do not require any where conditions or don't want to specify all the fields to get one by one,
assuming I just want them all. As would be with the default AR pattern in CI:
$this->db->from('user')->get();


Also, could you provide links/resources for actual usage examples which are using your model
in actual applications?
#19

[eluser]liri[/eluser]
Ahh, I see now in the code the following:
if ($options['fields'] == "*")
Kind of missed it before.


Though I'm also seeing the use of default option values (which I think is smart to do):
$options = $this->_default(
array(
'fields' => array($this->$table->pk),
'sort' => 'asc',
'order_by' => $this->$table->alias.'.'.$this->$table->pk,
'offset' => 0,
'distinct' => true,
'join' => 'left'
), $options);

So I'm not sure why it requires it anyway.
#20

[eluser]Mark Croxton[/eluser]
You'll find this near the top of the function:

if (count($args)>0)
{

...
}

Add an else{} condition to handle the 'no arguments' case.

Actual usage - so far I've used it for one project, a sizable extranet with 39 tables. The complexity of this project meant I was able to really test and refine the code. What I would say is that some of the usefulness of the model will only become apparent to you from actual use and from reading the code closely.

I'd love to hear from anyone else using it in their projects.




Theme © iAndrew 2016 - Forum software by © MyBB