質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

0回答

3179閲覧

cakePHP4 _ Table class for alias (table_name)users could not be found. error

swanne

総合スコア2

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2021/02/28 09:03

前提・実現したいこと

i continued PHP(CakePHP) study hard
but can not do DB table insert operating.
in this code : TableRegistry::get('users')
'users' is (my_app)database table name.
how can i do make alias 'users'?
and found?
somebody help me please..

発生している問題・エラーメッセージ

Table class for alias users could not be found. Cake\ORM\Exception\MissingTableClassException CORE\src\ORM\Locator\TableLocator.php $message = '`' . $message . '`'; if (strpos($message, '\') === false) { $message = 'for alias ' . $message; } throw new MissingTableClassException([$message]); } if (empty($options['connection'])) { if (!empty($options['connectionName'])) {

該当のソースコード

## templates/User/add.php-------------------------------- <?php echo $this->Form->create(NULL,array('url'=>'/users/add')); echo $this->Form->control('username'); echo $this->Form->control('password'); echo $this->Form->button('Submit'); echo $this->Form->end(); ?> ## routers.php------------------------------------------- // csrf middleware is not problem. $routes->scope('/', function (RouteBuilder $builder) { $builder->connect('/users/add', ['controller' => 'Users', 'action' => 'add']); $builder->fallbacks(); }); ## UsersController.php---------------------------------- <?php namespace App\Controller; use App\Controller\AppController; use Cake\ORM\TableRegistry; use Cake\Datasource\ConnectionManager; use Cake\Auth\DefaultPasswordHasher; class UsersController extends AppController { public function add() { if($this->request->is('post')) { $username = $this->request->getData('username'); $hashPswdObj = new DefaultPasswordHasher; $password = $hashPswdObj->hash($this->request->getData('password')); //TableRegistry :: config ( 'users' , [ 'table' => 'users' ]); //$user_table = TableRegistry::getTableLocator()->get('Users', $config); $users_table = TableRegistry::get('users'); //maybe, here is problem $users = $users_table->newEntity($this->request->getData()); $users->username = $username; $users->password = $password; $this->set('users', $users); if($users_table->save($users)) echo "User is added."; } } } ?>

試したこと

i reading cakePHP COOKBOOK or site.
and great Japanese site^-^;;
but it's impossible

補足情報(FW/ツールのバージョンなど)

cakePHP4 / php7.4 / mysql / apache /
(xampp_xampp-portable-windows-x64-7.4.14-1-VC15)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2021/02/28 09:11

日本語サイトにあえて英語で質問するのはどういう経緯かは気になる。 StackOverflowとかあるのですけど。
swanne

2021/02/28 09:34

because i believe, Japanese more high quality answer to me. and i wonder Japanese with conversation.
m.ts10806

2021/02/28 09:38

矛盾がありそうな返答ですね・・・。 仕様としても「世界中から得られる可能性が高い」という点からも StackOverflow本体のほうがmore high qualityだと私は思います。 teratailよりもスタートが何年も早く、よりシステム的に高いとも思います。
swanne

2021/02/28 09:45

hmm.. okay! your answer is right. but i just want help, here and there ^^ could you please help me?
m.ts10806

2021/02/28 09:59

エラーの意味は理解されてますか? アドバイスをしようにも「エラーの通り」くらいになります。
swanne

2021/03/01 04:13

thanks!! i have serious headache.. so sorry about late. may be, i think at TableRegistry::(table_name), (table_name) will make alias. my table_name is 'users' however trouble name: Table class for alias (table_name)users could not be found. i will waiting your advice^-^
swanne

2021/03/01 04:24

when i was young, want be Japanese! but it's not possible. not enough money, i'm older. i want Japanese friends! even only net friends, it's alright~
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問