[eluser]Todd Lynch[/eluser]
I am in the process of building a small CMS (will be open source if I ever finish it!) using CodeIgniter along with Active Records.
There is a primary table that stores the main data for each piece of content, and then there are ancillary tables that store specific data about a given piece of content when needed.
For example, there is a metadata table that stores Keywords and Descriptions. Each piece of content could have 0 or 1 rows in the metadata table, depending on if it is needed for that piece of content.
Other ancillary tables store tags, categories, slideshows, etc... each ancillary table has a corresponding controller, model, and view that is used to manage it through an admin panel.
The admin section is working well.
I am now developing a framework for querying the data on the front end. I have no difficult manually writing the queries with Active Records that pull back the proper content. For example, I can write a query that returns all content that has a row in the tags table with a given tag, or all content that is in a given category. What I would like to do, is encapsulate the query building logic into the appropriate models.
I do not believe this is correct, but I would like to be able to do something along these lines:
Code:
$this->db->select();
$this->db->from("content");
$this->tags_model->has_tag("HELP", $this->db);
$this->category_model->has_primary_category("Code Igniter", $this->db);
This would be great because i could write functions like:
Code:
$this->tags_model->has_any_tag(array("help","technology"), $this->db);
$this->tags_model->has_all_tags(array("php","html"), $this->db);
In the model, and then they would always be available. The functions on the models know how to add all of the required joins and wheres to properly build the query. Can I pass $this->db around? Do I need to? Should I move up a level and extend CI_DB_active_record?
What is the proper architecture for a system like this?
Thanks is advance,
Todd Lynch