1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[ZF3] ディレクトリ整理用メモ

Last updated at Posted at 2019-06-30

目的

ZF3の最終的に行きつくところが英語ドキュメントになるため作成

インストール

$ cd /var/www/html
$ sudo su vagrant
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
$ /usr/local/bin/composer update
$ composer create-project zendframework/zend-expressive-skeleton skeleton

./vendorが生成されます。
※ composer install やupdateでWarning等が出る場合は、新規ディレクトリを作ってcomposer.jsonをそこに置いてディレクトリ権限なども確認してcomposerを実行、生成できた./vendorは移動なりコピーなりする

/vendor 初期状態

ここに自分が使いたいZendライブラリや自身のライブラリをcomposer.jsonに書いてcomposer updateをかける


-rw-r--r--.  1 root root  178 Jun 29 00:47 ./vendor/autoload.php

./vendor/bin:
total 0
lrwxrwxrwx. 1 root root 73 Jun 29 00:47 generate-deps-for-config-factory -> ../zendframework/zend-servicemanager/bin/generate-deps-for-config-factory
lrwxrwxrwx. 1 root root 67 Jun 29 00:47 generate-factory-for-class -> ../zendframework/zend-servicemanager/bin/generate-factory-for-class
lrwxrwxrwx. 1 root root 56 Jun 29 00:47 templatemap_generator.php -> ../zendframework/zend-view/bin/templatemap_generator.php
lrwxrwxrwx. 1 root root 55 Jun 29 00:47 zf-development-mode -> ../zfcampus/zf-development-mode/bin/zf-development-mode

./vendor/composer:
total 84
-rw-r--r--. 1 root root   147 Jun 29 00:47 autoload_classmap.php
-rw-r--r--. 1 root root   149 Jun 29 00:47 autoload_namespaces.php
-rw-r--r--. 1 root root  1874 Jun 29 00:47 autoload_psr4.php
-rw-r--r--. 1 root root  1762 Jun 29 00:47 autoload_real.php
-rw-r--r--. 1 root root  4351 Jun 29 00:47 autoload_static.php
-rw-r--r--. 1 root root 13459 Jun 29 00:47 ClassLoader.php
-rw-r--r--. 1 root root 40820 Jun 29 00:47 installed.json
-rw-r--r--. 1 root root  1070 Jun 29 00:47 LICENSE

./vendor/container-interop:
total 0
drwxr-xr-x. 4 root root 100 Jun 29 00:47 container-interop

./vendor/psr:
total 0
drwxr-xr-x. 3 root root 88 Jun 29 00:47 container

./vendor/zendframework:
total 0
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-component-installer
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-config
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-escaper
drwxr-xr-x. 3 root root 155 Jun 29 00:47 zend-eventmanager
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-http
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-json
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-loader
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-modulemanager
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-mvc
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-router
drwxr-xr-x. 4 root root 104 Jun 29 00:47 zend-servicemanager
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-stdlib
drwxr-xr-x. 3 root root  93 Jun 29 00:47 zend-uri
drwxr-xr-x. 5 root root 212 Jun 29 00:47 zend-validator
drwxr-xr-x. 5 root root 191 Jun 29 00:47 zend-view

./vendor/zfcampus:
total 0
drwxr-xr-x. 4 root root 173 Jun 29 00:47 zf-development-mode

skeletonをインストールしたディレクトリ内

[root@localhost skeleton]# ls -ltr
total 104
-rw-r--r--. 1 root root  2378 Jun 29 00:47 CONDUCT.md
-rw-r--r--. 1 root root  6878 Jun 29 00:47 CONTRIBUTING.md
-rw-r--r--. 1 root root  6526 Jun 29 00:47 README.md
-rw-r--r--. 1 root root  1517 Jun 29 00:47 LICENSE.md
-rw-r--r--. 1 root root   398 Jun 29 00:47 Dockerfile
-rw-r--r--. 1 root root  1828 Jun 29 00:47 Vagrantfile
-rw-r--r--. 1 root root   504 Jun 29 00:47 TODO.md
-rwxr-xr-x. 1 root root  1282 Jun 29 00:47 composer.json
drwxr-xr-x. 3 root root    19 Jun 29 00:47 data
-rw-r--r--. 1 root root    91 Jun 29 00:47 docker-compose.yml
drwxr-xr-x. 3 root root    25 Jun 29 00:47 module
-rw-r--r--. 1 root root   253 Jun 29 00:47 phpunit.xml.dist
-rw-r--r--. 1 root root   997 Jun 29 00:47 phpcs.xml
drwxr-xr-x. 6 root root   103 Jun 29 00:47 public
drwxr-xr-x. 8 root root   126 Jun 29 00:47 vendor
-rw-r--r--. 1 root root 42237 Jun 29 00:47 composer.lock
drwxr-xr-x. 3 root root   113 Jun 29 03:56 config

 
以下URLを叩く、
Apacheは起動してあることが前提
systemctl restart httpd
http://192.168.33.10/skeleton/public/

image.png

ルーティングについて

module/Application/config/module.config.php

コントローラーとビューを紐づけるためのもの

return [
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'test' => [
               'type'    => Segment::class,
               'options' => [
                   'route'    => '/test[/:action]',
                   'defaults' => [
                      'controller' => Controller\TestController::class,
                      'action'     => 'index',
                   ],
               ],
            ],
        ],
   ],
   // コントローラー追加した分だけ追加
    'controllers' => [
        'factories' => [
            Controller\IndexController::class => InvokableFactory::class,
            ControllerTestController::class => InvokableFactory::class,
        ],
    ],
]

ビュー側

module/Application/view/application/index/index.phtml

落としてきたばかりなので当然デフォルトサンプル


<div class="jumbotron">
    <h1>Welcome to <span class="zf-green">Zend Framework</span></h1>

    <p>
        Congratulations! You have successfully installed the
        <a href="https://github.com/zendframework/ZendSkeletonApplication" target="_blank">ZF Skeleton Application</a>.
        You are currently running Zend Framework version <?= \Application\Module::VERSION ?>.
        This skeleton can serve as a simple starting point for you to begin
        building your application on ZF.
    </p>

    <p><a class="btn btn-success btn-lg" href="https://github.com/zendframework/zendframework" target="_blank">Fork Zend Framework on GitHub &raquo;</a></p>
</div>

<div class="row">

    <div class="col-md-4">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">Follow Development</h3>
            </div>
            <div class="panel-body">
                <p>
                    Zend Framework is under active development. If you are
                    interested in following the development of ZF, you can check
                    <a href="http://framework.zend.com/blog/">ZF dev blog</a>,
                    and <a href="https://github.com/issues?utf8=%E2%9C%93&amp;q=is:issue+org:zendframework">ZF issue tracker</a>
                    (link requires a GitHub account). This is a great resource
                    for staying up to date with the latest developments!
                </p>

                <p><a class="btn btn-success pull-right" href="http://framework.zend.com/" target="_blank">ZF Development Portal &raquo;</a></p>
            </div>
        </div>
    </div>
・・・略

module/Application/view/application/test/index.phtml

テスト用画面



<html>
<head>
<meta charset="utf-8">
<title>Sample</title>
</head>
<body>
<h1>hello world</h1>
<input type="text" value="<?php
    date_default_timezone_set('Asia/Tokyo');
    $now = time();
    $now = date('Y/m/d H:i:s');
    echo $now;
 ?>">
</body>
</html>

つづく

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?