• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Meet CodeIgniter MY_Model

#21
Thanks for sharing . i was using Jamies my model for months now .
Reply

#22
Added paginate() method. This one will allow you to paginate the results. You can do this by simply changing get_all() method with paginate() method. The paginate() method can receive up to three parameters:


- first paramater, which is optional (default is set to 10) is the number of rows per page;
- second parameter, which is optional (default is set to NULL), is the total of rows;
- the third parameter, which is also optional (default is set to 1) is the page you want to get.

If you only passed the first parameter, the page number will be retrieved from the URL (the last segment of the page). If you didn't pass the second parameter you will only be able to output the previous and next page, without links to all the pages.

Example:

PHP Code:
$total_posts $this->post_model->count(); // retrieve the total number of posts
$posts $this->post_model->paginate(10,$total_posts); // paginate with 10 rows per page
echo $this->post_model->all_pages// will output links to all pages like this model: "< 1 2 3 4 5 >". It will put a link if the page number is not the "current page"
echo $this->post_model->previous_page// will output link to the previous page like this model: "<". It will only put a link if there is a "previous page"
echo $this->post_model->next_page// will output link to the next page like this model: ">". It will only put a link if there is a "next page" 
Reply

#23
How about implementing $this->db->like() into this great model?
Reply

#24
Do I understand correctly that My_Model should not be asked to handle relationships on insert or update operations?

Something like

$this->article_model->with_authors()->insert($data);

with_authors() being a many-to-many relationship, and where $data would be all the data of the article, including the author information?

If I am correct, is there a piece of code that could handle such inserts?
Reply

#25
(09-25-2016, 01:06 AM)dgvirtual Wrote: Do I understand correctly that My_Model should not be asked to handle relationships on insert or update operations?

Something like

$this->article_model->with_authors()->insert($data);

with_authors() being a many-to-many relationship, and where $data would be all the data of the article, including the author information?

If I am correct, is there a piece of code that could handle such inserts?

MY_Model can be asked whatever you want it to ask, as long as it's not "too applied" to a certain table. If anything is possible, there could be a piece of code that could handle what you asked. The internet is huge. On the other hand, if there isn't, you can create that piece of code and do a pull request on my MY_Model, if you wish to. Or you can use an ORM...

But from your question, what I actually understand is the fact that you think that MY_Model is a paradigm. MY_Model is not a paradigm, it's only a tool that can help you do things faster. For more complex things like what you asked you should simply not use MY_Model's methods, and just get your hands wet with the query builder.
Reply

#26
(09-27-2016, 11:26 PM)Avenirer Wrote: But from your question, what I actually understand is the fact that you think that MY_Model is a paradigm. MY_Model is not a paradigm, it's only a tool that can help you do things faster. For more complex things like what you asked you should simply not use MY_Model's methods, and just get your hands wet with the query builder.
Thank you for explanation. I could gather it up from the quite detailed information in the readme. I was just wondering, maybe there is more to it than is explicitly documented. Smile
==

Donatas G.
Reply

#27
Usually when I'm creating some new features, I mention them in the tutorial or in the readme. I don't like to do things and not be proud of them (as in "brag about them" in the readme...).  Big Grin
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.