カテゴリー: 未分類

  • HTTPメソッド

    HTTPメソッドってのがあって、GET,POSTはよく使ってたんだが、それ以外にも結構あるのね。

    GET
    HEAD
    POST
    PUT
    DELETE
    OPTIONS
    TRACE
    CONNECT
    PATCH
    LINK
    UNLINK

    さらに、データベース用に

    PROPFIND
    PROPPATCH
    MKCOL
    COPY
    MOVE
    LOCK
    LINK
    UNLINK

    とか。
    そう言われてみたら、HEADとかも使ってたな。
  • SymfonyとXAMPPの共存

    Symfonyを試して”short_open_tag = Off”としたことで、XAMPPの表示がグダグダに。
    <? → <?php
    <?= → <?php echo
    と、置換する必要が。
    も~~~

  • icuuc46.dllが見つからない?

    xamppを起動して、apacheを起動すると、下のようなダイアログが連続で出てきて起動できない。

    httpd.exe – コンポーネントが見つかりません
    icuuc46.dll が見つからなかったため、このアプリケーションを開始できませんでした。アプリケーションをインストールし直すとこの問題は解決される場合があります。

    Warning
    PHP Startup: Unable to load dynamic library ‘X:xamppphpextphp_intl.dll’ – 指定されたモジュールが見つかりません。
    あれ?この前まで起動してたのに。何をした?

    とにかく、対策。
    “/xampp/php/icuuc46.dll”を”/xampp/apache/bin”にコピー。
    しかし、ダメ。
    結局”/xampp/php/icu**46.dll”を全てコピーして解消。
    ううむ。

  • Symfony2!!

    CakePHPをチョコっと触ったので、次はSymfony。

    PHP5.3.2以上に対応したバージョン2が最新らしい。

    下のページで、要求されている環境を確認。
    http://symfony.com/doc/current/reference/requirements.html

    下のページで、vendors付きのZIPファイルをダウンロードして解凍。
    http://symfony.com/download
    GITででも取れるけど、README.mdを読むと、あんまりお勧めしてないみたい。

    xampp/htdocs/に入れて、コマンドプロンプトで次を実行。
    xamppphpphp xampphtdocsSymfonyappcheck.php
    警告が3つ出たので、それぞれ処置を施す。
    [[WARNING]] Checking that the intl extension is available: FAILED
                *** Install and enable the intl extension (used for validators) ***
    php.iniに、次の行を追加。
    extension=php_intl.dll
    [[WARNING]] Checking that a PHP accelerator is installed: FAILED
                *** Install a PHP accelerator like APC (highly recommended) ***
    php.iniに、次の行を追加。
    extension=php_apc.dll
    次のページから、”php_apc-XXXXXXXX-X.X-nts-vc9-x86.zip”をダウンロードして、解凍して、xamppphpextフォルダにコピー。
    http://downloads.php.net/pierre/
    [[WARNING]] Checking that php.ini has short_open_tag set to off: FAILED
                *** Set short_open_tag to off in php.ini ***
    php.iniで、次のように編集。
    ;short_open_tag = On
    short_open_tag = Off
    あれ、タイムゾーンが違ってたので、ついでに編集。
    ; date.timezone = Europe/Berlin
    date.timezone = Asia/Tokyo
    タイムゾーンの文字列は、http://jp.php.net/manual/ja/timezones.asia.phpを参照。

    以上で、全てOKになったので、次のページで設定開始。
    http://localhost/Symfony/web/config.php

    最終的に次の設定ファイルができるっと。
    xampphtdocsSymfonyapp/config/parameters.ini

  • CakePHPの徳井くんと福田くん

    http://book.cakephp.org/2.0/ja/tutorials-and-examples/blog/blog.htmlの徳、、、チュートリアルを進める。

    ’posts’というテーブル名にしておけば、自動的にPostモデルが呼び出され、’modified’と’created’というフィールドがあると、自動的にCakeが管理するようになります。
    ほっほ~、そういう事か。
    と、あんまり分かっていないので、とりあえず 書いてあるサンプルをコピペしてみる。
    ちなみに、ファイル構成は、以下のようになる。
    /app
      /Model
        /Post.php
      /Controller
        /PostsController.php
      /Posts
        /index.ctp
        /view.ctp
        /add.ctp
        /edit.ctp
    /app/Model/Post.php
    <?php
    class Post extends AppModel {
    public $name = ‘Post’;

    public $validate = array(
    ‘title’ => array(
    ‘rule’ => ‘notEmpty’
    ),
    ‘body’ => array(
    ‘rule’ => ‘notEmpty’
    )
    );
    }
    /app/Controller/PostsController.php
    <?php
    class PostsController extends AppController {
    public $name = ‘Posts’;
    public $helpers = array(‘Html’, ‘Form’);
    public $components = array(‘Session’);

    public function index() {
    $this->set(‘posts’, $this->Post->find(‘all’));
    }

    public function view($id) {
    $this->Post->id = $id;
    $this->set(‘post’, $this->Post->read());

    }

    public function add() {
    if ($this->request->is(‘post’)) {
    if ($this->Post->save($this->request->data)) {
    $this->Session->setFlash(‘Your post has been saved.’);
    $this->redirect(array(‘action’ => ‘index’));
    } else {
    $this->Session->setFlash(‘Unable to add your post.’);
    }
    }
    }

    function edit($id = null) {
    $this->Post->id = $id;
    if ($this->request->is(‘get’)) {
    $this->request->data = $this->Post->read();
    } else {
    if ($this->Post->save($this->request->data)) {
    $this->Session->setFlash(‘Your post has been updated.’);
    $this->redirect(array(‘action’ => ‘index’));
    } else {
    $this->Session->setFlash(‘Unable to update your post.’);
    }
    }
    }

    function delete($id) {
    if ($this->request->is(‘get’)) {
    throw new MethodNotAllowedException();
    }
    if ($this->Post->delete($id)) {
    $this->Session->setFlash(‘The post with id: ‘ . $id . ‘ has been deleted.’);
    $this->redirect(array(‘action’ => ‘index’));
    }
    }
    }
    /app/View/Postsフォルダを作成して、
    /app/View/Posts/index.ctp
    <h1>Blog posts</h1>
    <p><?php echo $this->Html->link(‘Add Post’, array(‘action’ => ‘add’)); ?></p>
    <table>
    <tr>
    <th>Id</th>
    <th>Title</th>
    <th>Actions</th>
    <th>Created</th>
    </tr>

    <!– ここで$posts配列をループして、投稿情報を表示 –>

    <?php foreach ($posts as $post): ?>
    <tr>
    <td><?php echo $post[‘Post’][‘id’]; ?></td>
    <td>
    <?php echo $this->Html->link($post[‘Post’][‘title’], array(‘action’ => ‘view’, $post[‘Post’][‘id’]));?>
    </td>
    <td>
    <?php echo $this->Form->postLink(
    ‘Delete’,
    array(‘action’ => ‘delete’, $post[‘Post’][‘id’]),
    array(‘confirm’ => ‘Are you sure?’));
    ?>
    <?php echo $this->Html->link(‘Edit’, array(‘action’ => ‘edit’, $post[‘Post’][‘id’]));?>
    </td>
    <td>
    <?php echo $post[‘Post’][‘created’]; ?>
    </td>
    </tr>
    <?php endforeach; ?>
    </table>

    /app/View/Posts/view.ctp
    <h1><?php echo $post[‘Post’][‘title’]?></h1>
    <p><small>Created: <?php echo $post[‘Post’][‘created’]?></small></p>
    <p><?php echo $post[‘Post’][‘body’]?></p>
    /app/View/Posts/add.ctp
    <h1>Add Post</h1>
    <?php
    echo $this->Form->create(‘Post’);
    echo $this->Form->input(‘title’);
    echo $this->Form->input(‘body’, array(‘rows’ => ‘3’));
    echo $this->Form->end(‘Save Post’);
    /app/View/Posts/edit.ctp
    <h1>Edit Post</h1>
    <?php
    echo $this->Form->create(‘Post’, array(‘action’ => ‘edit’));
    echo $this->Form->input(‘title’);
    echo $this->Form->input(‘body’, array(‘rows’ => ‘3’));
    echo $this->Form->input(‘id’, array(‘type’ => ‘hidden’));
    echo $this->Form->end(‘Save Post’);
    で、とりあえず、表示してテスト。
    http://localhost/cakephp/posts
    でも、文字化け。。。
    /app/Config/database.phpに次の一行追加で解決!
    ‘encoding’ => ‘utf8’,