Tuesday, March 3, 2015

How can run cakephp inside a cakephp

In my host root I installed cakephp named cake1 and I want to install another cakephp inside cake1 directory named cake2. 

--
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: Still having trouble with saving BelongsToMany data

What did you have to do that was not in the documentation? It would be helpful to add it to the docs so other don't get stuck as well in the same problem

On Tuesday, March 3, 2015 at 7:25:01 AM UTC+1, Joe T. wrote:
i'm REALLY sorry for the delay getting back to you. And unfortunately, i'm still not there. It's CLOSE though:

i did exactly as you suggested in your last post. Set up my Entities & Tables just as you described. Set up the controller to manually set the _joinData "dirty" and called the save.

i get the ListingsAttributes record now! But no value from the text input (_joinData.value).

The POST data is correct:

Array
(
   
[attributes] => Array
       
(
           
[3] => Array
               
(
                   
[id] => 1
                   
[_joinData] => Array
                       
(
                           
[value] => Off-street
                       
)
               
)
       
)
)

That's exactly what i've been getting since i change to use _joinData...

Here's the Entity after merging & setting _joinData dirty:

Array
(
   
[attributes] => Array
       
(
           
[0] => Array
               
(
                   
[id] => 1
               
)
       
)
)

As before, the "value" input got lost. However, there is FINALLY an Attributes array in the Listing entity with the correct Attributes.id. The result is, i get a ListingsAttributes record with the Listings.id and Attributes.id, but nothing in the value column.

This is making me crazy & i'm on the edge of scrapping this thing & starting over with something else. i never expected this much difficulty getting some basic data relationships to work after following documentation exactly (and then having to make undocumented changes that still only get me part-way there. i don't think i'm doing anything radical or unconventional with my form, so i don't understand the difficulty of making the ORM function as advertised.

i'm frustrated, obviously. It's taken me this long to come back to follow up because it becomes harder & harder to come back & try again. i'm almost there, i just don't know why the value input won't go into the Entity data with everything else.

If you're moving on, i totally understand. But if you'd like to look at the code directly, let me know. i'll have to put a version online without sensitive info in it...

Thanks for at least getting me this far. :)
-joe




On Wednesday, 25 February 2015 04:57:35 UTC-5, heavyKevy wrote:
Joe,

Here is what I did:
In the attribute entity:
   protected $_accessible = [
        'id' => true,
        'name' => true,
        'listings' => true,
    ];

In the Listings_Attributes Table:
   public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create')
            ->add('listing_id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('listing_id', 'create')
            ->notEmpty('listing_id')
            ->add('attribute_id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('attribute_id', 'create')
            ->notEmpty('attribute_id')
            ->allowEmpty('value');

        return $validator;
    }


In the Listings Controller:  Add method:
    public function add()
    {
        $listing = $this->Listings->newEntity();
        if ($this->request->is('post')) {
            $listing = $this->Listings->patchEntity($listing, $this->request->data,['associated'=>['attributes._joinData']]);
            $listing->dirty('attributes._joinData',true);
            if ($this->Listings->save($listing)) {
                $this->Flash->success('The listing has been saved.');
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error('The listing could not be saved. Please, try again.');
            }
        }
        $attributes = $this->Listings->Attributes->find('list', ['limit' => 200]);
        $this->set(compact('listing', 'attributes'));
        $this->set('_serialize', ['listing']);
    }

In the Add template of the Listing: add.ctp
 <?= $this->Form->create($listing); ?>
    <fieldset>
        <legend><?= __('Add Listing') ?></legend>
        <?php
            echo $this->Form->input('name');
            //echo $this->Form->input('attributes._ids', ['options' => $attributes]);
           
            if(!empty($attributes)){
                $i =0;
                foreach( $attributes as $k =>  $attr){
                              echo $this->Form->input('attributes.'.$i.'.id',['type'=>'checkbox','value'=>$k,'label'=>$attr]);
                              echo $this->Form->input('attributes.'.$i.'.name',['type'=>'hidden','value'=>$attr]);
                              echo $this->Form->input('attributes.'.$i.'._joinData.value');
                              $i++;
                          }
                        }
            //echo $this->Form->select('attributes._ids', $attributes,['label'=>'Attributes','multiple' => 'checkbox']);
           
           
        ?>
    </fieldset>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>


I don't believe I changed anything else.. Just used what was baked, and it works for me.

--Kevin

--
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, March 2, 2015

Re: Still having trouble with saving BelongsToMany data

i'm REALLY sorry for the delay getting back to you. And unfortunately, i'm still not there. It's CLOSE though:

i did exactly as you suggested in your last post. Set up my Entities & Tables just as you described. Set up the controller to manually set the _joinData "dirty" and called the save.

i get the ListingsAttributes record now! But no value from the text input (_joinData.value).

The POST data is correct:

Array
(
   
[attributes] => Array
       
(
           
[3] => Array
               
(
                   
[id] => 1
                   
[_joinData] => Array
                       
(
                           
[value] => Off-street
                       
)
               
)
       
)
)

That's exactly what i've been getting since i change to use _joinData...

Here's the Entity after merging & setting _joinData dirty:

Array
(
   
[attributes] => Array
       
(
           
[0] => Array
               
(
                   
[id] => 1
               
)
       
)
)

As before, the "value" input got lost. However, there is FINALLY an Attributes array in the Listing entity with the correct Attributes.id. The result is, i get a ListingsAttributes record with the Listings.id and Attributes.id, but nothing in the value column.

This is making me crazy & i'm on the edge of scrapping this thing & starting over with something else. i never expected this much difficulty getting some basic data relationships to work after following documentation exactly (and then having to make undocumented changes that still only get me part-way there. i don't think i'm doing anything radical or unconventional with my form, so i don't understand the difficulty of making the ORM function as advertised.

i'm frustrated, obviously. It's taken me this long to come back to follow up because it becomes harder & harder to come back & try again. i'm almost there, i just don't know why the value input won't go into the Entity data with everything else.

If you're moving on, i totally understand. But if you'd like to look at the code directly, let me know. i'll have to put a version online without sensitive info in it...

Thanks for at least getting me this far. :)
-joe




