CakePhp 2 Tip#8-Checking User Ownership

cake-logo

Another common task in Cakephp Applications or any Web Application is making sure that a user can only delete items they own otherwise anyone could erase your entire database.

An example you have created a users table and users can create posts, but we need to ensure that User A can only edit and delete posts belonging to them.

Solution: The isAuthorized() function.
This function will check that the user isAuthorized to do what ever action they are about to under take.

Assuming every posts has a user_id as a foreign key, we can check the current logged in user’s Id against the id stored in the post their about to modify and if they match allow and if not deny.

Entire User Auth Solution and Guide:
https://github.com/cakephp/docs/blob/master/en/tutorials-and-examples/blog-auth-example/auth.rst

CakePhp Tip #6: Displaying items that belong to a user

cake-logo

Displaying items that belong to a user:

One of the most common things youll do in cakephp is list items that the user should only see. For example a user should just see their “posts” listed or their “articles” etc.

CakePHP has “Magic Find Types” that can help. For example if i wanted to list all the posts of the user_id =12

In my controller i can create an action as follows;

if i wanted to list all posts of the current logged in user;

To call view this action;

Source and more info;
http://book.cakephp.org/2.0/en/models/retrieving-your-data.html

CakePhp tip #5: Joining two fields to create one

Joining two fields to create one (eg to get somebodys name by combining firstname and surname)

cake-logo

You need to create a “VirtualField” in the model;

Then in your controller, to get a drop downlist;

Credit to:
http://stackoverflow.com/questions/11822942/cakephp-display-multiple-fields-in-a-single-drop-down

Cakephp Tip #3 – Requesting JSON or XML

The newest version of Cakephp makes it even easier to make a JSON or XML request.

Add the request handler component to your controller;

create your action in your controller;
eg

To access either the JSON or XML version simply append .json or .xml to the action name;

http://localhost/myapp/posts/testjson.json

http://localhost/myapp/posts/testjson.xml

Manual:

CakePHP 2 – Tip#2: Saving Data via Hidden Field in View

If your trying to save the a foreign key of something heres how you can do it. Eg you want to save the user_id to the products table but you dont want the user to be able to input the user id as there all ready logged in;

In the your view add this line;

CakePHP 2 – Tip#1: Display Field instead of ID

Display Field instead of ID:

Whenever CakePHP automagically fetches lists from your tables, it uses the id key for the value and the $displayField for the text.

If your table has a name or title field, CakePHP automatically displays it as the display field. So, either rename the field that you want as your display field (say, candidate_name to just name) or set the $displayField variable in your model:

Source:
http://stackoverflow.com/questions/4558505/cakephp-related-tables-show-ids-instead-of-values

Manual:

Tidal – The Streaming service of every artist you dont want to hear!

It gets better lol;

NEW YORK (AP) — Madonna, Rihanna, Beyonce and Jay Z are among the A-List musicians who are co-owners of Tidal, a streaming service being billed as the first artist-owned platform for music and video.

The membership-based service — similar to subscription service Spotify — will provide music and video content that users can stream on computers, tablets and smartphones or listen to offline. It is being offered at two price points: $10 for standard sound quality and $20 for “lossless high fidelity sound quality.”

Few other details were released about the streaming service.

Kanye West, Daft Punk, Alicia Keys, Jack White and Nicki Minaj also were among the artists who announced at a New York City event Monday that they are co-owners of the service that quietly launched in October. Keys said the artists hope Tidal will “forever change the course of music history” and ensure the viability of the industry.

The celebrities — who also included Jason Aldean, Usher, members of Arcade Fire and deadmau5 — stood in a line onstage as Keys spoke to the audience at Skylight at Moynihan Station in Manhattan. Most of them wore black as a sign of solidarity. Keys called the event “a graduation.”

Source :

http://www.huffingtonpost.com/2015/03/30/tidal-jay-z_n_6972746.html?ncid=fcbklnkushpmg00000024

 

TLDR!
It is being offered at two price points: $10 for standard sound quality and $20 for “lossless high fidelity sound quality.”

Exception:
Daft Punk guess they sold out?

Rofl

Dr Dre’s Beat Headphones are a huge scam

Ah yes the headphones you wished you could afford are a pile of shit!

Beats headphones cost anywhere between £100 and £400. Jimmy Iovine and Dr. Dre have created a $3.2 billion empire off the back of them after they sold the company to Apple last year.

What a lot of people don’t know is that a regular haircut costs more than it does to create some Beats headphones.

It has been revealed the cost of making the fancy headset is as low as $14.

Source