FAQ Database Discussion Community


How to display validation message for select box in CakePHP 3?

validation,cakephp-3.0,formhelper
Below you can see my model and view. Can't figure out how to display validation error message. How do I do that? All other validation messages for input fields are displayed as expected. class ProjectsTable extends Table { public function validationDefault(Validator $validator) { $validator->requirePresence('language'); return $validator; } } <?php echo...

How to translate words from $this->Time->timeAgoInWords?

cakephp-3.0
Here some translations at default.po /src/Locale/pt_BR/default.po msgid "{0} minute" msgid_plural "{0} minutes" msgstr[0] "minuto" msgstr[1] "{0} minutos" msgid "January" msgstr "Janeiro" ... The months are being translated at input type date but minute at $this->Time->timeAgoInWords is not. They are from a different domain?...

Login custom route being rejected by Auth

php,cakephp-3.0
Router::scope('/:club_slug', function ($routes) { $routes->connect('/login', ['controller' => 'Users', 'action' => 'login']); }); So when I'm trying access http://example.com/club-name/login, I'm being redirected to http://example.com/users/login with the flash message You have to login to access this area. Auth loginAction is [controller => 'Users', 'action' => 'login'], since the custom route that I...

cakePHP get users details of logged in user

cakephp-3.0
I am using the cakeManager plugin with cakePHP 3 to manage users. I have two user roles businesses and employees and I have tables for each with additional information. When a user logs in I am trying to get the additional information with the users details but I cannot seem...

Cakephp 3 how to set maximum number of selected option in multiple select?

php,forms,validation,cakephp-3.0
I would like to set a rule to limit the number of option visitors can select in a field multiple select. I tried this, but it doesn't work $validator ->add('colors._ids', [ 'multiple'=>[ 'rule'=>['multiple', ['max'=>3]], 'message'=>'Please select only one color' ] ]) ->requirePresence('colors._ids', 'create'); // ->allowEmpty('colors._ids'); return $validator; In the view...

Cakephp 3.0 sesson time expire re-direct to home page

cakephp-3.0
How to re-direct home page when the session id time is expire, not using auth id i have set the another value is session in Cakephp 3.0

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...

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...

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.0: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax

mysql,cakephp-3.0
I faced saving data to database using Form in CakePHP 3.0. //add.ctp <div> <?= $this->Form->create($deposit) ?> <fieldset> <legend><?= __('Add') ?></legend> <?php echo $this->Form->input('date'); echo $this->Form->input('profile_id', ['options' => $profiles]); echo $this->Form->input('amnt'); echo $this->Form->input('desc'); echo $this->Form->input('user_id', ['options' => $users]); ?> </fieldset> <?= $this->Form->button(__('Submit'))...

CakePHP Entity contain without foreign key

