Tuesday, November 3, 2015

CakePHP with Sqlite3: How to connect to multiple sqlite file?

I working on a project where user register and get a free online shop using CakePHP v2.6.5. I'm using shared hosting so i can't create Mysql database for them, So I use sqlite instead. Because I need to use it with Mobile App too. In my code I dynamically create sqlite file for user after their register. But I don't know how to change database path in CakePHP. All I know is CakePHP use config in `config/database.php` file, but i can't init it dynamically.

In my `config/database.php` file:
   
    public $sqliteDB = array(
        'datasource' => 'Database/Sqlite',
        'persistent' => false,
        //'database'=>'',
        'prefix' => '',
        'encoding' => 'utf8'
    );

I trying to follow these link:
http://stackoverflow.com/questions/5512327/cakephp-switch-database-using-same-datasource-on-the-fly
and this link
http://stackoverflow.com/questions/13956791/cakephp-cant-change-database-on-the-fly, but I got nothing.

--
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.

Monday, November 2, 2015

Calephp 3.0 -> Error: Unknown method "fields"

Hello, I m working cakephp 3.0

Error :  Unknown method "fields"

Why ?  my code is 

$query = $this->ClientsFr->find('all')
->fields('ClientsFr.provider_id', 'ClientsFr.name')
->order(['ClientsFr.id' => 'ASC'])
->join([
'providers_fr' => [
'table' => 'providers_fr',
'type' => 'LEFT',
'conditions' => 'providers_fr.id = ClientsFr.provider_id'
]
]);

Please help. 

--
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: Problem Console on cakephp 2.7.5

I don't have an 2.7.5 install to work on, but you might be better off submitting a ticket to GitHub at https://github.com/cakephp/cakephp/issues

On Tuesday, 3 November 2015 09:10:22 UTC+10, Nilson Pena wrote:
There is something wrong with cakephp 2.7.5. when using the console, for example:
cakephp/lib/Cake/Console/cake AclExtras.AclExtras aco_sync

I get the following error:

PHP Parse error:  syntax error, unexpected T_STATIC, expecting T_STRING or T_VARIABLE or '$' in /home/myDomain/public_html/cakephp/lib/Cake/Core/App.php on line 221

If I switch to version 2.6.11 everything works well!!!

Any idea?

Thank You,

Nilson

--
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: Cakephp Inline Editing

Aha Thanks for the help.

I'm working on function add()

I'm trying to get user input and calculate hours from the start and stop date provided by the users. I'm not able to have the calculated $hours to save in the database together with rest of the user inputs.

           $starttime = $this->request->data['Leave']['event_date'];
            $endtime = $this->request->data['Leave']['event_stop_time'];
            $lunch = $this->request->data['Leave']['lunch_break'] * 60; //lunch break in seconds
                                       
               
            $start = strtotime($starttime); //Convert to unix time
            $end = strtotime($endtime); //Convert to unix time             
            $hours = ($end - $start - $lunch)/60/60;   
          ----------------------------------------------------------

When i use this
        if ($this->Leave->saveAll($this->request->data)) {   
                $this->Session->setFlash(__('The leave has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The leave could not be saved. Please, try again.'));
            }

    The hours field is not updated. I have no idea how to save the $hours together with other user inputs. Any help is much appreciated

Thanks
Para

     

On Sat, Oct 24, 2015 at 6:56 AM, John Andersen <j.andersen.lv@gmail.com> wrote:
In your code you are already using $stop as an array:

        $this->set('stop',$stop['Leave']['event_stop_time']);

so when you try to calculate the $hours, then you have an array - a value :)

Try and fix that!
Enjoy, John


On Friday, 23 October 2015 12:43:47 UTC+3, Para K wrote:
I'm working on a project for Payroll Dept. I have included inline editing feature in my code.

When the user edits start date, the program should calculate and update the hours field by subtracting the stop date from start date. I'm stuck on the calculation part giving an error "Unsupported Operand Types". Below is my code snippet

case 'event_date':
           
             if ($this->request->data['Leave']['event_date'] == $value) {
                   
                    $stop = $this->Leave->find('first', array('conditions' => array('event_date' => $value)));
                    $this->set('stop',$stop['Leave']['event_stop_time']);
                   
                    $start = $this->request->data['Leave']['event_date'];
                                   
                    $hours = ($stop - $start);
                    $this->request->data['Leave']['hours'] = $hours;
                    $this->set('updated_value', $hours);
               
             }

Any form of help is much appreciated as I'm a newbie to cakephp

Thanks

--
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.

--
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.

Problem Console on cakephp 2.7.5

There is something wrong with cakephp 2.7.5. when using the console, for example:
cakephp/lib/Cake/Console/cake AclExtras.AclExtras aco_sync

I get the following error:

PHP Parse error:  syntax error, unexpected T_STATIC, expecting T_STRING or T_VARIABLE or '$' in /home/myDomain/public_html/cakephp/lib/Cake/Core/App.php on line 221

If I switch to version 2.6.11 everything works well!!!

Any idea?

Thank You,

Nilson

--
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.

run Model::beforeSave before Behavior::beforeSave

Hi,

Is there any way to ensure that Model::beforeSave runs before Behavior::beforeSave?

My use case is saving multiple records into a model with Tree behaviour, where the scope can change from record to record.

So, using Model::beforeSave I check to see if the scope field has a value and if so I set the Tree scope to that value.  

Problem is Tree::beforeSave has already ran and set the lft and rght values not taking the correct scope into account.

I can get around this be manually calling the following in Model::beforeSave right after setting the scope ...

$this->Behaviors->Tree->beforeSave($this);

... but this feels really hacky.

Any ideas on how I control the order/priority of beforeSave actions?

Thanks, Paul.

--
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.

Sunday, November 1, 2015

Cakephp 3 Transaction management on multiple model operation

$saveStatus = 1;  $conn = ConnectionManager::get('default');  $conn->begin();  $tableArticles = TableRegistry::get('Articles');  $tableUsers = TableRegistry::get('Users');  $articlesEntity = $tableArticles->newEntities($categoriesArray);  foreach ($articlesEntity as $entity) {                if(!$tableArticles->save($entity))      {          $saveStatus = 0;      }  }  $usersEntity = $tableUsers->newEntities($usersArray);  foreach ($usersEntity as $entity) {      if(!$tableUsers->save($entity))      {          $saveStatus = 0;      }  }  if($saveStatus ==1)  {      $conn->commit();    }  else  {      $conn->rollback();             }  

But the transaction works for only one table.I want multiple table operation should be in transaction.

In cake 2, we do transaction using begin() and commit() on each model data source like following.

$mealOptionDataSource = $this->MealOptionFood->getDataSource ();
$foodExtrasDataSource = $this->FoodExtras->getDataSource ();
$complexOptionDataSource = $this->ComplexOptionFood->getDataSource ();

$mealOptionDataSource->begin ();  $foodExtrasDataSource->begin ();  --- Code here---  $mealOptionDataSource->commit ();  $foodExtrasDataSource->commit ();  $complexOptionDataSource->commit ();  

I can't find a way how to do it in cake 3.

--
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.