Can I use one controller with two or more models?

I have a really big book database table which has millions of rows.

Considering performance, I divided it into several smaller tables.

But how can i use all these tables in one ‘book’ controller?

I do not exactly what you finally want to do. But generally you can use every model you like in every controller you want. One point would be using the relations function in your "main model" … everything else has to be written manually in your "main controller" you can reach the models via


… also check out the blog tutorial there is an example for this issue, they use the comment model in the post controller if i remember it correctly.

I know what you mean, but a post table and a comment table are related with a foreign key in the tutorial example. What I want is several parallel tables in one controller.

For example, I have tbl_book_1, tbl_book_2, tbl_book_3, database, and contents in these tables are all needed in one controller- If I select rows where bookid=1****(url will be like: /book/view/1*****), the controller will use the tbl_book_1, while i select rows where bookid=2****(/book/view/2*****), the controller will reference tbl_book_2 …

I’ll try the method you told me.

It doesn’t look a great solution.

You will have 3 tables with the same fileds? And if you have to sort and page, how will you do?

Millions of rows doesn’t mean that you can’t use the entire table as-is.

Page it, and you’ll never have to grab more than page_size number of rows at any time while browsing it.

Dividing it will only make performance worse, AFAIK. ;)

The only time you’d want to divide a table like that is when you archive old stuff.

I agree, if you’re having performance issues then I would look at your indexes and the queries you are performing on the table. It’s probably that the table is failing to use an index and so doing a file search. The DESCRIBE SELECT… syntax should assist in this.

Thank you guys very much.

I think I misunderstood what is dividing tables for. :)

Selecting a row with index performances well,but when i use

select * from tbl_book limit (a,<img src='' class='bbc_emoticon' alt='B)' />

it will get very slow as ‘a’ gets larger.

Are there any way to deal with this?

Check if your DBMS supports table partitioning. It can be used to split up large tables and can improve performance when used properly, without the troubles caused by the multiple-table approach.