When to use $this->data vs $this->request->data - cakephp-2.0

I've tried Googling this and I can't really find a definitive answer to this question.
I know that when I want to manipulate my data, I'll need to use $this->request->data, but even so, even without manipulation I see that the blog tutorial of the Cakephp 2.0 website, which can be found here:
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html
Uses $this->request->data. Now, if it's good practice to use $this->request->data even when you're not manipulating your data, what is the use of $this->data within a controller?

$this->data is deprecated. It still works so that migration will not break. But it will eventually be removed and everything is moving to the CakeRequest and CakeResponse objects.
Go here:
http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html
And look for:
Controller::$data

Related

Cache and pagination with CakePHP 3.x

Here is how to cache results with pagination with CakePHP 2.x.
I have not tried it yet, but I believe that the same method is valid with CakePHP 3.x.
However, since CakePHP 3.x introduces several new features for using the cache (for example, the find() method takes the cache option), I wanted to know if there is a faster method.
I have seen book and APIs, but is not mentioned anything special in this regard.
One thing: here is explained that
By default the paginate() method will use the default model for a
controller. You can also pass the resulting query of a find method:
Maybe is this? I use the find() method with the cache option and then I pass the results to paginate()?.
Thanks.
I would not avise towards caching queries, specially not the results of a pagination. But you idea is in theory right:
$aKeyThatEncodesQueryStringAndConditions = ...;
$this->paginate($this->Users->find()->cache($aKeyThatEncodesQueryStringAndConditions));

Installing and using the Uploader plugin

I am trying to get my head around the documentation for installation and use of this Uploader plugin for CakePHP 2.x which deals with uploading of files. I have a few questions I hope somebody could help me with. There's quite a good thread on the topic, Installing Uploader Plugin for CakePHP 2.x, but I wanted to clear some things out which are not that clear in the thread (to me at least).
Btw the authors page: http://milesj.me/code/cakephp/uploader
Is it right that if you want to save manually (without the behaviour), the installation is as follows:
CakePlugin::load('Uploader'); // THIS GOES INTO THE BOOTSTRAP.PHP FILE PER THE REFERENCED QUESTION ANSWER
App::import('Vendor', 'Uploader.Uploader'); // THIS GOES INTO CONTROLLER PER THE REFERENCED QUESTION ANSWER
$this->Uploader = new Uploader(); // THIS GOES INTO CONTROLLER PER THE REFERENCED QUESTION ANSWER
Is that right?
BUT, if you are using the behaviour instead you don't do ANY of that above for installation, instead you do ONLY in model:
public $actsAs = array('Uploader.Attachment');
Is that right?
Is chapter 2 of the documentation only applicable for when using the plugin manually? Otherwise, you configure the model behaviour per chapter 3 only in the model.
Final question: So if I understand this right (I am still a little new to CakePHP), if I am using the behaviour to do the save automatically, whenever I upload a file to that model, it will automatically save the file in the right folder without me having to do anything and put a reference in the $data variable which is pointing to the saving location?
Thanks in advance!
I had such trouble getting this to work and understanding the whole plugin and behaviour thing so I thought it would be worth sharing quickly what I have learnt in a short video on how to install, implement and use the Uploader plugin through the model behaviour.
http://www.youtube.com/watch?v=lMNUOz8wqzE
Hope you find it helpful. To answer my questions above, I basically only have to:
Include the CakePlugin::load('Uploader'); in the bootstrap.php
file which can be found under App/Config/
Call the behaviour inside my model as per public $actsAs =
array('Uploader.Attachment'); but with the relevant options
configured
Then just save to the model, through my controller, and in the model I have included the $actsAs variable
The beforeSave callback function which has been defined in the Attachment behaviour in the Plugin will take care of the rest.
Uploading file seems to be such a mundane tasks so I suppose it is very appropriate to do it through a behaviour, and I don't want to write my own behaviour given my own beginners level so it's good that Miles has, particularly since he's an experienced developer. After reading up, uploading files using controller code is not the way to go, using expert developers plugin's probably is THE way to go.

