cakephp-2.0

CakePHP 2 - Validating password fields

假装没事ソ 提交于 2019-12-06 09:39:16
问题 I have some problem with Cakephp 2 validation. I am trying to validate several fields on an Edit form. Some of them are a password and confirm password fields. I want to validate both only if they are supplied. If they are empty I dont change the password, but if the user writes over them I would like to validate if they have a minLength or the passwords matchs. Code: 'pwd' => array( 'length' => array( 'rule' => array('between', 8, 40), 'message' => 'Your password must be between 8 and 40

Cakephp how to create virtual field based off another table

爷,独闯天下 提交于 2019-12-06 07:42:12
问题 I have 2 tables: projects, project_types. The relations are as follow: Project => belong to => ProjectType ProjectType => hasMany => Project The columns are as follow Project => id, project_type_id, name, description ProjectType => id, name How can I create a virtual field called projectTypeName with the name from projectType based on project_type_id and for those that project_type_id = 0, it will be "" I have this public $virtualFields = array( 'projectTypeName' => "IF(Project.project_type

Cake PHP 2.4.x. AuthComponent login() always return true

前提是你 提交于 2019-12-06 06:46:58
问题 Sorry for the VERY long question, but I am having problems with auth->login() and after long hours of debugging, I would like to share my findings. It may well be something stupid on my side, but bear with me... Model "Cliente" (relevant parts): <?php App::uses('AppModel', 'Model'); App::uses('BrValidation', 'Localized.Validation'); App::uses('AuthComponent', 'Controller/Component'); App::uses('SimplePasswordHasher', 'Controller/Component/Auth'); /** * Cliente Model * */ class Cliente extends

Dynamically created datasource not being passed to associated models in CakePHP

≡放荡痞女 提交于 2019-12-06 06:20:24
问题 I have a Model - Car - the Car has several associated models, lets consider one of them which is linked with the hasMany relationship - Wheel In my CarsController, I dynamically generate a datasource using the following code - $schemaName = $this->Session->read('User.schema'); $config = ConnectionManager::getDataSource('default')->config; $config['database'] = $schemaName; ConnectionManager::create($schemaName, $config); Then I set this datasource in my Car Model using the following line of

How to make cakePHP 2.x in sub directory appear in root (with mod_rewrite in htaccess)? [closed]

百般思念 提交于 2019-12-06 05:41:15
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm working on an cake app which is inside a sub directory (because I need to run it along side another app on the same domain). I want the pages powered by cake to appear as if they'r e top level. So instead of example.com/cake_dir/page... I want example.com/page... I think the best way to make this work is by adding a rewrite rule to an .htaccess file, so here's what I want to know: Is this the best way to do

CakePHP Fulltext search MySQL with rating

核能气质少年 提交于 2019-12-06 04:55:54
I've read that, to be able to rank search results you may query MySQL like this: SELECT * , MATCH (title, body) AGAINST ('$search') AS rating FROM posts WHERE MATCH (title, body) AGAINST ('$search') ORDER BY rating DESC Is there a way to do this in CakePHP 2.X? Also, I need to do this while paginating at the same time. So I think I would need to write condition for the paginator, not a direct 'query'. Thanks for your help! Sandeep Kundu Use like this it will prevent mysql injection too array("MATCH(User.current_position) AGAINST(? IN BOOLEAN MODE)" => $srch_arr['text']) Ok, it took me some

CakePHP 2.1 - Custom Validation Rule - Check for Unique Field Value Combination

让人想犯罪 __ 提交于 2019-12-06 03:28:46
I have a couple of columns (ip, provider_id) for which I want combinations of values to always be unique. Therefore, I am trying to build a custom validation function. But I am having issues grabbing on the value of the secondary field. This is my code so far in the model: public $validate = array( 'ip' => array( 'rule' => array('uniqueClick', 'provider_id'), 'message' => 'The click is not unique.' ) ); public function uniqueClick ($ip, $field) { $count = $this->find('count', array('conditions' => array('ip' => $ip, 'provider_id' => $field))); // echo $field; return $count == 0; } So the

CakeEmail debug

人盡茶涼 提交于 2019-12-06 01:21:39
I'm trying to set up a test email in my controller that outputs the email as it would look, without actually sending the email. I am using CakePHP 2.1 At the top of my controller I have: App::uses('CakeEmail', 'Network/Email'); And in my controller the method is: $email = new CakeEmail('default'); $email->from(array('me@example.com' => 'My Site')); $email->to('you@example.com'); $email->subject('About'); $email->send('My message'); In my email config I have set the $default to Debug mode: public $default = array( 'transport' => 'Debug', 'from' => 'you@localhost.com', //'charset' => 'utf-8', //

CakePHP bake Error: Database connection “Mysql” is missing, or could not be created

让人想犯罪 __ 提交于 2019-12-05 21:22:20
I've already checked other questions and answers regarding my issue and nothing seems to help resolving it. I'm using vagrant percise64 (ubuntu server 12.04) with lamp installed. On my host (desktop) I have myfinalproject dir containing extracted cakePHP version 2.3.5. I've set all that cakePHP required and on the generated page of cakePHP it says that "Cake is able to connect to the database." When I try to bake a new Model/Controller or All I get the following error: Welcome to CakePHP v2.3.5 Console --------------------------------------------------------------- App : app Path: /home/shahar

User sessions and two CakePHP applications running in the same machine

跟風遠走 提交于 2019-12-05 20:29:33
I have 2 CakePHP applications running on the same machine. Both of them need a previous registration to have access to them and the first thing users see is the login form. I have realized that when I do login in one of them, then, I can access to the other web application without being asked for my credentials to login. (which is not correct) In my Controllers of both applications I have this to deny access without a previous login. public function beforeFilter(){ parent::beforeFilter(); $this->Auth->deny(); } But this seems not to work properly when I use the same browser and I do login in