Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7171471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:25:15+00:00 2026-05-28T15:25:15+00:00

how can I access any table from database in my model? For example, I

  • 0

how can I access any table from database in my model?

For example, I have Indexcontroller and code inside it:

$results = $this->Index->query("SELECT COUNT(*) FROM my_own_table");


Error: Database table indices for model Index was not found.

So, as I understand, I can access only table with naming related to model/controller name. But what to do if I can’t modify the table naming and I want to access it’s data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:25:16+00:00Added an answer on May 28, 2026 at 3:25 pm

    You’re not limited to using a model that’s directly associated with your controller (this is just default behaviour); you can use any model.

    To achieve what you want, create a new model for this table, eg. MyOwnTable, and in your controller, you can add this property to the class:

    public $uses = array('Index', 'MyOwnTable');
    

    Now you can access MyOwnTable using CakePHP’s built in ActiveRecord functionality:

    $results = $this->MyOwnTable->find('count');
    

    If you have other tables you want to access, simply create models for those and add them to the $uses property. (You can also use $this->loadModel('Model') inside the action if you prefer).

    If you have a table name that isn’t very readable (eg. my_tb_own_1_x or some such), you can call the model class something human readable (eg. MyTable), and add the $useTable property to the model:

    public $useTable = 'my_tb_own_1_x';
    /* and change the default primary key if you have an unusual one */
    public $primaryKey = 'my_tb_own_1_x_idx_pk';
    

    See the CakePHP manual for more info on how to change default model and controller behaviour:

    1.3 – Model Attributes

    2.0 – Model Attributes

    1.3 – Controller Attributes

    2.0 – Controller Attributes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way i can access the page object from within the global.asax
I can access the database either from a .NET program (using ODBC) or through
I have configured spring security core plugin using requestmap table inside the database.. Now
I have a database with a table users. I generate the EF .edmx from
Are there any .NET-specific tools out there that can parse / access the elementary
Is there any really low level programming language that can get access the memory
Is there any way that I can programmatically create (and I guess access) hidden
How can I access dynamically properties from a generated LINQ class ? Cause I
I want to select data from a database table that is not part of
I have a fairly large EF4 model, using POCO code gen. I've got lots

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.