cakephp plugin calls a model I already have set up

In my cakePHP app I am implementing Miles Johson's Forum Plugin (http://milesj.me/code/cakephp/forum).
It creates a model named Profile in the plugin. I already have a model named Profile in my normal app, and as a result am getting a lot of errors when I use the forum. Combining the two models into one doesn't seem like a good option because they are used for very different purposes.
Is there an easy way to change model names in a plugin without hours of searching for every instance of "Profile" or "Forum.Profile" and changing it to "ForumProfile" and "Forum.ForumProfile"?
Thanks!
You could try to add another connection to your database.php, something like 'forums' and configure it to use a prefix 'forums_'. In the ForumsAppModel override the constructor and use your forums connection and prefix. You'll need to prefix all you forum tables with 'forums_'.
I do not understand why the forum plugin was not directly done with prefixes for the tables and everything.

Paypal Integration in Cakephp

i really can't seem to make it.. im frustrated learning this for almost three days now however im still trying. What i actualy wanna happen is this:
Customer fills up order form
After filling up, he will click the "Buy now" button at the bottom of my page.
I would like to extract the data the user have entered from the order form and save it to may database.
Dunno if it has something to do with the IPN or PDT stuff. The point is im cant move forward for three days now. I wanna know how this starts of perhap ah pseudocode of what i can actually do with this?
I mean where can i possibly start. Okay i downloaded the plugin and extracted it in /app/Plugin/, and then? I have read the manual and tried various tutorials but it's not getting me anywhere. Im totally a beginner. Please help.
this is an update with im doing.
i got this error:
Error: PaypalIpn.PaypalHelper could not be found.
Error: Create the class PaypalHelper below in file: C:\xampp\htdocs\wifidrivescanportal\app\Plugin\paypal_ipn\View\Helper\PaypalHelper.php
<?php
class PaypalHelper extends AppHelper {
}
Since you said this is cake 2.x, make sure that your plugin is loaded:
http://book.cakephp.org/2.0/en/plugins.html#installing-a-plugin
Since cake 2.0, plugins need this to work. Also, make sure that the plugin you're using is made for Cake 2.x versions, not an earlier one, because they are not compatible.
This is because you did'nt configure your global bootstrap. Add the following line to your cakephp/app/Config/bootstrap.php and it should work!
CakePlugin::load('PaypalIpn', array('bootstrap' => array('paypal_ipn_config'), 'routes' => true));
you didnt mention your cake version - which you ALWAYS should.
but I assume it is 2.x
so why aren't you naming your plugin after the convention?
paypal_ipn should be PaypalIpn

Why use JsHelper for jQuery integration?

I was trying to integrate jQuery to use it for some effects in my site and I started to search for the solution of integrating in the best way. It simply came to my mind to write a helper which would get the selector of proper element and output the javascript code.
Then I ran into the new JsHelper in cake 1.3 but I'm really having problems understanding the concept of JsHelper. I mean for sure each JavaScript block that I'm gonna write is more than one call to jQuery methods and many of them are also not transfered to JsHelper. So for what reason may I use the JsHelper? it would be much easier to write the javascript specified for my action inside a helper and use it simply as any other helper. The only thing which comes to my mind as a good capability is to use the caching and buffering options provided in JsHelper nothing more. Did I understood the JsHelper well or I have missed some points?
FWIW, I never use any of the javascript helpers except to write the include, i.e.
<?php echo $javascript->link('aJavascriptFile') ?>
I'd be pulling my hair out trying to find out why some jQuery plugin wasn't working if it was all wrapped up in helpers.
You don't have to use helpers - they're there to help. Sometimes people go a bit crazy and start creating helpers for stuff that really doesn't justify the weight of extra code.
Just code it the 'old way' and keep your sanity.

Resources