ラベル cakephp の投稿を表示しています。 すべての投稿を表示
ラベル cakephp の投稿を表示しています。 すべての投稿を表示

2017年3月27日月曜日

cakephp2のページ遷移

基本的に、actionごとにviewが用意されている。
場合によって、ほかのページに遷移する必要がある。そのとき、下記のように、「redirect」を使う。

$this->redirect(
array('controller' => 'Users', 'action' => 'login')
);

htmlのimg tag内base64画像をサーバーに送信(cakephpの場合)

<img src="data:image/jpeg;base64,/9j.....=">

このsrcの画像をサーバーに送りたい。

JS側は以下のような感じ
function asyncSend() {
      // Generate the image data
      var base64image  = $("#createdPic").attr('src');
      // Sending the image data to Server
      $.ajax({
          method: "POST",
          url: '/Projects/ajaxCall',
          data: { "base64image" : base64image },
          success: function (msg) {
              console.log("OK");
          },
          error: function (response, desc, exception) {
              console.log("NG");
          }
      });
    }

サーバー側はcakephpを使用
public function ajaxCall() {
$this->autoRender = FALSE; //Viewある場合不要
    if($this->request->is('ajax')) {
            $img = $this->request->data['base64image'];
            $img = str_replace('data:image/jpeg;base64,', '', $img);
    $img = str_replace(' ', '+', $img);
    $data = base64_decode($img); //base64_decode() でバイナリに戻す
    $file = 'image.jpeg';
    $success = file_put_contents($file, $data);
        }
}

参考:http://stackoverflow.com/questions/1532993/i-have-a-base64-encoded-png-how-do-i-write-the-image-to-a-file-in-php

2016年12月11日日曜日

cakephpにおけるgmailアカウントによる送信設定

cakephpのマニュアル通りで、gmailのアカウントを設定しても、送信したら、エラーになって、gmailから「ブロックされたログインについてご確認ください」のメールが来た。メールの指示通り、「安全性の低いアプリ」のアクセスを許可しても、「SMTP server did not accept the password」のエラーになった。

そこで下記リンクにアクセスして、アカウントへのアクセスが有効にすれば、メールが送信できるようになった。
https://accounts.google.com/b/0/DisplayUnlockCaptcha

参考:http://stackoverflow.com/questions/26399202/sending-activation-email-smtp-server-did-not-accept-the-password

2016年12月7日水曜日

cloud9でcakephp2の設定

以前はgitHubからcloud9にcloneして、特に問題はなかったが。cakephp2のインストールファイルをそのままcloud9にコピーしたら、アクセスしようさい、「File does not exist」エラーになった。どうもweb rootの設定の問題のようです。

そこで、cloud9のapacheの設定を変更したところ、無事アクセスできるようになった。

sudo vi /etc/apache2/sites-enabled/001-cloud9.conf

DocumentRoot /home/ubuntu/workspace/app/webroot/ #この行を変更

sudo service apache2 restart

参考ページ
http://qiita.com/entaku19890818/items/918bdeeac6a99b03c93b
http://qiita.com/daiki7nohe/items/6e65d405f6dad1888d74

2016年11月20日日曜日

cloud9でcakephp3の動作確認

1)環境を整える、シェルで
phpmyadmin-ctl install

2)cakephp3をインストール、シェルで
curl -s https://getcomposer.org/installer | php
php composer.phar create-project --prefer-dist cakephp/app bookmarker

3)phpmyadminでDBとテーブルを作成

4)config/app.phpのDatasourcesのところで書き換える

5)自分のスペースにアクセスすると、cakephp3の環境設定完了の画面が出てくる
https://{app_address}/bookmarker/

6)シェルでbakeする
cd bookmarker
bin/cake bake all users
bin/cake bake all bookmarks
bin/cake bake all tags


2016年10月28日金曜日

awsにおけるcakephpの設定

git cloneであるcakephp2のプロジェクトをawsのweb rootに追加したが、top以外のところにアクセスできない。以下のメッセージがでてきている。

URL rewriting is not properly configured on your server.

とりあえずcakephpのマニュアルを参照、httpd.conf(/etc/httpd/confの下)を一行修正したところ、上記メッセージが消えてないが、アクセスできるようになった


<Directory "/var/www/html">
    AllowOverride All #none->All
</Directory>

2016年10月24日月曜日

cakephp2におけるHABTM関係要素の検索


ProjectとSkill, AreaはHABTMの関係となっています。Skill, AreaでProjectを検索するには、条件には「joins」を定義してあげないと、SQLがエラーになります。hasOne/hasMany/belongsToなら、不要ですが。

if ($this->request->is('post')) {
            $areas = $this->request['data']['area'];
            $skills = $this->request['data']['Project']['Skill'];
            $industries = $this->request['data']['Project']['Industry'];//IndustryはhasMany Project

            $opt_area = array('OR' => array('Area.id' => $areas));//OR条件検索
            $opt_skill = array('OR' => array('Skill.id' => $skills));
            $opt_industry = array('OR' => array('Industry.id' => $industries));

            $opt = array($opt_area, $opt_skill, $opt_industry);//default AND条件検索

$this->Paginator->settings = array(
                'conditions' => $opt,
                'recursive' => 1,
                'group' => array('Project.id'),
                'joins' => array(
                    array('table' => 'areas_projects',
                        'alias' => 'AreasProject',
                        'type' => 'inner',
                        'conditions' => array(
                            'Project.id = AreasProject.project_id',
                        )
                    ),
                    array(
                        'table' => 'areas',
                        'alias' => 'Area',
                        'type' => 'inner',
                        'conditions' => array(
                            'AreasProject.area_id = Area.id',
                        ),
                    ),
                     array('table' => 'skills_projects',
                         'alias' => 'SkillsProject',
                         'type' => 'inner',
                         'conditions' => array(
                             'Project.id = SkillsProject.project_id',
                         )
                     ),
                    array(
                        'table' => 'skills',
                        'alias' => 'Skill',
                        'type' => 'inner',
                        'conditions' => array(
                            'SkillsProject.skill_id = Skill.id',
                        ),
                    ),

$projects = $this->Paginator->paginate('Project');