Re: Virtual fields problem

2016-03-10 Thread LeHung
How about this?

$array = Hash::combine($array, '{n}Tag.name,{n}0.aantai,{n}');

On Fri, Mar 11, 2016 at 4:14 AM, Sam Clauw  wrote:

> Hi 2 all,
>
> I'm working on my first CakePHP blog project: http://kattenbelletjes.be/
> As you can see, there's a footer section that shows the top 25 most
> popular tags.
>
> There are three relevant tables I use the implement those popular tags:
>
> POSTS: id, title, content, slug
> TAGS: id, name, slug
> POST_TAG_LINK: id, post_id, tag_id
>
> I tried to make a CakePHP query via $this->tag->find, but there was a
> persistent SQL error that I couldn't fix.
> So, I tried it on the "$this->tag->query" SQL way:
>
> debug($this->Tag->query(
> "SELECT
> Tag.name,
> COUNT(PostTagLink.id) AS aantal
> FROM
> tags AS Tag
> INNER JOIN
> post_tag_links AS PostTagLink
> ON
> tag.id = PostTagLink.tag_id
> WHERE
> Tag.show = 'Y'
> GROUP BY
> Tag.name
> ORDER BY
> Tag.name ASC"
> ));
>
> The problem is that the output array isn't very nice:
>
> array(
>> (int) 0 => array(
>> 'Tag' => array(
>> 'name' => 'Beauty'
>> ),
>> (int) 0 => array(
>> 'aantal' => '2'
>> )
>> ),
>> (int) 1 => array(
>> 'Tag' => array(
>> 'name' => 'Koken'
>> ),
>> (int) 0 => array(
>> 'aantal' => '1'
>> )
>> ),
>> (int) 2 => array(
>> 'Tag' => array(
>> 'name' => 'Lente'
>> ),
>> (int) 0 => array(
>> 'aantal' => '2'
>> )
>> ),
>> (int) 3 => array(
>> 'Tag' => array(
>> 'name' => 'Wonen'
>> ),
>> (int) 0 => array(
>> 'aantal' => '4'
>> )
>> )
>> )
>
>
> I wan't something like this instead:
>
> array(
>> (int) 0 => array(
>> 'Tag' => array(
>> 'name' => 'Beauty',
>> 'count' => '2'
>> )
>> ),
>> (int) 1 => array(
>> 'Tag' => array(
>> 'name' => 'Koken',
>> 'count' => '1'
>> )
>> ),
>> (int) 2 => array(
>> 'Tag' => array(
>> 'name' => 'Lente',
>> 'count' => '2'
>> )
>> ),
>> (int) 3 => array(
>> 'Tag' => array(
>> 'name' => 'Wonen',
>> 'count' => '4'
>> )
>> )
>> )
>
>
> Is there somebody with a solution on this?
> Thanks 4 helping ;)
>
> --
> Sign up for our Newsletter for updates.
> http://cakephp.org/newsletter/signup
>
> We will soon be closing this Google Group. But don't worry, we have
> something better coming. Stay tuned for an updated from the CakePHP Team
> soon.
>
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Follow 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.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow 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.
For more options, visit https://groups.google.com/d/optout.


Virtual fields problem

2016-03-10 Thread Sam Clauw
Hi 2 all,

I'm working on my first CakePHP blog project: http://kattenbelletjes.be/
As you can see, there's a footer section that shows the top 25 most popular 
tags.

There are three relevant tables I use the implement those popular tags:

POSTS: id, title, content, slug
TAGS: id, name, slug
POST_TAG_LINK: id, post_id, tag_id

I tried to make a CakePHP query via $this->tag->find, but there was a 
persistent SQL error that I couldn't fix.
So, I tried it on the "$this->tag->query" SQL way:

debug($this->Tag->query(
"SELECT
Tag.name,
COUNT(PostTagLink.id) AS aantal
FROM
tags AS Tag
INNER JOIN
post_tag_links AS PostTagLink
ON
tag.id = PostTagLink.tag_id
WHERE
Tag.show = 'Y'
GROUP BY
Tag.name
ORDER BY
Tag.name ASC"
));

