cakephp-2.1

Want to create a custom function

不羁的心 提交于 2019-12-08 10:40:23
问题 I am working on a CakePHP 2.x .. I want to create a special class in which I want to create functions so that I can call functions from other controllers. For example this function function replace_dashes($string) { $string = str_replace("-", " ", $string); return $string; } So whenever I want to use that function in some other controller I can call this or can pass parameters too ... I want to implement all the raw functions like this in some class. How can I do this in CakePHP? 回答1: Its not

How to create a seperate directory for admin controller in cakephp

蓝咒 提交于 2019-12-08 07:56:50
问题 I am new to cakephp development. I have create user controller to register, login & update own profile in the user table. I can access the user controller with http://local-host/my_project/user/login . I have also a admin table in database so that admin can login and manage user in my project. I want to create a folder separate folder (ex: admin) in the controller directory so that i can access the controller files using http://local-host/my_project/admin/controller/login & http://local-host

Cakephp How to validate my D.O.B field so that the age will not be greater than the period of residence entered

只愿长相守 提交于 2019-12-08 04:52:48
问题 i have two fields in my form that should correspond to each other.If a users enters the date of birth,in the D.O.B field,he/she must not be allowed to enter a period of residence greater than the D.O.B my two fields in the add.ctp are as follows echo $this->Form->input('DOB',array('label' => 'Date of birth*', 'minYear' => 1900, 'maxYear' => 2000)); echo $this->Form->input('period_of_residence', array('label' =>'Period of residence in Zimbabwe')); So now i don't know how i validate the two so

Disabling Security Salt for plain MD5 hashing in AuthComponent?

放肆的年华 提交于 2019-12-08 04:07:25
My CakePHP 2.1 app shares its user database table with another app. In order for users to be able to login into both applications, the password field needs to be hashed in plain MD5. Changing the other app or the database is not an option. I am able to change the hashing algorithm from SHA1 (the default?) to MD5 by the following: <?php // AppController.php public function beforeFilter() { Security::setHash('md5'); } ?> And I can add new users to the system with plain MD5 passwords: <?php // User.php public function beforeSave() { if (isset($this->data['User']['password'])) { $this->data['User'

CakePHP 2.1 find using contain with condition

ⅰ亾dé卋堺 提交于 2019-12-08 03:31:01
问题 I have the following models. Industry(id, name) Movie(id, name, industry_id) [Industry has many movies] Trailer(id, name, movie_id) [Movie has many trailers] I need to find 6 latest trailers for each Industry . Every movie does not need to have a trailer or can have multiple[0-n]. The results must contain array of movies with atleast one trailer. $this->Industry->find('all', array( 'contain' => array( 'Movie' => array( 'Trailer' => array( 'limit' => 1 ), 'order' => 'Movie.release DESC',

CakePHP - Include class from a directory outside the app directory

丶灬走出姿态 提交于 2019-12-08 01:41:06
问题 I am trying to include a miscellaneous library class from outside my app (it gets used by different apps). My app is located at: /var/www/websites/my_website/app/ And the class is located at: /var/www/websites/libs/CakePHP/MyClass.php In my bootstrap I'm struggling to figure out how to add the path for loading the classes from that directory: App::build(array('Lib' => array('/var/www/websites/lib/'))); App::uses('MyClass', 'CakePHP'); $myClass = new MyClass(); 回答1: Loading shouldn't be done

User sessions and two CakePHP applications running in the same machine

坚强是说给别人听的谎言 提交于 2019-12-07 12:32:17
问题 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();

CakePHP 2.1 Ajax validation errors

旧时模样 提交于 2019-12-06 15:55:01
问题 I'm trying to get validation errors with Ajax and jQuery working in CakePHP 2.1 for a contact form. On blur of the name field a js function is called: $(document).ready(function(){ $('#name').blur(function(){ $.post( '/Cake_ajax/Contacts/validate_form', { field: $(this).attr('id'), value: $(this).val() }, handleNameValidation ); }); function handleNameValidation(error){ if(error.length > 0){ if($('#name-notEmpty').length == 0){ $('#name').after($('<div id="name-notEmpty" class="error-message"

CakePHP - Include class from a directory outside the app directory

安稳与你 提交于 2019-12-06 14:15:30
I am trying to include a miscellaneous library class from outside my app (it gets used by different apps). My app is located at: /var/www/websites/my_website/app/ And the class is located at: /var/www/websites/libs/CakePHP/MyClass.php In my bootstrap I'm struggling to figure out how to add the path for loading the classes from that directory: App::build(array('Lib' => array('/var/www/websites/lib/'))); App::uses('MyClass', 'CakePHP'); $myClass = new MyClass(); Loading shouldn't be done in your bootstrap, but in your AppController 's beforeFilter method instead. Also, there is a reserved place

CakePHP: How to use Containable for nested HABTM models

有些话、适合烂在心里 提交于 2019-12-06 13:06:12
I'm trying to use Containable to return a model with several of its associated models (and those arrays of data). The models deal with test results. Here are the models: Models: Question : has and belongs to many Category Category : has and belongs to many Question Attempt : has many AttemptedQuestions AttemptedQuestion : belongs to Question I want to return an Attempt with all of it's AttemptedQuestions and their corresponding Quesions + Category So basically, the relationships map like this: Attempt => AttemptedQuestion(s) => Question => Category I suspect that because of the HABTM