前提・実現したいこと
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)
あなたの回答
tips
プレビュー