php,cakephp,foreign-keys,cakephp-3.0
I have an entity Villa, and I want this Entity to contain other Villas which have the same 'complex' (Varchar(255)). class VillasTable extends Table { /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ public function initialize(array $config) { $this->table('villas'); $this->displayField('name');...

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?

How should I use requestAction in the view with CakePHP 3.x

cakephp-3.0
My code: // View/Activities/index.ctp ... <div> <?php echo $this->requestAction('/Activities/ajax_list/'.$categoryId,['return']);?> </div> ... //View/Activitest/ajax_list.ctp .... <?php echo $this -> Html -> image("/img/add1.jpg"); ?> ... <?php echo $this->Html->link('add_project', array('controller'=>'projects', 'action'=>'add', $categoryId)); ?> .... I want to include the view 'ajax_list' into the 'index',and it has been displayed but the url of image and...

CakePHP 3 foreign key with matching table/model name

php,mysql,cakephp,cakephp-3.0
CakePHP 3: I'm trying to update a foreign key in my table called poi. The foreign table is named poi_types. Unfortunately the DB-Designer named the foreign key poi_type instead of poi_type_id. Cake responds with Passed variable is not an array or object, using empty array instead I'm not able to...

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',...

How secured if Cross Site Request Forgery(CSRF) to be enabled in Cakephp?

cakephp,cakephp-3.0
First of all, the confusion comes from CSRF and Check Your Security in the development section of cake document. From CSRF: By enabling the CSRF Component you get protection against attacks. CSRF or Cross Site Request Forgery is a common vulnerability in web applications. It allows an attacker to capture...

Customize login cakephp3

cakephp-3.0
I have a form like this: email [input] password [input] Login-Button I want to eliminate the "email" and "password" text and put them inside the inputs like placeholder and also change the "login" text to "LOGIN". This is my login ctp. <fieldset style="background:#F44336"> <?= $this->Form->create() ?> <?= $this->Form->input('email') ?> <?=...

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...

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...

How to access caller model from behavior in cakephp 3?

php,cakephp,cakephp-3.0
I need caller model in my behavior to find and save data. How can I do something like this. class MyBehavior extends Behavior { public function func() { $entities = $this->find()->all(); } ...

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...

Testing beforeFilter() function

php,unit-testing,cakephp-3.0
I am doing unit testing for a PHP application using CakePHP framework. The function that I am testing is beforeFilter() which basically loads the models. public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->loadModel('Model1'); $this->loadModel('Model2'); $this->loadModel('Model3'); $this->loadModel('Model3'); } How should I test this function ? What assertions I need to make in...

How can I add FOR UPDATE to a cakephp3 query?

select,transactions,sql-update,cakephp-3.0,isolation-level
Is there a way to add FOR UPDATE to a find (SELECT) query in cakephp3? I found this hack: http://bakery.cakephp.org/2012/04/14/SELECT-FOR-UPDATE-hack-kind-of-ugly-but-it-works-PostgreSQL-and-MySql.html but it does not work since the limit value must contain only of a number. Another discussion on a similar topic can be found under https://github.com/cakephp/cakephp/issues/3136#event-213462937....

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 - 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' =>...

configure DocumentRoot for cakephp 3 in openshift

openshift,cakephp-3.0
good I am new user in OpenShift, today I read the documentation, but it was not clear yet, how could I configure DocumentRoot. in my case I use cakephp 3 and for take my application into production I need to configure the DocumentRoot, this should be webroot for production, I...

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...

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 i create CRUD with relationships in cakephp3

cakephp,relationship,crud,cakephp-3.0
How i do a crud with a relationship between a user and services order? With the code, i can't add users in a team for service order. When cakebake, the controller TeamHasUsersController is created, but the form add don't have any field. The crud has generated with cake bake. ...

Cakephp 3.0 download file

cakephp-3.0
I asked a question before about file uploading. I managed to get it working and my next step is getting the file to be downloaded by a customer the files may be different formats from videos to PDFs. I did read about media views, but they where cakephp 2.0. I...

CakePHP 3.x - fixtures import does not load data

php,unit-testing,cakephp,cakephp-3.0,fixture
I am trying to import fixtures in my CakePHP 3.x plugin. When I launch the tests, I always get the error : UserManager\Test\TestCase\Controller\UsersControllerTest::testProfile exception 'Cake\Datasource\Exception\RecordNotFoundException' with message 'Record not found in table "users" Here is UsersFixture.php : namespace UserManager\Test\Fixture; use Cake\TestSuite\Fixture\TestFixture; class UsersFixture extends TestFixture { public $import = ['table'...

How to set Authorization wise view in the Form in CakePHP-3.0

cakephp-3.0
I want to set an authorization in the registration of a form using CakePHP 3.0. Before asking here, i tried below things but no luck in my favor. Suppose i have role field in the usersTable like 'superuser', 'admin', 'user'. I want to provide permission superuser to make all the...

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...

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...

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');...

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,...

cakephp 3.0 same controller name for admin and users

cakephp-3.0
I am using cakephp 3.0 and want to write some admin actions and some users actions in users controller. admin actions should be accessible from admin routing and user actions should be accessible without admin routing I know in cakephp 3.0 for admin, users controller should be in src/Controller/Admin/UsersController.php and...

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...

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...

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...

Cakephp3 transaction find query

mysql,select,transactions,cakephp-3.0
When making a transaction in cakephp3 and adding a get() query inside all works fine. But why is a find() query not performed inside the transaction? I have the following controller in cakephp3: <?php namespace App\Controller; use Cake\Core\Configure; use Cake\Network\Exception\NotFoundException; use Cake\View\Exception\MissingTemplateException; use Cake\Network\Session; use Cake\Event\Event; use Cake\Network\Http\Client; use Cake\ORM\TableRegistry;...

Change the Default Fav icon in cakephp 3.0

cakephp-3.0
How to change the title logo in cakephp 3.0 ? Added another image instead of default cakephp logo image Anyone explain with example Thank you...

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 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 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 handle Imagine exception in CakePHP 3

php,cakephp-3.0,php-imagine
I suppose I don't manage correctly the exception using Imagine libray. My code is: use .... use Imagine\Exception; .... try { $imagine = new Imagine(); $image = $imagine->open($img_path . DS . "tmpfile." . $extension) ->resize(new Box($cwidth, $cheight)) ->crop(new Point($offsetx, $offsety), new Box(500, 500)); ... } catch (Imagine\Exception\Exception $e) { die("catch...

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'...

Cakephp3 redirect in beforeFilter is not working

redirect,controller,cakephp-3.0,before-filter
When I add the $this->redirect statement inside a beforeFilter of a controller and return afterwards, the redirection is being ignored. When I move the redirect statement inside an action of the controller, it works fine. Does someone has an idea what I am doing wrong? public function beforeFilter(Event $event) {...

Preventing malicious users update data at add action

cakephp-3.0
Here is a basic add action: public function add() { $article = $this->Articles->newEntity(); if ($this->request->is('post')) { $article = $this->Articles->patchEntity($article, $this->request->data); if ($this->Articles->save($article)) { $this->Flash->success('Success.'); return $this->redirect(['action' => 'index']); } else { $this->Flash->error('Fail.'); } } $this->set(compact('article')); } If a malicious user injects at form a field with name id and set...

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...

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) }...

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' =>...

Remove INTL extension support in cakephp

php,cakephp-3.0
I am using CakePHP 3.0 framework. Is there any way to use CakePHP framework without the intl extension support?

core difference between set and serialized in cakephp 3.0?

serialization,cakephp-3.0
$player = $this->Players->get($id, [ 'contain' => [] ]); $this->set('player', $player); $this->set('_serialize', ['player']); if i will remove $this->set('_serialize', ['player']) than i am not getting any difference at my view. <h6 class="subheader"><?= __('First Name') ?></h6> <p><?= h($player->first_name) ?></p> <h6 class="subheader"><?= __('Last Name') ?></h6> <p><?= h($player->last_name) ?></p> <h6 class="subheader"><?= __('Email')...

Update a row(entity) in a table only if a change detected(automatically)

sql-update,entity,detect,cakephp-3.0,changes
Sorry for my bad english :( I'm using the CAKEPHP 3 framework and i want to update a row(entity) in a table only if a change detected(automatically). Eg.: $id = 1; // debug($this->request->data) $this->request->data = ['id' => 1, 'name' => "My Name", 'content' => "My Content"]; // Inside the ArticlesController...

Removing the debugging bar from cakephp

php,cakephp-3.0
I am creating a new project in cakephp, I completly customized the view page, but since I am new to cakephp framework unable to understand how to remove the debugging bar given bottom of the page. I checked and tried every possible things, but not getting. Any suggestion will be...

How to choose the fields from a associated model at find

cakephp-3.0
Before I had this: //ArticlesController::index $articles = $this->Articles->find('all', [ 'contain' => ['Comments'] ]); So I set the fields key: //ArticlesController::index $articles = $this->Articles->find('all', [ 'fields' => ['title', 'text], 'contain' => ['Comments'] ]); Since I set the fields key the result of the find is not bringing the comments anymore....

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...

Translating query involving join table from CakePHP 1.3 to 3

has-and-belongs-to-many,cakephp-3.0
I'm migrating an application from Cake 1.3 to 3.0. My database has teams and people (with teams_people to connect them via belongsToMany relations) and divisions (teams belongTo divisions). The teams_people table has additional information, like whether the person's role on the team (captain, player), jersey number, position, that sort of...

join and orwhere ends to AND

orm,cakephp-3.0
I have the follwing code: $_duplicates = $this->find() ->innerJoin( ['c' => 'contacts'], //alias [ 'Contacts.contactname != ' => '', 'Contacts.id < c.id', 'c.id > ' => 0 ] ) ->select(['Contacts.id', 'Contacts.contactname', 'Contacts.legalname', 'c.id', 'c.contactname', 'c.legalname']) ->orWhere([ 'LEVENSHTEIN(Contacts.contactname, c.contactname) <= ' => $distance, 'LEVENSHTEIN(Contacts.contactname, c.legalname) <= ' => $distance, 'LEVENSHTEIN(Contacts.legalname, c.contactname)...

CakePHP 3.x - Testing actions that require Authentication

php,unit-testing,cakephp,cakephp-3.0
I am trying to run unit tests in CakePHP 3.0, but all actions require authentication. I tried to set session data with $this->session() like in the official documentation here, but phpunit always returns error when I test responsecode with $this->assertResponseOk() : Status code is not between 200 and 204 Failed...

Redirect to a homepage cakephp 3

php,redirect,routes,cakephp-3.0
I've followed the articles tutorial from cakephp 3 website and created the website http://i.imgur.com/JMh1Pwv.png Now there is add article, delete article and edit article actions. When I delete an article it redirect me to http://localhost:8888/test/articles/delete/14 Here is the delete code. public function delete($id) { $this->request->allowMethod(['post', 'delete']); $article = $this->Articles->get($id); if...

Cakephp 3 - var not transmitted to view when exception thrown

error-handling,cakephp-3.0
In my AppController, I define a variable that must be used in every views (including error400.ctp, error500.ctp) of my app: // /src/Controller/AppController.php public function beforeFilter(Event $event) { parent::beforeFilter($event); $foo = 'bar'; $this->set(compact('foo')); } It works well, except when an exception is thrown (like NotFoundException): I get the following error: Undefined...

Why Authorize is to set to Controller in AuthComponent?

cakephp-3.0
Why authorize is to set to Controller while Authentication is done in AppController? Like: I got it when Blog example is doing but did not get details explanation on it $this->loadComponent('Auth', [ 'authorize' => ['Controller'] ]); I read the Authorize Section but could not understand it. So Could someone please...

mySQL table structure with adding new users table [closed]

php,mysql,cakephp-3.0
I have a small app in php using the cakePHP framework connected to mySql database. I have two types of users (business and employees) with relationships to other tables also. I am now adding a login facility which means I will be adding a users table to hold the password...

How to we use the SoapClient in Cakephp…?

php,soap,soap-client,cakephp-3.0
I have enabled SOAP in my local server. My code is: ini_set('soap.wsdl_cache_enabled', '0'); ini_set('soap.wsdl_cache_ttl', '0'); $client = new SoapClient('web_url'); $session = $client->login('username', 'pwd'); $result = $client->call($session, 'function_name', '<id>'); print_r($result); Here it's executed successfully when I run the code on separate php file. But I got this error: Error: Class 'App\Controller\SoapClient'...

List all tables in cakePHP 3.x

php,cakephp,database-schema,cakephp-3.0
I have been trying to work this one out. In cakePHP 2 I could use: $tables = ConnectionManager::getDataSource('default')->listSources(); But in CakePHP 3.x I can't work out what to use? I have looked at the link cakephp get schema for list of tables Unfortunately it doesnt help with cakePHP 3.0?...

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'...

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...

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'))...

how to cakephp2 project transplanted to cakephp3?

passwords,cakephp-3.0,transplant
I want to cakephp2 project transplanted to cakephp3 problem. I must retain the user's information. How to make them have the same way to generate password? Here's how I generate passwords by cakephp2. App::uses('AuthComponent', 'Controller/Component'); .... public function beforeSave($options = array()) { $this->data['User']['password'] = AuthComponent::password( $this->data['User']['password'] ); return true; }...

CakePHP 3 Join Multiple Tables

php,mysql,cakephp,join,cakephp-3.0
i am using CakePHP 3x. What i want is to be able to call $this->Categories->find() and then join Topics on Topics.cat_id = Categories.id and then join Posts on Posts.topic_id = Topics.id. I don't get any errors but the only data i'm getting back is the Categories data, i have tried...

Users Authentication fail

cakephp,cakephp-3.0
So this is my login method: public function login() { if ($this->request->is('post')) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); return $this->redirect($this->Auth->redirectUrl()); } else { $this->Flash->error(__('Invalid username or password, try again')); } } } And this is how I has my password inside my User entity: <?php namespace App\Model\Entity; use...