On Wednesday, 25 February 2015 04:57:35 UTC-5, heavyKevy wrote:
Joe,

Here is what I did:
In the attribute entity:
   protected $_accessible = [
        'id' => true,
        'name' => true,
        'listings' => true,
    ];

In the Listings_Attributes Table:
   public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create')
            ->add('listing_id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('listing_id', 'create')
            ->notEmpty('listing_id')
            ->add('attribute_id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('attribute_id', 'create')
            ->notEmpty('attribute_id')
            ->allowEmpty('value');

        return $validator;
    }


In the Listings Controller:  Add method:
    public function add()
    {
        $listing = $this->Listings->newEntity();
        if ($this->request->is('post')) {
            $listing = $this->Listings->patchEntity($listing, $this->request->data,['associated'=>['attributes._joinData']]);
            $listing->dirty('attributes._joinData',true);
            if ($this->Listings->save($listing)) {
                $this->Flash->success('The listing has been saved.');
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error('The listing could not be saved. Please, try again.');
            }
        }
        $attributes = $this->Listings->Attributes->find('list', ['limit' => 200]);
        $this->set(compact('listing', 'attributes'));
        $this->set('_serialize', ['listing']);
    }

In the Add template of the Listing: add.ctp
 <?= $this->Form->create($listing); ?>
    <fieldset>
        <legend><?= __('Add Listing') ?></legend>
        <?php
            echo $this->Form->input('name');
            //echo $this->Form->input('attributes._ids', ['options' => $attributes]);
           
            if(!empty($attributes)){
                $i =0;
                foreach( $attributes as $k =>  $attr){
                              echo $this->Form->input('attributes.'.$i.'.id',['type'=>'checkbox','value'=>$k,'label'=>$attr]);
                              echo $this->Form->input('attributes.'.$i.'.name',['type'=>'hidden','value'=>$attr]);
                              echo $this->Form->input('attributes.'.$i.'._joinData.value');
                              $i++;
                          }
                        }
            //echo $this->Form->select('attributes._ids', $attributes,['label'=>'Attributes','multiple' => 'checkbox']);
           
           
        ?>
    </fieldset>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>


I don't believe I changed anything else.. Just used what was baked, and it works for me.

--Kevin

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

cake app install

hi,

I have a CakePHP project hosted on github. As cake and some of the
plugins use composer I am a little bit confused what is the best way
to install the app somewhere. The vendor and plugn folders added to
.gitignore, so they are not there on the git repo.

The app itself is not a composer package.

How to install and kepp synced with the git repo?

rrd

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

cake app install

hi,

I have a CakePHP project hosted on github. As cake and some of the
plugins use composer I am a little bit confused what is the best way
to install the app somewhere. The vendor and plugn folders added to
.gitignore, so they are not there on the git repo.

The app itself is not a composer package.

How to install and kepp synced with the git repo?

rrd

--
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, March 1, 2015

Re: File upload validation

I think we have a misunderstanding.  The code I sent you was for your model.  The only thing that changes was you had some code in the "afterValidate" function and I provided you with an alternative to do all the legwork in the "beforeValidate" function.

If you use "beforeValidate" you can do all the photo uploading and field-setting logic and return TRUE.   Alternatively, you can return FALSE to prevent further validation if there is an error.

NOTE:  If beforeValidate returns FALSE CakePHP will short-circuit and "validates()" DOES NOT execute.  

NOTE:  If beforeValidate returns TRUE CakePHP will execute "validates()".   Performing the file upload in the afterValidate function is TOO LATE; The Model has already attempted to validate your field "photo" and the error is already set before afterValidate callback event is executed.

NOTE:  The function afterValidate is called by the ModelValidator object inside the errors  function.  The ModelValidator errors function performs tests all the fields, sets errors, and finally executes afterValidate before returning.


Sincerely,

Charles A Beasley


On Sun, Mar 1, 2015 at 5:56 AM, Sam Clauw <sam.clauw@gmail.com> wrote:
Charles, thank you for the great effort!
But is there no other option than move the validation into the controller instead of doing it in the model?

The code I wrote only contains one single if/else and is very clear to me. Okay, it's not working so I'm not getting anywhere for the moment huh ;)

Can you confirm that extension rule in CakePHP is validation the ['type'] variable in the FILES array? If "yes", I realy don't understand why I keep getting validation errors on the validExtension rule :s

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

Re: File upload validation

Charles, thank you for the great effort!
But is there no other option than move the validation into the controller instead of doing it in the model?

The code I wrote only contains one single if/else and is very clear to me. Okay, it's not working so I'm not getting anywhere for the moment huh ;)

Can you confirm that extension rule in CakePHP is validation the ['type'] variable in the FILES array? If "yes", I realy don't understand why I keep getting validation errors on the validExtension rule :s

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