The problem is that the output array isn't very nice:

array(
> (int) 0 => array(
> 'Tag' => array(
> 'name' => 'Beauty'
> ),
> (int) 0 => array(
> 'aantal' => '2'
> )
> ),
> (int) 1 => array(
> 'Tag' => array(
> 'name' => 'Koken'
> ),
> (int) 0 => array(
> 'aantal' => '1'
> )
> ),
> (int) 2 => array(
> 'Tag' => array(
> 'name' => 'Lente'
> ),
> (int) 0 => array(
> 'aantal' => '2'
> )
> ),
> (int) 3 => array(
> 'Tag' => array(
> 'name' => 'Wonen'
> ),
> (int) 0 => array(
> 'aantal' => '4'
> )
> )
> )


I wan't something like this instead:

array(
> (int) 0 => array(
> 'Tag' => array(
> 'name' => 'Beauty',
> 'count' => '2'
> )
> ),
> (int) 1 => array(
> 'Tag' => array(
> 'name' => 'Koken',
> 'count' => '1'
> )
> ),
> (int) 2 => array(
> 'Tag' => array(
> 'name' => 'Lente',
> 'count' => '2'
> )
> ),
> (int) 3 => array(
> 'Tag' => array(
> 'name' => 'Wonen',
> 'count' => '4'
> )
> )
> )


Is there somebody with a solution on this?
Thanks 4 helping ;) 

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow 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.
For more options, visit https://groups.google.com/d/optout.


Re: API Design using CakePHP 3

2016-03-10 Thread Florian Krämer
1) I would *not *avoid that. We use the protection and have no problem at 
all with it.
2) Create a filter and use it in beforeSave()? Create data objects like the 
entities in Cake and filter the date there before sending?
3) No idea what you're talking about, you basically say "It's not working 
righ". We do the transformRequest just once AFAIR.
4) No idea, "It's not working" is nothing you'll get help with.

See 
http://book.cakephp.org/3.0/en/development/routing.html#creating-restful-routes 
There is also the FoC CRUD plugin but we don't use it yet and probably 
won't. Cake is good enough as it is for us so far. We're re-building our 
frontend and a CRM with Angular and Cake3.

On Wednesday, March 9, 2016 at 3:04:19 PM UTC+1, Rafael Queiroz wrote:
>
> Hi guys,
>
> I make a *API* using *CakePHP 3.2.x*, so, and now have a angular app 
> requesting *API*.
> My question is about association data, e.g. i have *Series* *Model* and 
> send the request:
>
> *api.com/series/add *
>
> {
> "id": 5,
> "title": "New serie", 
> "hidden": false,
> "courses": {"_ids":["1","2"]}
> }
>
> It's work, many times, i have problems, because first time in edit, i get 
> register and mockup in scope of app, and have problems, because register 
> have all fields, per sample: 
>
> 1. Avoiding Mass Assignment Protection in Entity, because save created = 
> null
> 2. Send all object data, have association data i don't want send, i need 
> using transformRequest in angularJs
> 3. Many times i have problem with CORS, because send a object complex, not 
> expected, if simple object it's work
> 4. I have problem for delete association data, have a garbage in docs, but 
> not work's 100%. [1]
>
> So, this easy save data and associations, now, it's my nightmare.
>
> *My point is about best practices for api, i read articles and have a 
> solution, using sub resources.*
>
>
>
> *I need create new endpoints for retrieve/save/delete associations data in 
> register ?What do you think ? Thank you in advance for your attention*
> [1] 
> http://book.cakephp.org/3.0/en/orm/saving-data.html#patching-hasmany-and-belongstomany
>
> -- 
> Regards,
>
> Rafael F. Queiroz
>

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow 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.
For more options, visit https://groups.google.com/d/optout.