FAQ Database Discussion Community


How to use: $this->Auth->user('id') in a model? Cakephp 3.0

cakephp,authentication,model,cakephp-3.0
I've been working on the skinny controller fat model way. Before, I used this in my controller: $this ->find('all') ->contain(['Declarator']) ->where(['user_id' => $this->Auth->user('id')]) ->order(['Declarations.created' => 'DESC']); However, $this->Auth->user('id'), doesn't work in a model. What other way is there to get the id from the authenticated user in a model?...

How to fix Undefined offset and Could not find validation handler for name

php,validation,cakephp
My Validation code is like this: public $validate = array( 'name' => array( 'rule' =>array( 'rule'=>'notEmpty', 'required' => true , 'allowEmpty' => false , 'on'=>'create', 'message' => 'This field cannot be left empty' ) ), 'email' => array( 'rule1' => array( 'rule' => 'isUnique', 'required' => true, 'allowEmpty' => false,...

Pagination in home.ctp not clickable data

cakephp,pagination
home.ctp <?php echo $this->element('distromob/featured'); ?> WebsitesController.php <?php class WebsitesController extends AppController { public $components = array('Paginator'); public function index(){ $images = $this->paginate('Website'); if (isset($this->params['requested'])) { return $images; } else { $this->set('images', $images); } } featured.ctp <?php $images = $this->requestAction('/Websites/index'); ?> <ul> <?php foreach($images as $image): ?> <?php $domain =...

how to call controllers from the cakephp default layout?

php,cakephp,cakephp-2.0
I have a controller called UsersController, is there a way I can output some values from this controller to the cakephp default layout? Here is what I have tried, the default.ctp: <?php foreach ($users as $user): ?> <ul class="nav navbar-nav navbar-right"> <?php if (!$this->Session->read('Auth.User.id')) : ?> <li> <?php echo $this->Html->link('Login',array('controller'...

File not Uploading using Ajax in cakephp

php,jquery,ajax,file,cakephp
Am trying to upload an image using Ajax to server. I know the code to upload file using Cakephp, but first i just want to make sure that data/file is uploaded to server for sure by printing the formdata. But it seems that only the data i typed in the...

Changing the order items are retrieved from the DB in CakePHP?

php,cakephp
I've made a forum using CakePHP while following a tutorial and would like to expand it. Currently, in a post it allows me to comment, but they are displayed as newest -> oldest, so it doesn't make as much sense and I would like to reverse this. This is the...

CakePHP 3 Multiple BelongsTo Associations

php,cakephp,cakephp-3.0
I am using cakePHP version 3.x. When i query the MessagesTable i want to get the Users data for the the sender and the receiver of the message. I have done this many times in cakePHP 2 but i cant figure out why it isn't working in version 3.x. i...

Port a MVC PHP project into CakePHP

php,cakephp
I'm new with CakePHP and I want to convert an existing PHP project into CakePHP. This project is already written using MVC, however the structure is not clear, models are not match with databases,different logic... (e.g. When I need to find something I cannot know where to look for.) My...

Set data from database to generated popup window in CakePHP

cakephp
I have created a popup window in cakephp. <div id="pop_box"> <span id="close">&times;</span> <h2>This is the Popup Box</h2> <span id="selected_content"></span> </div> Now I want to set data to this popup window by getting data from database(MySql). Normally we are getting data from database for a new page using functions in controller....

Cakephp select disable field value send failed

cakephp,scala-2.9
This page actually a preview where user can't change anything,that he has given before.I have tried bellow code, echo $this->Form->input('exchange_type', array( 'disabled' => 'disabled', 'empty' => '--Please Select--', 'options' => array( '6' => 'POINT_TO_PRODUCT', '7' => 'POINT_TO_GIFT', '2' => 'POINT_TO_GAME' ) )); Here field has disabled but it's sending null...

Cakephp Find all WHERE in two categories

php,cakephp,find,cakephp-2.3
I have trouble finding items that belong to two or more categories in cakephp 2. In my Controller I have the following: $kategories = array(1,2); $options['conditions'] = array('Categorie.id' => $kategories); $items = $this->Item->find('all',$options); The query above shows all Items that have either associated category-id 1 or 2. How can I...

cakephp 3.0.x extending view?

php,cakephp,cakephp-3.0
I'm using cakephp 3.0.x and I wanna make a page that has multiple views in it. E.g. If I have these index.ctp from other Templates like below Template/Customers/index.ctp Template/Orders/index.ctp i want to make a page say Template/Main/index.ctp. That contains the index.ctp from Customers and Orders. Essentially, views in a view...

HABTM CakePHP no results for related model

cakephp,cakephp-2.0,has-and-belongs-to-many
I have problem with HABTM models. When I try to fetch any related model f.e. like this: $this->Tagi->find('first'); I dont get any results for associated model. Result looks like this: array( 'Tagi' => array( 'id' => '1', 'nazwa' => 'sth' ), 'Instytucje' => array() ) I am sure that there...

Change language in CakePHP

php,cakephp
I am trying to implement language changing buttons in my CakePHP app. I followed the cookbook (http://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html) and now I am able to change language after the user is logged in. My language buttons are linked to actions in my own LanguagesController that looks like this: public function sk() {...

CakePHP Missing out AND statement on Query

php,mysql,cakephp
I have a problem where I have a Find in Cakephp that is designed to look for users that are busy in a calendar app. However when I look at the MYSQL query it doesn't look right. Find Statement: $result = $this->EventsUser->find('all',array('conditions'=>array( 'OR' =>array( 'AND' => array( 'Event.start >=' =>...

How to increase cakephp Auth component session expire time

php,cakephp,cakephp-3.0
I am using Auth component to check user is logged in. Here is my AppController's initialize function public function initialize() { parent::initialize(); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => [ 'Form' => [ 'fields' => [ 'username' => 'username', 'password' => 'password' ], 'passwordHasher' => [ 'className' => 'Md5',//My own password hasher...

CakePhp 2.6.3 Auth component not working. Accepting any userID/password combination

cakephp,cakephp-2.6
I have been trying to get cakephp 2.6.3 auth component for my site to work for a week now. The problem am facing is that when ever I enter any bogus user ID/password combination, the login function returns true. i have read all is there to read and watched tutorials...

Cakephp Version 2.x Unable to Show selected file name in edit view

php,cakephp,file-io,editview
Hopefully this is a simple issue. I have a Cakephp MVC set to upload an image and store it in a database table. Index, View and Add are working as I want. However, in the Edit view how can I indicate that the record currently has an uploaded image that...

conditions OR in join cakephp

php,mysql,cakephp
I am a novice in cake and I'm having trouble with a query I want to do in a tables. $options['joins'] = array( array('table'=>'users_views', 'alias' => 'UserView', 'type' => 'inner', 'conditions' => array( 'View.id = UserView.view_id', 'UserView.user_id' => $user_id, 'UserView.like' => 1 ), ) ); $options['order'] = array('View.created' => 'desc');...

How to Receive JSON sent from clent side to server Side in cakePHP 3.x

cakephp,cakephp-3.0
I am receiving A String instead of Json. i am accessing received json using $this->request->input() My Add method is as follows: function add() { if (!empty($this->request->input())) { $this->loadModel('crud'); if($this->crud->save( $this->request->input() ) ) { $this->Flash->set("Operation Completed."); $this->set('message',"Your user data has been saved."); } else $this->set('message',"Error."); } } ...

Cakephp 3 - MissingDatasourceConfigException when running phpunit test

php,unit-testing,cakephp,phpunit,cakephp-3.0
I am trying to run some unit tests in CakePHP 3 with PHPUnit 4.7.3, but I`m getting the following error: PHPUnit 4.7.3 by Sebastian Bergmann and contributors. There was 1 error: 1) App\Test\TestCase\Model\Table\MoviesTableTest::testFindMoviesByGenre Cake\Datasource\Exception\MissingDatasourceConfigException: The datasource configuration "default" was not found. C:\xampp\htdocs\movie-pal\vendor\cakephp\cakephp\src\Datasource\ConnectionManager.php:188 C:\xampp\htdocs\movie-pal\vendor\cakephp\cakephp\src\ORM\TableRegistry.php:191...

cakephp use record values in afterDelete

cakephp,cakephp-3.0
I am using the soft delete plugin for my EmployeesTable.php in CakePHP 3.0. When I soft delete an employee I wish to update their associated user table with $user->set('active', false); within the afterDelete() My problem is getting the user_id used in the employees table into the afterDelete() I have even...

Cakephp 2 : Have two different authentication functions

php,cakephp,authentication
I am using a custom authentification object in cake php. I have created a file in component/Auth/LdapAuthenticate.php. In this file I have a function who made the authentification with LDAP. It looks like this: App::uses('BaseAuthenticate', 'Controller/Component/Auth'); class LdapAuthenticate extends BaseAuthenticate { public function authenticate(CakeRequest $request, CakeResponse $response) { $username=$request->data["Users"]["username"]; $pwd=$request->data["Users"]["password"];...

Different find results between cakephp 2.5 and 3.0

cakephp,cakephp-3.0
I am migrating my app from cakephp 2.5 to 3.0 and I am doing a ->find() method and then looping over the results in the controller. However I am getting different results returned in 3.0. I seem to be getting the query settings that cakephp uses before going to the...

CakePHP on Shared Windows Plesk Server

cakephp,plesk
I am wondering if it is possible to get CakePHP working on a shared Windows Plesk server? I have extracted the CakePHP files to the /httpdocs/ folder, and have created a web.config file as per the instructions in the CakePHP docs, however all I seem to get is an 'Internal...

postLink() in cakePHP 3.x

cakephp,hyperlink,delete
I just created the CRUD operations in cakephp 3.x. I am deleting the records using postLink() function. $this->Form->postLink("<i class='fa fa-remove'></i>", ['action' => 'delete', $role->id], ['escape' => false],['title' => 'Delete', 'class' => 'users'])]); It doesn't set the class for my delete icon. I need set the class name for this delete...

Disable password hashing for particular users

php,cakephp,cakephp-3.0
We are using a single table for both admin and normal users. We need to save the admin password in hash format, but save the user password in plain text. How do do that with CakePHP 3.0 EDITED: User's username and password are used as a login credentials on another...

Best rules to get data with Contain

cakephp,cakephp-3.0
In CakePHP 3 ORM has changed and I can't find the proper way to select needed data from the database. In CakePHP 2, I use contain('User.name','User.id'), but In CakePHP 3 this code doesn't work. So how can I select only id and name from User? The code: $query = $data->find()->contain(['Users'])->execute()->fetchAll('assoc');...

Radio Button CakePHP 3.0

php,cakephp,cakephp-3.0
In CakePHP 2.0 I can actually add 'before', 'after' and 'separator' attributes to the radio button. The attributes will create a div element between my radio options. It seems like these options have been removed from CakePHP 3.0. How can I do that in CakePHP 3.0? <div class="col-xs-6 col-sm-6 col-md-6...

Cakephp: How to use migration to insert records

php,sql,cakephp,cakephp-3.0
I'm using CakePHP v3.x and I'm trying to figure out how to insert some records via the migrations tool. The documentation only lists methods for modifying the schema. Will I need to insert records manually with raw SQL?

can I consider GitHub Issue equals Number of Bugs for a project? [closed]

php,cakephp,github,frameworks
According to this paper written by Steve Cornwell, Industry average of Bugs in 1K lines of code (BKLOC) is: 15-20. So for php framework that are on GitHub, can I consider GitHub Issue equals Number of Bugs (BKLOC)? for example for cakephp this nubmer is 2433 (114 Open Issues +...

Change password function not working - hash wrong

cakephp,authentication,hash,passwords
Ok, I've been hitting my head against this wall all evening. Can someone explain to my why this returns false (user model): public function changePassword($user_id, $currentPassword, $newPassword, $repeatPassword){ //Check repeat /* if($newPassword != $repeatPassword) return false; */ //Check old password $this->id = $user_id; $current = $this->field('password'); $passwordHasher = new BlowfishPasswordHasher();...

print_r on array set in view on cake just prints 'Array'

php,arrays,cakephp
I am setting a array in my controller by: $messages = array("Apples", "Oranges", "Pears"); $this->set('messages', "$messages"); However then in my View if I try to print the array with: <?php print_r($messages); ?> I just get the word 'Array' not the actual content of the array. Trying to access elements of...

issue Login cakephp

cakephp,login
i'm new cakephp and i have 1 question, please help me! I have 1 table name quan_tri_viens same users, but i don't use table users i read and follow the instructions http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html but i can not sign in Model: QuanTriViensController <?php App::uses('AppController', 'Controller'); class QuanTriViensController extends AppController { public function...

cakephp 3 multi level associated save

cakephp,cakephp-3.0
I have a Users model which has a hasOne relationship to an Employees model. When I save a user I also add a record in the Employees table with the user_id. This works fine. The Employee can be associated to belongsToMany Courses through CoursesEmployees table. This saves ok when I...

make SQL function SUBSTRING_INDEX work in cakePHP query builder

cakephp,cakephp-3.0
I have a fullname column for authors and would like to extract the surname into another column. I do that with the following raw SQL: SELECT name, SUBSTRING_INDEX(`name`, ' ', -1) AS `surname` FROM qr.authors; Output: Under "Using SQL Functions" the Cookbook says: In addition to the above functions, the...

How can we validate multiple fields with one validation in cakePHP 2.0?

php,cakephp
how can we check firstname and last name is unique validation in cakePHP ? record1: first name :raj last name: kumar if we enter same name in input field , it should show validation message "Record alredy Exists". i know how to validate single field validation. how to validate that...

I need to count the today created account in Cake 3

cakephp,cakephp-3.0
I need to count the users, but my condition is only if their account have been created today. I have a users table with a created field (datetime) for each rows. How can i do it in Cakephp, i didn't find the answer in the documentation. $usersNewCount = Number::format($this->Users->find()->where(['created' =>...

Remove resource wrapper from CakePHP REST API JSON

rest,cakephp,cakephp-2.2
My question is similar to this one. I understand the answer given there. The OP of that question doesn't seem to have my issue. I am using CakePHP 2.2.3. I am fetching a resource like this: http://cakephpsite/lead_posts.json and it returns results like this: [ { "LeadPost": { "id": "1", "fieldA":...

Uploading image in cakephp and storing it's path in database

php,cakephp
I have a form in which i am trying to upload image and trying to store that in database. My Controller Code is: class OlxProductsController extends AppController{ public function post(){ if($this->request->is('post')) { if ($this->request->data['OlxProduct']['img_upload']) { $file = $this->data['OlxProduct']['img_upload']; //put the data into a var for easy use // print_r($file); $filename...

Sql date between query with a date and number of days

php,mysql,date,cakephp
I have a table called Renewals as follows id | item_name | next_renewal_date | alert_before_days 2 | Test | 2015-05-25 | 5 6 | Test4 | 2015-05-12 | 2 7 | Test7 | 2015-05-30 | 12 I would like to read the table by alert_before_days. For example, i need the...

CakePHP 1.3 - Extract URL GET parameters

php,url,cakephp,get,cakephp-1.3
I have CakePHP 1.3.2 application working with similar URLs: /controller/action/name1:value1/name2:value2.html I'm trying to extract the values after the : sign specified by the names before that. I can see the whole URL with no problem using $this->params['url'], however, I can't get the value itself using neither $this->params['name1'], nor $this->params['url']['name1']. Any...

Different cakephp datasource for local and live

cakephp,cakephp-3.0
My MySQL connection details are different for both my local connection and my deployed live hosted. I am using CakePHP 3 At the moment I have to keep changing the default datasource which is not really the best way to do it. I have not added two datasources but I...

Retrieve records on matching a field in any 2 tables out of 4 tables

mysql,cakephp
I have four tables with same fields. Now I want to join these tables in such a way that I retrieve records only if there is a match between any two tables on a field(like name). Thanks in advance.

CakePHP Unable to insert to database (datetime format)

database,datetime,cakephp,insert
I was new to Cakephp and I actually following the tutorial of the Blog tutorial however I didn't follow their database and try my own. Currently my database: My Model: class FypCakephp extends AppModel { //Table Name public $useTable = 'Report'; public $primaryKey = 'report_id';} My Controller: public function add()...

ftp_get() does not download, instead moves file to website root folder

php,cakephp,ftp
I have a website developed under CakePHP. I'm trying to change the download system from Apache to FTP. I currently am doing the FTP by hand with PHP (not using any plugins or libraries). My code succesfully connects to the FTP server etc. The problem I'm having is that when...

intl PHP extension is not working for xampp server

php,cakephp
I am trying to install CakePHP 3-0-0 version and I have downloaded the source code from here. But it is showing the error of enable intl extension. As I have already changed ;extension=php_intl.dll to extension=php_intl.dll (remove the semicolon) in php.ini file and restart xampp 2-3 times, but still it is...

Cakephp simple OR condition

cakephp,cakephp-2.3
I want to perform a simple OR statement with a Cakephp find.. can't manage to get this or condition to work quite right, consistently this tends to execute the first part of the statement and not the OR.. anyone offer any pointers? $hols = $this->find('all', array( 'conditions' => array( 'Holiday.leave_type...

Cakephp 3.x Ajax deleting data gives this Error: Unknown method “isNew”

php,ajax,cakephp,cakephp-3.0
I try to delete a record with Ajax in CakePhp 3.0.6. Here is the jquery in my View (start.ctp) <script> $('.delavailable').click(function(){ var dataString = 'ID=' + $(this).attr('id'); $.ajax({ type: 'POST', url: '/ID/admins/delavailable.json', data: dataString, beforeSend: function(xhr) { xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); } }); }); Controller (AdminsController.php) public function delavailable() { $this->loadModel('TeamFree'); if($this->request->is('ajax'))...

PHP Multiple cURL requests to REST API stalls

php,rest,cakephp,curl
Currently I have a system that sends multiple requests to a REST API. It is structured something like this: foreach ($data as $d) { $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_HTTPHEADER, (array of data here)); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec( $ch ); $retry...

Access normal php file in cake php

php,.htaccess,cakephp
if i use normal php file so display error of controller missing and my normal php file is in order/api.php in base directory so please help me how can i access this path without error my htaccess code is <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1...

Validation Combobox CakePHP

php,mysql,validation,cakephp,cakephp-2.3
Hi I'm new using CakePHP 2.6.3, I have a problem with the validation of some models. I populate two different combo box with the same information, how can I validate that when I insert they don't have the same value. Thanks in advance. EDIT: class Requisitoscurso extends AppModel { public...

describe( ) in CakePHP 3.x

cakephp,cakephp-3.0
i'm trying to find the equivalent of describe() in CakePHP 3.x Here is the version 2.x documentation DataSource::describe() Any ideas?...

CakePHP 2.x Sending user messages to element('menu')

cakephp,menu,message
I would like to know the best way to send data to an element which appear everytime the page is loaded. For instance, once a user is logged in, I have to recover some informations about him. The User.id, User.name, etc. are recovered using the SessionHelper as follow : <?php...

How to create a join table record

php,cakephp,cakephp-3.0
So I'm trying to add a record to my join table, but it doesn't seem to work, no errors are given either. So here's my data array (which saves correctly without a problem) array(3) { ["id"]=> string(2) "32" ["title"]=> string(5) "Hello" ["participant"]=> array(1) { [0]=> array(1) { ["id"]=> int(1) }...

Moving a CakePHP 1.3.2 Application to a New Server

php,cakephp,cakephp-1.3
I have a very old CakePHP 1.3.2 application that used to work on a server under a given domain. I have the original files and now I'm trying to set it up and get it running on a new server under a different domain. At first I had to fix...

cant saveall on 1 model with cakephp

cakephp,cakephp-model
I cant saveall records to the 1 model. I have a numerical array which i added a model name. For saving multiple records of single model, $data needs to be a numerically indexed array of records :' I did this and also tried many varieties with Tutor as the key....

Format displayValue option of find function with CakePHP 3.x

cakephp,cakephp-3.0
With CakePHP 3, displayValue option allows you to change the field which will be displayed in your view, for example a name instead of an id. find('list', [ 'keyField' => 'no_user', 'order' => ['Users.name' => 'asc'], 'valueField' => ['name'] ]); In my example above, I want to display name and...

Checking for 'isUniqueUsername' in cakephp doesn't seem to work?

php,cakephp,registration
I have a register form where when a user registers it asks for their Username, Password and email. For the username, I have a few rules such as: Must be 5-12 characters Must be unique Must use only alpha, numbers, and dashes With that being said, I can't seem to...

CakePHP 3.0 IIS web.config

php,cakephp,iis,iis-7.5,cakephp-3.0
All of my urls for images and css or being rendered with app prepended /app/favicon.ico /app/img/logo.png /app/css/styles.css The content of the pages is rendering fine, just not the images and css. My web.config looks like this, but doesn't seem to be helping these urls. Thus they are all resulting in...

where I can find change log file in cakephp framework files?

php,cakephp,changelog
I want to see all Bug fix of cakephp framework. for other php framework Bug fixes are located in change log file in framework, but in cakephp i can't find any changelog file. where i cat find this file?

Difference of cakephp2 and Cakephp3 [closed]

cakephp
I think entirely different in folder structure Cakephp 2.0 and Cakephp 3.0 Could please explain about some functionality like how to set primary_key in Table and how to use "use_table" syntax in cakephp 3.0

CakePHP2 how to check referral URL only when POST

cakephp
I'm using CakePHP2 (2.6.3) and I need to check referral URL when POST action for avoiding some security issues. In CakePHP 1.x days, there used to be configuration Security.level which can be set to check if referral URL is sort of the same domain, but it seems have been removed....

on editing file upload field is blank

image,cakephp
I am using cakephp 2x. I have a problem in my edit page image upload field. Everytime when i try to edit my profile page , it shows image upload field blank.Other fields information are remains same as fill in the add form of profile but the image field is...

validating mutiple drop downs list with the same name field in CakePHP 2.x

cakephp,drop-down-menu
I'm new to cakephp 2x. I have multiple drop down in my form. All the drop downs are using same list data, from one table called -> Students. Now what I want is ,when the user select first student in first drop down ,then that student should be minus from...

CakePHP 3.x: hide shell class

shell,cakephp,cakephp-3.0
I have a src/Shell/AppShell.php class that is extended to all other shell classes and which contains common methods used by all other classes. In other words, this class doesn't contain any method callable directly. If I launch the console: bin/cake the class is automatically detected and is shown: $ bin/cake...

CakePHP - Controller testing failed because of Security component

security,unit-testing,cakephp,cakephp-3.0
I am trying to test controller methods (add, edit, ...) that use Security component. ContactsController public function initialize() { $this->loadComponent('Security'); } public function add() { $contact = $this->Contacts->newEntity(); if ($this->request->is('post')) { $contact = $this->Contacts->patchEntity($contact, $this->request->data); if ($this->Contacts->save($contact)) { $this->Flash->success(__d('contact_manager', 'The contact has been saved.')); return $this->redirect(['action' =>...

CakePHP 2.6.0 is not loading CSS and JS files

css,.htaccess,cakephp,mod-rewrite,cakephp-2.6
I just uploaded my website to the server but is not loading the css and js files, only I can see the site just like text and after put the .htaccess files in their places I got this message in the site: Internal Server Error The server encountered an internal...

Get Google Plus Images Using Zend Framework 1 Gdata

php,cakephp,zend-framework,google-plus,gdata
I've been searching for an answer for this for quite some time now. I've looked into the other questions here but couldn't find a relevant one to my situation. Googling the question wasn't helpful as well. Basically, I am using ZF1's Gdata class to access the photos api. This was...

cakephp 3 order by query generates 14 queries with associate tables instead of 1

cakephp,cakephp-3.0
My cakephp3 app works very well and now I wish to order some of the queries by the associated table fields. The query works fine when ordered by a field in the current model. But if I choose to order by a field Models.field in an associated table I now...

Cakephp 3 and Postgre add.cpt doesnt work id_parent

postgresql,cakephp,cakephp-3.0
I'm trying to create an easy page on cakephp 3 using postgreSQL. I do not understand where is the problem: I create a table "menus". When I add a new instance (add.cpt) the parent field is empty so I cant add a parent. It's all generated from command "cake bake...

Array to string conversion [CORE\Cake\Model\Datasource\DboSource.php, line 2094]

php,cakephp
I have a review & rating page. After viewing the product customer can give review and rating. My controller/review.ctp code is like this: public function review($prod_id = NULL) { if($this->request->is('post')) { $this->Product->updateAll(array( 'Product.rating' => "'".$this->request->data['Product']['rating']."'", 'Product.review' => "'".$this->request->data['Product']['review']."'", array('conditions'=>array( 'prod_id' => $prod_id)) )); $this->Session->setFlash("Thanks for your feedback !!!"); }...

CakePHP 3.0 Auth Error Flash Element

php,cakephp,view,cakephp-3.0
I am having no luck trying to change the Flash Element on the AuthError from default to error? I was just trying to see if I can change it, but now its driving me up the wall as I can not seem to change it? This is how I have...

CakePHP 3: change order in dateWidget

cakephp,cakephp-3.0
I found on the CakePHP developer's guide the following hint on how to adjust the order of the fields when using the date form input. It says To control the order of inputs, and any elements/content between the inputs you can override the dateWidget template. However, I cannot find anywhere...

CakePHP - all pages blank except the home page

php,cakephp,cakephp-1.3
I inherited a very old CakePHP application (version 1.3.2) that I have to run on a new server (old server is long gone, I only have the code). I managed to get it going after some configuration and right now the home page loads here: http://m.gratuito24.com/ So far so good,...

Basic CakePHP: Unable to get the id (Edit Method)

cakephp,sql-update
This my database: http://gyazo.com/c6a86127d6f91aae947cf45ee535cecd Example: http://gyazo.com/c23fec3fabb7e4504c42453980fbc372 When I press the edit button , they able to retrieve the data however the page show me empty field instead of the field that have old data. Secondly, unable to undate because they keep send empty id_field back to controller. p.s. add,edit,delete method...

How to Edit User CakePHP 3

cakephp,cakephp-3.0
So I've been trying to get an edit user functionality working in my app, and I'm a little confused as to how to go about doing this with CakePHP 3. This is what I've got for my edit action in my UsersController.php: public function edit() { $this->layout = 'dashboard'; $user...

Trouble linking models together in CakePHP2

php,cakephp,cakephp-2.6
I'm using CakePHP 2.6.7. Here is my database (simplified) : ***Users*** id username ***Cars*** id CarMake CarModel NumberPlate user_id ***Addresses*** id address postalcode city country ***Addresses_Users*** user_id address_id This is what I want : One user can have multiple cars and one car is owned by only one user. One...

Cake PHP change value of hidden form item by javascript

javascript,php,cakephp
I have the below cake php form in my view: <?php $form_id = 'message_form ' + $profile_id ?> <?php echo $this->Form->create('Post', array('id' => $form_id, 'url' => array('app' => true, 'controller' => 'messages', 'action' => 'new', $profile_id))); ?> <?php echo $this->Form->input('text', array('type' => 'textarea', 'class' => 'form-control', 'label' => false, 'data-validate'...

How to change the message in buildRules [CakePHP 3]?

validation,cakephp,cakephp-3.0
The function below is for being sure the e-mail from form is unique, if it's already in use a message is showed. I want to change this message. public function buildRules(RulesChecker $rules) { $rules->add($rules->isUnique(['username'])); $rules->add($rules->isUnique(['email'])); return $rules; } I tried this way: public function buildRules(RulesChecker $rules) { $rules->add($rules->isUnique(['username'])); $rules->add($rules->isUnique(['email']), ['errorField'...

how to add search by date cakePHP

cakephp,cakephp-2.5
I have the following code that displays a list of details from my Database. It is paginated as well. I want to add a search function that someone can search the provided data using " Date From - Date To " Currenty source : $tapplicant= $this->paginate = array( 'fields' =>...

How to load a xml file in plugins webroot

cakephp,plugins,components,cakephp-3.0
I am using cakephp-3.0 In a Component of a plugin, I want to load a XML file in the plugins webroot. simplexml_load_file('RangeMessage.xml') The file can't be found. Debugging the path with debug(realpath('')); Says, that the actual directory is /path/to/app/webroot. My xml-file however is in /path/to/app/plugins/myPlugin/webroot So how can I find...

how to display a message if database table is empty in cakephp

cakephp,cakephp-2.3
i can retrieve database entries with $this->set('view_applications', $this->Application->find('all')); but i do not know how to display a message if the results of the above function is empty. here is my controller code public function index() { $this->set('results', $this->Application->find('all')); } and here is my index.ctp view code <h1>Requests for Graduation Registration</h1>...

How to Save Associated Table in CakePHP 3.0

cakephp,cakephp-3.0
Hi I just made a function to save data in multiple tables. Even Though, I followed the instruction in Instruction for Cakephp 3.0 It saves data in only one table. Please see what i missed. Thank you public function saveTest() { $goods = TableRegistry::get('Goods'); //$data = $this->request->data; $data = [...

Cakephp3 query model

cakephp,cakephp-3.0
Here is my Product Model: $this->table('products'); $this->belongsTo('OrderProducts', [ 'foreignKey' => 'order_product_id', 'propertyName' => 'order_product', 'joinType' => 'INNER' ]); $this->hasMany('RefundProducts', [ 'foreignKey' => 'product_id', 'sort' => ['RefundProducts.created' => 'DESC'], 'propertyName' => 'refund_products', 'className' => 'RefundProducts' ]); My query: $result = $this->Products->find('all', [ 'contain' => [ 'RefundProducts' => [ 'PriceUnits', 'conditions' =>...

How to show associated data in add form in cakephp 3.x

cakephp,has-and-belongs-to-many,cakephp-3.0
I have two tables CREATE TABLE `user_roles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `role_name` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=latin1 CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(20) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, `user_role_id` int(11) DEFAULT NULL,...

Get last inserted ID after inserting to associated table

cakephp,cakephp-3.0
Employees table has a field named current_address_id. I'm adding a new address to Addresses like: $updatedEntity = $this->patchEntity($employee, [ //some other fields 'user' => $userData, 'employees_phones' => $phonesData, 'employees_addresses' => $addressesData, ], [ 'associated' => ['Users', 'EmployeesPhones', 'EmployeesAddresses'] ]); $this->save($updatedEntity); I'm inserting the new address successfully but now I need...

CakePHP find WHERE NOT EQUAL

php,cakephp,frameworks
can you see the error guys ? my AND conditions is ignored! I'm getting so frustrated with those arrays.. $transaction_query = $this->Transaction->find('all', [ 'limit' => $countList, 'fields' => ['Transaction.client_id','Transaction.name','Transaction.created','Transaction.message_id','Transaction.credit'], 'conditions' => ['Transaction.id' => $client_id], 'AND' => ['Transaction.name !=' => 'Facturation'] ]); ...

Basic CakePHP: Edit Post Method become Add Post Method

cakephp,methods,sql-update,edit
Currently following the blog tutorial however my database and their variable are different. I was looking through the "Edit Post" method and follow the step they given however they turn into "Add Post" method. What is the reason that cause it ? (I have set the hidden field at view...

cakephp 3 bootstrap-ui change prev/next text

cakephp,cakephp-3.0,cakephp-bootstrap-ui
I have FriendsofCake Bootstrap-ui plugin. I see in the source that it accepts text for the pagination prev and next labels. I am not sure how to exactly set the config option though. PaginatorHelper.php if (isset($options['next'])) { if ($options['next'] === true) { $options['next'] = $this->config('labels.next'); } $options['after'] = $this->next($options['next'], ['escape'...

How to implement pagination with search in CakePHP

cakephp,pagination,cakephp-2.0
My pagination is working, even the search is also working. But the problem that I'm having is when i click on next page link in the pagination links. The search is not working for the next page of the pagination. Also I need to know how I send other parameters...

Cakephp MySql Query with WHERE

mysql,cakephp
I have work function: public function index() { $this->set('tables', $this->Table->find('all')); } But how show only column WHERE owner = logged user?...

cakephp 3 and view cells with use of Cookie

cakephp,cakephp-3.0
I can't find any info about using $this->Cookie in view cells. When i wrote code like this, error will arise: namespace App\View\Cell; use Cake\View\Cell; class CityCell extends Cell { public function display() { $this->Cookie->config('encryption', false); $cookie = $this->Cookie->read('city'); } } and the error is: Error: Call to a member function...

CakePHP 3 build complex join using query builder

cakephp,query-builder,cakephp-3.0
I need to add joins on the same tables dynamically... something like this: // foreach ... as $id $options['join']['T_Values' . $id] = [ 'type' => 'LEFT', 'table' => 't_values', 'conditions' => ['T_Values' . $id . '.t_id = T.id'] ]; $options['join']['Values' . $id] = [ 'type' => 'LEFT', 'table' => 'values',...

Modify $this->request->data in model CakePHP?

php,cakephp,cakephp-2.6
How can I modify $this->request->data from model in CakePHP. I tried it with code in model User : public function beforeValidate($options = array()) { unset($this->request->data['User']['birthday']); } But it return errors : Notice (8): Indirect modification of overloaded property User::$request has no effect Warning (2): Attempt to modify property of non-object...

Is there an alternative to neighbors in Cakephp

cakephp,cakephp-3.0
I am coverting my app over to cakephp 3.0 and I am having trouble finding an alternative to using neighbors in the find method. I need to find the next record in the associated table and neighbors was a great way to do it. //Open courses $options = [ 'conditions'...

Using slug in CakePHP v3

cakephp,cakephp-3.0
I plan to upgrade my CakePHP v2 to v3 website. So I start to learn by looking at the Blog tutorial & it work fine. Next, I start to customize base on my CakePHP v2 site. The first thing I would like to do is using slug in URL instead...

how to add normal script code to view.ctp in CakePHP 2.2.4

jquery,cakephp
enter code hereI want to insert this code to my .ctp file <script> $(document).ready(function(){ $('open').click(function(){ $('#pop_background').fadeIn(); $('#pop_box').fadeIn(); return false; }); }); </script> it should work with this <a href="#" id="open">Open popup box</a> I have created the relevant CSS files and div for 'pop_background' and 'pop_box'. Now it should be appeared...

Cakephp link to view a page in sub folder

cakephp,cakephp-2.0,cakephp-2.3
I wish to display a normal page in a sub-dir of the Pages folder, however cakephp keeps removing the "/" forwardslash and replacing it with "%2F".Ive tried to add the escape=>false flag but it doesnt seem to work. What am i doing wrong? my code; echo $this->Html->link('Tiny MCE plugin',array( 'controller'=>'pages',...

How to view a cakephp plugin page

php,cakephp,plugins,cakephp-2.0
I'm making a plugin called "test", as an example. Is it possible to create "pages" for this plugin and display them? In my plugin folder I've got a folder called View, and inside that another folder called Pages, which contains a file: "demo5.ctp" +test view Pages demo5.ctp +webroot I'm assuming...