Friday, July 3, 2015

Basic usage of cakePHP 3.0 Upgrade tool - Where to install the upgrade tool?

Ok, you got me into cakePHP 3.0, but now it's time to actually upgrade a V2 site to V3.

The Upgrade tool README.md says "After downloading/cloning the upgrade tool, you need to install dependencies with 'composer'

OK, but the what FOLDER  was I supposed to download and unpack the upgrade-master folder into?

Since there is not a composer.phar file inside the upgrade tool directories, it must require more than just unzipping the supplied download.

I'd really appreciate any assistance,

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Thursday, July 2, 2015

Re: multi table query with cross reference table

OK - NVM
I figured it out

what I learned - how to create a query / subquery object expression to use
 
        //create subquery
        $sub = $query->newExpr('select t.op_team_name from Teams t
            where (t.ws_team_name=Matches.team_home OR t.ws_team_name=Matches.team_away) and 
            (t.op_team_name=OpMatches.team_home OR t.op_team_name=OpMatches.team_away)');
        
        $query->where(['Matches.odds_url is null'])
            ->contain(['OpMatches' => [
                'foreignKey' => false,  //turn off foreignKey when doing initial matching - data is not matched yet
                'queryBuilder' => function($q){
                    return $q->where([
                        'Matches.match_date = OpMatches.match_date',
                    ]);
                }//end - querybuilder                     
            ],
                    //'MatchesCsv',
                    'Seasons'   //load the season object too - we need the league id
            ])->andWhere(function ($exp) use($sub) {                
                return $exp->in("(Matches.team_home OR Matches.team_away)" , $sub);
            });
        
        return $query;

 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Re: multi table query with cross reference table

OK, i found the right query - now i just need to modify it into cakephp orm


SELECT Matches....
Seasons...
OpMatches...

FROM matches Matches


LEFT JOIN seasons Seasons ON (Seasons.id = (Matches.season_id) AND Seasons.stage_id = (Matches.stage_id))

LEFT JOIN op_matches OpMatches ON (Matches.match_date = OpMatches.match_date) /* AND 
(Matches.team_home = t.op_team_name OR Matches.team_home = OpMatches.team_home OR Matches.team_away = t.op_team_name OR Matches.team_away = OpMatches.team_away))  */
WHERE Matches.odds_url is null
AND(  
((Matches.team_away OR Matches.team_home) IN (select t.op_team_name from Teams t where (t.ws_team_name=Matches.team_home OR t.ws_team_name=Matches.team_away) and (t.op_team_name=OpMatches.team_home OR t.op_team_name=OpMatches.team_away) ) )
/*OR Matches.team_away IN (select t.op_team_name from Teams t where t.ws_team_name=Matches.team_away and t.op_team_name=OpMatches.team_away) )*/
);

You'll notice - the 'AND' part of the query is in parens - how do I get cakephp to do that?

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Problems with relationships without Auto increment

I have the following relationships

Contact HABTM List
list HABTM Contact

Only I had to take my auto_increment primaryKey ID field from the contact table, I'm having problem when using INSERT IGNORE.
To replace the auto_incremente created the following trigger:


  DECLARE AUTOI int UNSIGNED DEFAULT 0;
  SELECT max(id) into AUTOI from contacts;
  
  IF (AUTOI IS NULL) THEN
      SET new.id=1;
  ELSE
      SET new.id=AUTOI+1;
  END IF;


When I save a new record in the table contacts is all right, more on the table contacts_lists the field contat_id is always with value 0

Would anyone know tell me how can I fix this?

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

saveMany validation not working correctly

I'm trying to do this With last 2.x CakePHP version, I'm trying to do a upload multiple file form with validations but not working...

DocsController.php (action add)

if ($this->request->is('post')) {      if ($this->Doc->saveMany($this->request->data, array('deep' => true))) {          $this->Session->setFlash(__('Ok'));      } else {          debug($this->Doc->validationErrors); die();          $this->Session->setFlash(__('Error'));      }      $this->redirect($this->referer());  }

add.ctp

<?php  echo $this->Form->create('Doc', array('type' => 'file'));  echo $this->Form->input('files.', array(      'label' => __("New document",true),    'type' => 'file',       'div' => 'input text no',      'multiple' => 'multiple',      'required' => true,  ));  echo $this->Form->end('Upload');  ?>

Doc.php

class Doc extends AppModel {        public $belongsTo = array(          'Project' => array(              'className' => 'Project',              'foreignKey' => 'project_id',          )      );            public $validate = array(          'files' => array(                  'rule' => array('extension', array('pdf')),                  'required' => false,                  'allowEmpty' => true,                  'message' => 'Only pdf files'               ),      );  }

Arrays

This error is OK:

Array  (      [Doc] => Array          (              [files] => Array                  (                      [0] => Array                          (                              [name] => images.jpeg                              [type] => image/jpeg                              [tmp_name] => /private/var/tmp/phpSqerRI                              [error] => 0                              [size] => 5740                          )                    )            )    )    /app/Controller/DocsController.php (line 112)  array(      'Doc' => array(          'files' => array(              (int) 0 => 'Only pdf files'          )      )  )

This is the problem:

Array  (      [Doc] => Array          (              [files] => Array                  (                      [0] => Array                          (                              [name] => 4_54718093804437603.pdf                              [type] => application/pdf                              [tmp_name] => /private/var/tmp/phpCfUUDx                              [error] => 0                              [size] => 1441232                          )                    )            )    )    /app/Controller/DocsController.php (line 112)  array(      'Doc' => array()  )

It's PDF, so OK but validation returns array

Why return array if no broke rules??

Thanks in advance, sorry for my english.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Wednesday, July 1, 2015

multi table query with cross reference table

The problem,
I have two tables that need to be 'matched up' from data in a third table

I am currently using a contains query - but I think the final part should be a subquery - just not sure of how to go about it.

I dont need any 'data' from the third table - just using it to compare some name (string field)

Any suggestions would be awesome...

SELECT Matches....
Seasons...
OpMatches...

FROM matches Matches


LEFT JOIN seasons Seasons ON (Seasons.id = (Matches.season_id) AND Seasons.stage_id = (Matches.stage_id))

LEFT JOIN op_matches OpMatches ON (Matches.match_date = OpMatches.match_date) /* AND 
(Matches.team_home = t.op_team_name OR Matches.team_home = OpMatches.team_home OR Matches.team_away = t.op_team_name OR Matches.team_away = OpMatches.team_away))  */
WHERE Matches.odds_url is null
AND(  
(Matches.team_home = OpMatches.team_home OR Matches.team_away = OpMatches.team_away)

    /*need the other stuff to compare team names - see the query below 

OR (Matches.team_home IN (select t.op_team_name from Teams t where t.ws_team_name=Matches.team_home and t.op_team_name=OpMatches.team_home) )
OR (Matches.team_away IN (select t.op_team_name from Teams t where t.ws_team_name=Matches.team_away and t.op_team_name=OpMatches.team_away) )

    */
)

/* the query im using now */


        $query->where(['Matches.odds_url is null'])
            ->contain(['OpMatches' => [
                'foreignKey' => false,  //turn off foreignKey when doing initial matching - data is not matched yet
                'queryBuilder' => function($q){
                    return $q->where([
                        'Matches.match_date = OpMatches.match_date',
                    ])
                    ->andWhere(function($exp){
                        return $exp->or_([
                            'Matches.team_home = t.op_team_name' ,
                            'Matches.team_home = OpMatches.team_home' ,
                            'Matches.team_away = t.op_team_name' ,
                            'Matches.team_away = OpMatches.team_away']);
                    });
                }//end - querybuilder                     
            ],
                    //'MatchesCsv',  //this gets turned on later - not needed now
                    'Seasons'   //load the season object too - we need the league id
            ])
            ->join([    //not sure a join is the right to go - i dont need the data - just using columns to compare string fields
                'table' => 'teams',
                'alias' => 't',
                'type' => 'LEFT',
                'conditions' => ['t.league_id' => 'Seasons.league_id' , 
                    '(t.ws_team_name = Matches.team_home OR t.ws_team_name = Matches.team_away)']
            ]);        
        return $query;



I apologize if the problem isn't clear.

I can try to explain more in depth if anyone needs.

Thanks,
Joe

p.s.
i will set a .001 btc  bounty for solution

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Re: Validation Example


Use 'message'. For more information visit:
http://book.cakephp.org/3.0/en/core-libraries/validation.html#creating-validators

El viernes, 26 de junio de 2015, 7:17:53 (UTC-4:30), Kingston Abraham escribió:
How will the error messages in validator will appear. Is there any live example to see

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.