CakePHP 3: How to save model and field name in associated table?

2015-10-13 Thread Salines
I need a hint.

I have to develop a number of centralized models, which will be in relation 
to other models. 
Examples of such models are Timelines and Images, which secound have 
fields: 

id, 
model, // Model name, ex Users
field, // field name, from where upload
foreign_key, // User Id
descripton..


UsersTable example: 

$this->hasOne('Cover',[
'className' => 'Images',
'foreignKey' => 'foreign_key',
'conditions' => [
'model' => 'Users',
'field' => 'cover'
]
]);

$this->hasOne('Avatar',[
'className' => 'Images',
'foreignKey' => 'foreign_key',
'conditions' => [
'model' => Users',
'field' => 'avatar'
]
]);
$this->hasMany('Images',[
'className' => 'Images',
'foreignKey' => 'foreign_key',
'conditions' => [
'model' => 'Users',
'field' => 'images'
]
]);

Form->input('cover.cover',[ 'type' => 'file', 'label' => 
false]); ?>
Form->input(avatar.avatar',[ 'type' => 'file', 'label' => 
false]); ?>
Form->input('images[].images',[ 'type' => 'file', 'multiple' => 
true, 'label' => false]); ?>


How to in beforeMarshal or beforeSave methods on ImagesTable or Behavior 
retrieve model name from which is uploaded images, example Users, Posts,.., 
and store in images tables?

Currently I am migrating from 2.x to 3.x, I have a lot to learn.

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+unsubscr...@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: JQuery autocomplete on Cakephp 3.0

2015-10-13 Thread Raul Magdalena Catala
hola,

Solucionado, para que jquery autocomplete, los campos devueltos deben 
llamarse "value" y "label"

El dilluns, 12 octubre de 2015 22:48:52 UTC+2, Christian Quispe va escriure:
>
> Revisa si tienes los css incluidos. 
>
>
>
> Enviado con MailTrack 
> 
>
> Saludos
>
> Christian Quispe
>
> *Geek and Developer*
> *Miembro: * *GDG Lima (Google Developer Group Lima)*
>
> *Portafolio: www.oxicode.io 
> *
>
> *¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores 
> constantemente...*
>
>
> El 12 de octubre de 2015, 3:32 p. m., Raul Magdalena Catala<
> raulma...@gmail.com > escribió:
>
>> hola de nuevo Christian,
>>
>> finalmente he consegido una respuesta json de un controlador pero el 
>> input intenta autocompletar pero se queda a medio camino. Pego la pantalla 
>> que es más facil verlo que explicarlo
>>
>>
>> 
>>
>> ¿sabes a que se debe este comportamiento del input?
>> He comprobado que la respuesta json esta bien formateada.
>>
>> gracias
>>
>> El divendres, 9 octubre de 2015 9:27:16 UTC+2, Raul Magdalena Catala va 
>> escriure:
>>>
>>> hola
>>>
>>> el código del controladores muy sencillo
>>>
>>> >>   class CarsController extends AppController {
>>>
>>> public $layout = 'basic';
>>>
>>> public $components = array (
>>> 'RequestHandler');
>>>
>>> public function index() {
>>>   if ($this->request->is('ajax')) {
>>> $term = $this->request->query('term');
>>> $carNames = $this->Car->getCarNames($term);
>>> $this->set(compact ('carNames'));
>>> $this->set('_serialize', 'carNames');
>>>   }
>>> }
>>>   }
>>>
>>>
>>>
>>> El divendres, 9 octubre de 2015 7:06:21 UTC+2, Christian Quispe va 
>>> escriure:
>>>
>>> Ahiy esta el error. Hay un problema con la función. 
>>>
>>> Este tema del jquey, ajax y json es bien fácil. Fresh. Compartenos el 
>>> código del controlador para ver en que has metido la pata
>>>
>>> Enviado desde Gmail para Moto G
>>>
>>> www.oxicode.io 
>>> El oct. 8, 2015 2:08 AM, "Raul Magdalena Catala"  
>>> escribió:
>>>
>>> Hola Christian,
>>>
>>> tengo un archivo creado para la vista en , src/Template/Cars/index.ctp.
>>>
>>> la ruta en el script es correcta:
>>>
>>> $(document).ready(function(){
>>> $('#autocomplete').autocomplete({
>>> source: "/cars/index.json",
>>> });
>>> });
>>>
>>> finalmente te paso la pertaña network
>>>
>>>
>>> 
>>>
>>>
>>>
>>> El dijous, 8 octubre de 2015 0:57:13 UTC+2, Christian Quispe va escriure:
>>>
>>> Ya veo, el problema viene por la vista, tienes el archivo creado en la 
>>> vista?, si usas solo controlador debes tener 
>>>
>>> $this->set('_serialize', ['articles']);
>>>
>>> tambien checa la ruta,  la url destino, el u0022 es un ' por ahi puede 
>>> hacer conflicto
>>> pasame un pantallazo de la pestaña Network, el ultimo item debe ser el 
>>> request, subpestaña preview
>>>
>>>
>>>
>>> Enviado con MailTrack 
>>> 
>>>
>>> Saludos
>>>
>>> Christian Quispe
>>>
>>> *Geek and Developer*
>>> *Miembro: * *GDG Lima (Google Developer Group Lima)*
>>>
>>> *Portafolio: www.oxicode.io 
>>> *
>>>
>>> ...
>>
>> -- 
>> 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+u...@googlegroups.com .
>> To post to this group, send email to cake...@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+unsubscr...@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.