0

同じコントローラーと異なるコントローラーで CakePHP 3.0 にクエリを記述する方法。

ユーザーコントローラーで $data = $this->Users->find('all'); pr($データ);

出力:

Cake\ORM\Query Object
(
    [_hasFields:protected] => 
    [_autoFields:protected] => 
    [_hydrate:protected] => 1
    [_counter:protected] => 
    [_eagerLoader:protected] => 
    [_beforeFindFired:protected] => 
    [_connection:protected] => Cake\Database\Connection Object
        (
            [_config:protected] => Array
                (
                    [driver] => Cake\Database\Driver\Mysql
                    [persistent] => 
                    [host] => localhost
                    [username] => root
                    [password] => 
                    [database] => lenders
                    [encoding] => utf8
                    [timezone] => UTC
                    [cacheMetadata] => 1
                    [log] => 
                    [quoteIdentifiers] => 
                    [name] => default
                )

            [_driver:protected] => Cake\Database\Driver\Mysql Object
                (
                    [_baseConfig:protected] => Array
                        (
                            [persistent] => 1
                            [host] => localhost
                            [username] => root
                            [password] => 
                            [database] => cake
                            [port] => 3306
                            [flags] => Array
                                (
                                )

                            [encoding] => utf8
                            [timezone] => 
                            [init] => Array
                                (
                                )

                        )

                    [_config:protected] => Array
                        (
                            [driver] => Cake\Database\Driver\Mysql
                            [persistent] => 
                            [host] => localhost
                            [username] => root
                            [password] => 
                            [database] => lenders
                            [encoding] => utf8
                            [timezone] => UTC
                            [cacheMetadata] => 1
                            [log] => 
                            [quoteIdentifiers] => 
                            [name] => default
                            [port] => 3306
                            [flags] => Array
                                (
                                )

                            [init] => Array
                                (
                                )

                        )

                    [_autoQuoting:protected] => 
                    [_startQuote:protected] => `
                    [_endQuote:protected] => `
                    [_schemaDialect:protected] => Cake\Database\Schema\MysqlSchema Object
                        (
                            [_driver:protected] => Cake\Database\Driver\Mysql Object
 *RECURSION*
                        )

                    [_connection:protected] => PDO Object
                        (
                        )

                )

            [_transactionLevel:protected] => 0
            [_transactionStarted:protected] => 
            [_useSavePoints:protected] => 
            [_logQueries:protected] => 1
            [_logger:protected] => DebugKit\Database\Log\DebugLog Object
                (
                    [_queries:protected] => Array
                        (
                        )

                    [_logger:protected] => 
                    [_connectionName:protected] => default
                    [_totalTime:protected] => 0
                    [_totalRows:protected] => 0
                )

            [_schemaCollection:protected] => Cake\Database\Schema\CachedCollection Object
                (
                    [_cache:protected] => _cake_model_
                    [_connection:protected] => Cake\Database\Connection Object
 *RECURSION*
                    [_dialect:protected] => Cake\Database\Schema\MysqlSchema Object
                        (
                            [_driver:protected] => Cake\Database\Driver\Mysql Object
                                (
                                    [_baseConfig:protected] => Array
                                        (
                                            [persistent] => 1
                                            [host] => localhost
                                            [username] => root
                                            [password] => 
                                            [database] => cake
                                            [port] => 3306
                                            [flags] => Array
                                                (
                                                )

                                            [encoding] => utf8
                                            [timezone] => 
                                            [init] => Array
                                                (
                                                )

                                        )

                                    [_config:protected] => Array
                                        (
                                            [driver] => Cake\Database\Driver\Mysql
                                            [persistent] => 
                                            [host] => localhost
                                            [username] => root
                                            [password] => 
                                            [database] => lenders
                                            [encoding] => utf8
                                            [timezone] => UTC
                                            [cacheMetadata] => 1
                                            [log] => 
                                            [quoteIdentifiers] => 
                                            [name] => default
                                            [port] => 3306
                                            [flags] => Array
                                                (
                                                )

                                            [init] => Array
                                                (
                                                )

                                        )

                                    [_autoQuoting:protected] => 
                                    [_startQuote:protected] => `
                                    [_endQuote:protected] => `
                                    [_schemaDialect:protected] => Cake\Database\Schema\MysqlSchema Object
 *RECURSION*
                                    [_connection:protected] => PDO Object
                                        (
                                        )

                                )

                        )

                )

        )

    [_type:protected] => select
    [_parts:protected] => Array
        (
            [delete] => 1
            [update] => Array
                (
                )

            [set] => Array
                (
                )

            [insert] => Array
                (
                )

            [values] => Array
                (
                )

            [select] => Array
                (
                )

            [distinct] => 
            [modifier] => Array
                (
                )

            [from] => Array
                (
                )

            [join] => Array
                (
                )

            [where] => 
            [group] => Array
                (
                )

            [having] => 
            [order] => 
            [limit] => 
            [offset] => 
            [union] => Array
                (
                )

            [epilog] => 
        )

    [_dirty:protected] => 1
    [_resultDecorators:protected] => Array
        (
        )

    [_iterator:protected] => 
    [_valueBinder:protected] => 
    [_functionsBuilder:protected] => 
    [_useBufferedResults:protected] => 1
    [_typeMap:protected] => Cake\Database\TypeMap Object
        (
            [_defaults:protected] => Array
                (
                    [Users.id] => integer
                    [id] => integer
                    [Users.username] => string
                    [username] => string
                    [Users.password] => string
                    [password] => string
                    [Users.first_name] => string
                    [first_name] => string
                    [Users.last_name] => string
                    [last_name] => string
                    [Users.email] => string
                    [email] => string
                    [Users.status] => integer
                    [status] => integer
                    [Users.group_id] => integer
                    [group_id] => integer
                    [Users.created_by] => integer
                    [created_by] => integer
                    [Users.created] => datetime
                    [created] => datetime
                    [Users.modifiedmodified] => datetime
                    [modifiedmodified] => datetime
                    [Users.modified_by] => integer
                    [modified_by] => integer
                    [Users.last_login] => datetime
                    [last_login] => datetime
                    [Users.login_attempts] => integer
                    [login_attempts] => integer
                    [Users.unlocktime] => datetime
                    [unlocktime] => datetime
                )

            [_types:protected] => Array
                (
                )

        )

    [_repository:protected] => App\Model\Table\UsersTable Object
        (
            [_table:protected] => users
            [_alias:protected] => Users
            [_connection:protected] => Cake\Database\Connection Object
                (
                    [_config:protected] => Array
                        (
                            [driver] => Cake\Database\Driver\Mysql
                            [persistent] => 
                            [host] => localhost
                            [username] => root
                            [password] => 
                            [database] => lenders
                            [encoding] => utf8
                            [timezone] => UTC
                            [cacheMetadata] => 1
                            [log] => 
                            [quoteIdentifiers] => 
                            [name] => default
                        )

                    [_driver:protected] => Cake\Database\Driver\Mysql Object
                        (
                            [_baseConfig:protected] => Array
                                (
                                    [persistent] => 1
                                    [host] => localhost
                                    [username] => root
                                    [password] => 
                                    [database] => cake
                                    [port] => 3306
                                    [flags] => Array
                                        (
                                        )

                                    [encoding] => utf8
                                    [timezone] => 
                                    [init] => Array
                                        (
                                        )

                                )

                            [_config:protected] => Array
                                (
                                    [driver] => Cake\Database\Driver\Mysql
                                    [persistent] => 
                                    [host] => localhost
                                    [username] => root
                                    [password] => 
                                    [database] => lenders
                                    [encoding] => utf8
                                    [timezone] => UTC
                                    [cacheMetadata] => 1
                                    [log] => 
                                    [quoteIdentifiers] => 
                                    [name] => default
                                    [port] => 3306
                                    [flags] => Array
                                        (
                                        )

                                    [init] => Array
                                        (
                                        )

                                )

                            [_autoQuoting:protected] => 
                            [_startQuote:protected] => `
                            [_endQuote:protected] => `
                            [_schemaDialect:protected] => Cake\Database\Schema\MysqlSchema Object
                                (
                                    [_driver:protected] => Cake\Database\Driver\Mysql Object
 *RECURSION*
                                )

                            [_connection:protected] => PDO Object
                                (
                                )

                        )

                    [_transactionLevel:protected] => 0
                    [_transactionStarted:protected] => 
                    [_useSavePoints:protected] => 
                    [_logQueries:protected] => 1
                    [_logger:protected] => DebugKit\Database\Log\DebugLog Object
                        (
                            [_queries:protected] => Array
                                (
                                )

                            [_logger:protected] => 
                            [_connectionName:protected] => default
                            [_totalTime:protected] => 0
                            [_totalRows:protected] => 0
                        )

                    [_schemaCollection:protected] => Cake\Database\Schema\CachedCollection Object
                        (
                            [_cache:protected] => _cake_model_
                            [_connection:protected] => Cake\Database\Connection Object
 *RECURSION*
                            [_dialect:protected] => Cake\Database\Schema\MysqlSchema Object
                                (
                                    [_driver:protected] => Cake\Database\Driver\Mysql Object
                                        (
                                            [_baseConfig:protected] => Array
                                                (
                                                    [persistent] => 1
                                                    [host] => localhost
                                                    [username] => root
                                                    [password] => 
                                                    [database] => cake
                                                    [port] => 3306
                                                    [flags] => Array
                                                        (
                                                        )

                                                    [encoding] => utf8
                                                    [timezone] => 
                                                    [init] => Array
                                                        (
                                                        )

                                                )

                                            [_config:protected] => Array
                                                (
                                                    [driver] => Cake\Database\Driver\Mysql
                                                    [persistent] => 
                                                    [host] => localhost
                                                    [username] => root
                                                    [password] => 
                                                    [database] => lenders
                                                    [encoding] => utf8
                                                    [timezone] => UTC
                                                    [cacheMetadata] => 1
                                                    [log] => 
                                                    [quoteIdentifiers] => 
                                                    [name] => default
                                                    [port] => 3306
                                                    [flags] => Array
                                                        (
                                                        )

                                                    [init] => Array
                                                        (
                                                        )

                                                )

                                            [_autoQuoting:protected] => 
                                            [_startQuote:protected] => `
                                            [_endQuote:protected] => `
                                            [_schemaDialect:protected] => Cake\Database\Schema\MysqlSchema Object
 *RECURSION*
                                            [_connection:protected] => PDO Object
                                                (
                                                )

                                        )

                                )

                        )

                )

            .........

Cakephp 3.x で mysql クエリを作成する方法と、Model をその場でロードしてデータを選択する方法を教えてください。

4

1 に答える 1