Blog tutorial docs isAuthorized missing return false?

php,cakephp-3.0
// src/Controller/ArticlesController.php public function isAuthorized($user) { // All registered users can add articles if ($this->request->action === 'add') { return true; } // The owner of an article can edit and delete it if (in_array($this->request->action, ['edit', 'delete'])) { $articleId = (int)$this->request->params['pass'][0]; if ($this->Articles->isOwnedBy($articleId, $user['id'])) { return true; } } return parent::isAuthorized($user);...

How to convert special characters of an url in cakephp3?

url,cakephp-3.0
I have an upload folder in webroot that contains my pictures. And I read picture path from database. picture->path = 'uploads\pictures\pic1.png' When I try to show pictures with line below echo $this->Html->image('/'.$picture->path); browser could not show pictures. This is the result html that generated with cakephp <img src="/projects/bookmarker/uploads%5Cpictures%5Cpic1.png" alt=""> I...

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...

Why a virtual property getter should not be called in cakePHP 3?

cakephp,models,cakephp-3.0
in a ctp, I display several virtual properties from 2 entities, computed by getters. It's ok for one of the both entities but for the other, none of the properties getters are never called. Here is an excerpt of the ctp: <table> .... <td><?= $agTheme->agthemelanguages_wc_string ?></td> <td><?= $agPoi->paragraph_length_string ?></td> <td><?=...

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...

