jQuery image upload & crop by cakephp - cakephp

In my project, image need to upload and crop. So, I have taken help from http://bakery.cakephp.org/articles/klagoggle_myopenid_com/2010/08/25/jquery-image-upload-crop
By this instruction I have created file jq_imgcrop.php and with code saved it in app/controllers/components and also created cropimage.php and saved it app/views/helpers
after that I add the component and the helper in my controller where I want to use the cropload.
code given below
App::uses('AppController', 'Controller');
App::uses('BarcodeHelper','Vendor');
/**
* OesUsers Controller
*
* #property OesUser $OesUser
*/
// set the default timezone to use. Available since PHP 5.1
class OesUsersController extends AppController {
var $helpers = array('cropimage');
var $components = array('jq_imgcrop');
After saved, it is giving me a error that is "Missing Component!!"
In this define directory, have I made any mistake?

The article in the link is written in cakephp 1.x.

Related

CakePHP update public $uses = false; in action from same Controller

I'm writing an installation script for my CakePHP web application. I have a InstallController with 6 actions: step1, step2, step3, etc.
At step1 I'm handling Config/database.php creation. Because this file is empty and no datasource is available I have to set public $uses = false; in the InstallController.
At step2 the Config/database.php file is set so I should be able to make a connection to the datasource. This is also necessary because I want to update some database fields in the following steps.
Is it possible to update the public $uses = false; in every following steps after step1?
I'm using CakePHP version 2.3.5
Have you considered loading the model within the actions? So, something like:
<?php
App::uses('AppController', 'Controller');
class InstallController extends AppController {
public $uses = false;
public function step1() {
}
public function step2() {
$this->loadModel("Install");
$this->Install->callMethod();
}
}
In CakePHP 2.x models are lazy loaded, so as long as your step1 action doesn't try to make use of a model, you can safely declare the models in your controllers $uses property, they are not being constructed until your code actually makes use of them.
However, if for some reason you'd actually need to modify $uses, well then just do it, as mentioned models are lazy loaded, so you can modify $uses whenever you want and then access the models afterwards via magic properties on the controller.

CakePHP - Missing controller view - $_SESSION not available

We are experiencing an issue when an invalid url is passed to cake. This loads the missing_controller.ctp view correctly but $_SESSION variable is empty.
We have tested this on 1.3 and 2.0 and in both version $_SESSION is empty when the missing_controller view is rendered.
Is this done on purpose?
Thanks
Regards
Gabriel
Did you imported the Session component in Controller? Like this:
<?php
class MissingController extends AppController{
var $components = array('Session');
var $helpers = array('Session');
}
Try to access the data in $_SESSION with $this->Session->read('This.That');

CakePHP 2.0 can't access Model from its own Controller

I'm still trying to migrate from CakePHP 1.3 to 2.0
I have a Controller UsersController and its Model User.
The class User has some constants which I could easily access from the UsersController using User::constant. But for CakePHP 2.0 it doesn't work: I get an error saying the User class is not found. It works if I App::Import('Model', 'User');.
It sure has to do with their built-in lazy loading in 2.0!
you simple need to tell this file that it has other dependencies
do that at the very top of your UserController file:
<?php
App::uses('User', 'Model');
then everything works fine
You can try setting the controller name (in UsersController):
var $name = 'Users';
Or using the "uses" var (in other controllers:
public $uses = array('User');
Does that not work?
Did you declare the name of the model like that ?
class User extends AppModel {
public $name = 'User';
}
Do you have others variables in your UsersController ?
I set variables in the model like this:
//Person model
public $genders = array('m' => 'male', 'f' => 'female');
Then get them from the controller like this:
//People controller
$genders = $this->Person->genders;
No special code needed. (Is this what you're talking about?)
Also, I don't believe you need to set the $name variable anywhere anymore - I think that was just for PHP 4. (not 100% on that part, but... I don't ever set that anymore, and my Cake2 apps run fine)
You have to load the model like this:
$this->loadModel('User');

Cakephp missing helper file error

I'm getting below error...I'm not sure what this means as I have included helper file in the view file...
Missing Helper File
Error: The helper file track/views/helpers/request_handler.php can not be found or does not exist.
Error: Create the class below in file: track/views/helpers/request_handler.php
<?php
class RequestHandlerHelper extends AppHelper {
}
?>
If you can let me know what this means that would be appreciated!
Thank you.
Jae
Unless you customized how your CakePHP works, this should apply to most cases:
Checklist
Make sure the helper file is created in /app/views/helpers/request_handler.php
Make sure the content of the request_handler.php looks like this:
class RequestHandlerHelper extends AppHelper {
var $name = 'RequestHandler';
//bla....
}
Make sure in the controller that renders the view has the helper array included
class FancyController extends AppController {
var $name = 'Fancy';
var $helpers = array('RequestHandler');
//bla....
}
I think that's all :)
Cheers
you have to include the helpers in the controller (app_controller if you want the helper to be available for views of all controller)
var $helpers = array('Form', 'Html', 'YourHelper');
If you are using any version of CakePHP, just open the file core.php in the folder config and edit the line Configure::write('debug', 0); to Configure::write('debug', 2);
It will say the erro and how to create the file and where to put it.

How to add helper or component on-the-fly with the controller action method

i don't want to add it as below cause i needed them only once in certain action method
(so do not useless load the memory)
class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Session');
var $components = array('Session', 'Email');
class UsersController extends AppController {
public function method_name() {
$this->helpers[] = 'MyHelper'
}
}
More on this in the documentation.
Hope that helps.
You can load helpers using
$this->helpers[] = 'MyHelper';
as Rob mentioned above, but this won't work for controllers because they have their initialize and startup methods that need to be called in order for them to work.
I've come across a bit of code on the web for loading components inside of a controller action: ComponentLoaderComponent
Yes, it is a component but it isn't very big so it shouldn't be a problem to include it in your controllers.
Either that or you can just study it to see how the component loading works and then write your own controller action to do the same.
I use a component for adding helpers and components on the fly:
$this->Common->addHelper('Tools.Datetime');
$this->Common->addHelper(array('Text', 'Number', ...));
$this->Common->addComponent('RequestHandler');
$this->Common->addLib(array('MarkupLib'=>array('type'=>'php'), ...));
etc
The complete code to this can be seen in the cakephp enhancement ticket I just opened:
http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/1277
Or with php markup:
http://www.dereuromark.de/2010/11/10/loading-classes-on-the-fly/
It also fixes some minor problems with the solution posted by mtnorthrop.
Plugins as well as passed options are now possible. Have fun.

Resources