CackePHP 3 formatResults() ORDER by field created dynamically

cakephp-3.0
I wish to sort on a field that I dynamically creates in formatResults() $users = $this->Users ->find('all') ->formatResults(function ($users) use ($lat, $lng) { return $users->map(function ($user) use ($lat, $lng) { $user->distance = getDist($lat, $lng); return $user; }); }) ->order([ 'distance' => 'ASC' ]); [...] $this->set('users', $this->paginate($users)); The field $user->distance is...

Change Password not working Cakephp 3.0.3

cakephp,authentication,passwords,cakephp-3.0
i am using cakephp 3.0.3, i am writing action to change user password, for that i want to compare current password (entered by user) with existing one in database. but it give me different hash every time, Here is my setter for password in User Entity, protected function _setPassword($password) {...

Deny all actions by default

php,cakephp,cakephp-3.0
I'm trying to deny all pages to unauthenticated users as it explains in documentation (http://book.cakephp.org/3.0/en/controllers/components/authentication.html#making-actions-require-authorization) so I put this in my AppController.php: public function initialize() { parent::initialize(); $this->loadComponent('Auth', [ 'loginAction' => [ 'controller' => 'AuthController', 'action' => 'login' ], 'authenticate' => [ 'OAuth2Client.OAuth2' ] ]); } public function beforeFilter(Event $event)...

How do you get all uploaded files in CakePHP?

php,cakephp,recursion,file-upload,cakephp-3.0
How do you get all uploaded files in CakePHP 3.x? Here is my controller to get you on track. <?php class MyController extends AppController { public function upload() { // how to loop through all files? } } Sample form <form action="/my/upload" method="post" enctype="multipart/form-data"> <input type="text"> <!-- any number of...

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 = [...

how can I return the validation errors for a REST call?

validation,cakephp-3.0
I am making a REST api for my application. It almost works, but I want it to return the validation errors when they occurs. With CakePHP 2.x I see there was an invalidFields method, but it's not there anymore with Cake3. I see, instead, that there is an errors method...

Two associations for the same table resulting in a collision

php,cakephp-3.0
I have videos and artists, video belongsTo artist and artist hasMany videos. I did it and is working, when I find videos and set [contain => ['Artists'] I got the result videos entity with the related artist. This first relationship is about the artist that is the "owner" of the...

Update only one field on Cakephp 3

php,cakephp-3.0
In some part of my app I need to update only the field is_active of some table with a lot of fields. What is the best approach to update only this field and avoid the validations and requiriments of all other fields?

What is the difference between trait and behavior in cakephp 3?

behavior,cakephp-3.0,trait
I find soft delete in cakephp 3 that implemented via traits. And I try to implement it via behaviors. But unlike the trait version, SoftDeleteBehavior do not work. I have this line in my model initialize method: $this->addBehavior('SoftDelete'); And this is my SoftDeleteBehavior namespace App\Model\Behavior; use Cake\ORM\Behavior; use Cake\ORM\RulesChecker; use...

cakephp error. Connection to database …not …: Access denied for user 'my_app'@'localhost' (using password: YES)

database,cakephp,default,cakephp-3.0
I am trying to start CakePHP. I made bookmarker and tested by command bin\cake server. It showed one error as connection to database could not be established: SQLSTATE[HY000] [1045] Access denied for user 'my_app'@'localhost' (using password: YES). I read the config/app.default.php file. It says there is a database my_app and...

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...

How to build rule exist in or equal to a number in cakephp 3?

validation,cakephp,cakephp-3.0
I have table comments with column parent_id. And this is content of CommentsTable.php: namespace App\Model\Table; use App\Model\Entity\Comment; use Cake\ORM\Query; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; /** * Comments Model */ class CommentsTable extends Table { /** * Initialize method * * @param array $config The configuration for the Table. *...

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...

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' =>...

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...

How to read and write Session in Cakephp 3.0

session,cakephp-3.0
I am new to cake 3.0. I have read documentation on http://book.cakephp.org/3.0/en/development/sessions.html But I am not able to write sessions. use Cake\Network\Session\DatabaseSession; $session->write('Config.language', 'eng'); $session->read('Config.language'); ...

manually convert input parameters in type instance

cakephp-3.0
I have some problem to save date value in varchar field. I'm trying to convert an input date (like 17/06/2015) to an Time instance and then store it in my database as 2015-06-17 here an exemple of the entity which i want to save (int) 1 => object(App\Model\Entity\Valeur) { 'new'...

How to self join a many to many table in cakephp 3?

model,many-to-many,cakephp-3.0,self-join
I try to self join my table user to get parent-child associations but it didn't work here is my association in the Users model: $this->belongsToMany('Parents', [ 'className' => 'Users', 'joinTable' => 'users_users', 'foreignKey' => 'id', 'targetForeignKey' => 'parent_id' ]); $this->belongsToMany('Childs', [ 'className' => 'Users', 'joinTable' => 'users_users', 'foreignKey' => 'id',...

How do I disable CakePHP's client side email validation?

email-validation,cakephp-3.0
The kind of validation that pops out even before sending the data to the server. The other fields in my form, namely 'name', 'message', had these too but I removed that by taking their respective validators in my FormTable. Did the same for the email validator but its still there....

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...

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?...

Error loading association from controller in cakephp

join,cakephp-3.0
I can't get this simple query right. I need to join my adresses table to my annonces table. I supose this should be farly strait forward but I simply can't get it to work. I firstly made my adresse table object like this class AdressesTable extends Table { public function...