Auto login in CakePHP

I am using the registration form for different users? After a new user logs in, the registered users should redirect to an after-login page. We are using Auth component for the authentication. How do I do this?

Cakephp Retrieving data for a sidebar

In CakePHP I have a layout created and named default.ctp. In that layout I have a sidebar with some blocks and there're some statistics taken from the database. My solution: I just created model called Sidebar.php and there're some functions, then I set up data in controller to display it in layout. Is this the best solution? As far I know, I will have to re-set every data in every controller, so need suggestions how to solve that.

Cakephp check permission against group not users using Auth->authorize="actions"

Can any one explain me the working of Auth->authorize = "actions" In my project i am planning tp give this. As this taught me the authorize will call the $this->Aro->check($user,"controllers/:controller/:action") This will check the against the user right?? that means the user should be there in aros table. But i don't need this to check against user but i need to check against a group How can i achive this. now when the users is not in Aro table it showing the So that The Aro's w

Cakephp Automatically calls SQL Dump every page

So after moving my cakephp app to production server, it seems that every page I am getting an SQL Dump. The funny thing is, it appears in the source after the /html tag. I figure it has something to do with the index.php file, but the only thing I have edited is the root directory. Any ideas where I should start?

CakePHP Containable error

I am trying do a find statement to get the content accordingly users(id, name, city_id) visitors(id, user_id, visitor_id) // visitor_id also refers to users table cities(id, name) PHP $visitor_data = $this->User->Visitor->find('all', array( 'conditions' => array('user_id' => 1), 'limit' => 10, 'order' => array('timestamp DESC'), 'contain' => array('VisitorDetails' => array(

CakePHP: How to use the same controller function to render 2 pages

I wish to have a page called "index" with a corresponding url "domain/controller/index" and another page called "admin_index" with a corresponding url "domain/admin/controller/index". The trick is that i want both pages to use the same view to render and the same function for the logic while on of the page's parameters are a flag indicating to the view from which url the view is rendered. I need it because currently in my "index" page I have table with data. The page also has a smart filter f

Cakephp Defining a custom table for AuthComponent

I've created a simple CMS to manage several small websites built on CakePHP. After successfully migrating the plugin from 1.3 to 2.0 I'm running into a problem with the AuthComponent after updating Cake to the latest version 2.1.2. The classnames of the plugin are all prefixed by the plugin's name to avoid duplicate classnames, as the application shares most of its tables with the plugin. So there are cases when I have a UsersController for the main application and a PluginNameUsersController f

Cakephp: Saving data already saved in one table to another table in cakephp

Hie guys, im seeking your help. An applicant applies for a place and the details are saved in the applicants table and is given a default status of waiting. The administrator accepts applicants form waiting to either accepted or denied. When a student is accepted his details should automatically be saved to the students table. Applicants table and students have 26 fields in common and the national id is common and unique in both tables but it is not a primary key in either table. a) Is it possi

CAKEPHP paginator custom link

I want an custom link for my paginator. I use the folowing code $this->Paginator->options(array( 'url'=>array( "/custom",24,"custom1" ), 'escape'=>false ) ); This results in a link with the original controller in front of the link like this: /controller/action/%2Fcustom/24/custom1 I want the linkt to be /custom/24/custom1. So without the escaped(/) and as a root. How can I accomplish this?

Foreach logic issue with CakePHP

I have I problem that I hope someone can help me with. I thought this code was right, but it will not work. Below is my code, it is a function for my CakePHP 2.2.2 site, the main aim of the code is to produce a menu system from database results. The problem is with my foreach loop, it will not loop. All $Key does is return the value of 2 (three records within the table at this time). So When I display / echo / debug $Menu, the only result I get is the last result stored within the database. I

Paginate, filter and sort advanced search with calculated fields by function CakePHP

I'm looking for a better solution to solve this kind of problem. I need to paginate an advanced search for apartments with many search options: keyword, category, date from, date to, price range (price min, price max), and other fields ... In case you select the two dates I calculate the rental price of each apartment. To calculate the price I can not use a virtualField or one or more subqueries but I have to use a function of the model Apartment because it performs many calculations... So I de

cakephp attach word document on email

I'm working with CakePHP and i need to send email with attachment here is my code function sendAsEmail($data) { App::import('Component', 'Email'); $user = $this->Sender->find('first', array( 'conditions' => array('Sender.id' => $data['Message']['sender_id']), )); $Email = new EmailComponent(); if ($this->useDbConfig == 'test') { $Email->delivery = 'debug'; } $Email->sendAs = 'html'; $Email->from = 'info@admin.ca'; $Ema

Configuring CakePHP with XAMPP

I have been using CakePHP at work and now I am trying to set it up at home. I have a projects folder inside of htdocs and within that folder I have my cakeProject .../htdocs/Projects/CakeProject/app.... When I point the url to localhost/Projects/cakeProject/ I get this error. Missing Controller Error: ProjectsController could not be found.... And it goes on explaining how to make a controller. Clearly, this is not the real issue. Can anyone see right away what am I overlooking?? Here is the

Cakephp date automagic

I have the follow code: echo $this->Form->input('date', array( 'label' => __('Date') ) ); which generate one select for year, one for month and one for day. I want one input text instead of select which I can put all date. So, I have done: echo $this->Form->input('date', array( 'label' => __('Date'), 'type' => 'text' ) ); Form works but validation does not works, I can't get the correct data (Cake's "automagic") at Controller, but can't

CakePHP 2.2 AclExtras aco_sync in browser (sh permission denied)

I'm working on a remote server and I can't use the console because ssh is not enabled. So I need to run aco_sync directly from the browser (or any other way that doesn't involve the shell). I managed to sync acos on my local dev server with the following code in controller/action: $command = ROOT . DS . APP_DIR . DS . 'Console' . DS . 'cake'; $params = ' -app ' . ROOT . DS . APP_DIR; $params .= ' AclExtras.AclExtras'; $params .= ' aco_sync'; $result = shell_exec($command . $params); But on t

CakePHP session refreshes at each request

I'm working on my first app w/ CakePHP 2.3 and I'm having an issue where I can login (no auth errors), but my session isn't sticking around so I'm sent back to the login page when the Auth->redirect() is called. I'm sure I'm just missing a setting or have something configured slightly wrong, but I haven't been able to find it. # core.php # session record is written the the database, but the same record's id changes w/ every request Configure::write('Session', array( 'defaults' => 'datab

Containable Behaviour in Cakephp

Since a long time as per my knowledge I was using recursive to control my model relationship. If I make any relation between my models it would surely be autoconnected with paginate. To control that I need to use recursive. By default its value is 1 and to contro; that I have to use it as -1 or 0. Yes I read about Containable behaviour that how it automatically control fetching result from other Models Though relationships are made. I went through same as writing public $actsAs = array('Conta

CakePHP validation rule for uploaded image

In the user form I have a field for a picture: <?php echo $this->Form->file('Document.submittedfile', array('label' => __('Billede'))); ?> I had a validation made in controller, but it was not the best solution, so I have moved it to the Model, and since then it stop working. Here is the validation snippet from the model: 'submittedfile'=>array( 'rule' => 'savePicture', 'message' => 'The image has to been in jpg, png, gif or pdf format and should

CakePHP 3 : Hybriauth config does not exist on the given path

I am working on CakePHP 3 project where I have to add social login. For that I'm using HybridAuth following the tutorial from Here Now When I access http://website.com/users/social/Facebook I get error as Hybriauth config does not exist on the given path. My UsersController is <?php namespace App\Controller; use App\Controller\AppController; use Cake\Event\Event; /** * Users Controller * * @property \App\Model\Table\UsersTable $Users */ class UsersController extends AppController

Cakephp Fatal error: Call to a member function user() on boolean

I have to use loggedIn user data in view therefore creating a variable AUTH_USER in AppController in beforeRender function. 82 public function beforeRender(Event $event) 83 { 84 if ($this->Auth->user('id')) { 85 $this->set('AUTH_USER', $this->Auth->user()); 86 } 87 ... 88 ... 89 } Whenever there is an error, instead of displaying actual error it shows following error without style formatting Fatal error: Uncaught Error:

cakephp 2.4.6 and array output

When I am try pick a manufacturer name and upload the manufacturer logo image I want the image name to the manufacturer name. But the file name is always Array. Can someone check the below code and tell me what is wrong? View.ctp <fieldset> <label>Manufacturer</label> <?php echo $this->Form->input('manufacturer_id', array('options' => $manufacturers)); ?>

Two users associated to one transaction in CakePHP 3.x

In my app there is a Transaction table with: seller_id, buyer_id and asset_id. seller_id and buyer_id are id's supposed to point to Users table. To stick to the convention and keep automatic associations both should be called "user_id" (which is of course impossible) What is the correct way to create such associations in CakePHP 3.x? My guess is that I should create special association tables: Sellers (id, user_id) Buyers (id, user_id) and then associations would be trough those tables: Tran

Cakephp 3 Associative Limit Per Row

I am trying to get products under the Categories. Here Categories hasMany products. I am trying to fetch 3 products under the category. I have tried below code in controller public function test() { $this->viewBuilder()->layout(false); $Menus = $this->loadModel( 'Categories' ); $menu_top = $Menus ->find() ->contain(['Subcats','Products'=>function($q{return $q->limit(3);}]) $this->set('menu_top',$me

CakePHP read blob of session-data in DatabaseSession

I am using CakePHP DatabaseSessions with the following structure: When I query the data blob, I get back a stream. So usually you want to read the data with the function stream_get_contents which returns me a string of the stream. The content looks like this: user|O:21:"App\Model\Entity\User":11:{s:14:" * _accessible"; What does that mean now? How can i get the data as a object? Unserialization didn't work so far.

Cakephp change defaultLocale on runtime

Have a multilanguage app and i want the admin to be able to specify the "default website built language". For this ive created a table with language entries that the admin can choose from. Users can then choose the language they want the app in, which ive done with I18n::setLocale(...) in AppController. The problem is that if the main language the admin sets the site to, does not match config/app.php App.defaultLocale, the app will try to save content in the translation table instead of the main

Save multiple record loops cakephp2

I want to save multiple record with this loops but only save the last item. foreach($pregunta['img'] as $key2 => $ima) { if(!empty($ima['name'])) { $file['name'] = $ima['name']; $file['svy_question_id'] = $newquestion['SvyQuestion']['id']; $file['svy_survey_id'] = $newquestion['SvySurvey']['id']; $file['dir'] = WWW_ROOT . DS . 'img\encuestas\img' . DS; $file['video'] = 0; if($this->SvyFiles->save($file)) { debug($file); $filename = basename(

cakephp new field not saving

How to you extend a cakePHP project so it can use a new field in the database? I just given a CakePHP Project that I am trying to extend the model to include a new field. I The original Developer is no longer available, and I haven't worked with CakePHP previously. The problem is that all of the other fields are being saved correctly, but the new field is being saved as an empty string. The database has been extended to include the new field: class_time varchar(30) I extended the origina

autoComplete CakePHP 2.0

Since CakePHP 1.3, the Ajax helper has been deprecated, one cannot user $ajax->Autocomplete.. I use Cake 2.0, and wish to implement dynamic autocomplete( dynamic table, dynamic field) it seems impossible with current tutorials available. What is closest alternative to $ajax->autoComplete in cakephp 2.0?

CakePHP 2.0 HABTM Model Filename

I have two tables/models (messages and users) that are combined by a HABTM table (messages_users) Everything works right, but I need to make a change to the default model for MessagesUser. What should the filename for the model be? I have tried every thing I can think of: MessageUsers.php MessagesUsers.php Messages_Users.php ... I have my code working because I check in AppModel.php in the constructor if it is constructing MessagesUser and if so I make the change, but th

Cakephp Modifying aro_aco entries?

I'm using CakePHPs ACL to handle user permissions. When a user creates a, lets say Post, I automatically create an ACO for that post, and allow the user to access it. But, if I would like to change the user later on so that a different user "takes over" the ownership of the post, what would I do in the ACL? Is there a delete/remove ACL function I can use to remove rows, and the add the new relationship? I thought about using deny on the old user, and then allow all on the new one, but it wou

CakePHP + nuSOAP - exposing a global function as a closure or using models outside of the controller?

I need to implement a SOAP service in a CakePHP controller. The exposed function names need to be in a global namespace (as in "Authenticate", not "SOAPController.Authenticate"). This forces me to implement Authenticate in the global namespace, since nuSOAP will deduce where to look for the function from its name. On the other hand, on the example below, I cannot use CakePHP's API, because I have no access to SOAPController's this. That is why I thought I should somehow declare some kind of a cl

Mocking Email component in CakePHP Call to a member function on a non-object

I'm trying to mock an email component in a model, but after the first function, Cake gives me an error: Error: Call to a member function to() on a non-object Here's my test class: <?php App::uses('User', 'Model'); class UserTest extends CakeTestCase { . . // I'm not copying the setUp and tearDown methods here, but they are there. . . public function testEmailTest(){ $CakeEmail = $this->getMock('CakeEmail',array('to','subject')); $CakeEmail->expects($this->any(

Cakephp DomPDF strange page breaks

I'm using DomPDF with CakePdf to generate pdf. Good tool, but juste one thing I don't understand : the behavior of "page-break-before" in CSS. Usually it works pretty well : pages break when I want, but sometimes it becomes crazy and causes many page breaks inside, or before. Unbelievable. Here's an example of pdf generated with DomPDF, look at page 3, there's a blank whereas it should not (on other examples, it works well, no blank) : link [edit] and an HTML version as well : link Now the c

cakephp 1.2 saving multiple checkboxes

Using cakephp 1.2, I am attempting to save checkboxes as a string to the database. However, even though I am storing the checkboxes as a string, it is not saving.. Here is view: <?php echo $form->input('body_part', array('label' => false, 'type' => 'select', 'multiple' => 'checkbox', 'options' => $bodyparts, 'name' => 'body_part',

CAKEPHP - Undefined Index on production server

I put my application in a production server on the web and, it's not recognize any of my models. In my local server this works fine... This give this error on foreach datas. Undefined index: Power I have this in my controller: $this->set('poderes',$this->Attorney->Power->find('all')); This in my view: ?php foreach ($poderes as $power): ?> <?php debug($power) ?> <div class="checkbox tooltip" title="<?php echo $power['Power']['texto'] ?>"> <

CakePHP: issues with different model and used table names

I'm having a problem where I get an error saying, Error: Database table catalog_product_entity for model CatalogProductEntity was not found. I want the model MagentoCatalogProductEntity to use the table catalog_product_entity, but why is it looking for the model named after the table I defined, instead of the actual model name, MagentoCatalogProductEntity? I have... magento_catalog_product_entity.php class MagentoCatalogProductEntity extends AppModel { public $name = 'MagentoCatalogPr

PDF to Image Conversion not working in Cakephp

Hello anyone please help me out, In Cakephp i have the requirement of converting the dynamically generated pdf into .png image So for this I did this : $a = explode('/',$pdfURL1); $b = $a[10]; $c = explode('.',$b); $pdfname= $c[0]; //pr($pdfname); //$dirname = "D:/Images/ExtractFromFTP/" . $pdfname; $dirname = BASE_URL."app/webroot/images/uploaded_files/research/" . $pdfname; pr($dirname);

Cakephp Amazon Cloudfront redirecting to my site domain

i am using cloudfront to use images for good speed but when site is loading it first hits the url to amazon cloudfront and then redirect to my site domain, why this happening? I am doing this in cakephp. Please suggest what to do?

Cakephp authentication from two tables

I am using cakephp 2.0, I have two tables called accounts,subaccounts with fields as id,email,password. The table accounts contains the main account of a user and table subaccounts contains the sub account of a user in the accounts table. I have one login action for both of these accounts and subaccounts. What i planning do is that when a user enter an email and password in the login form then it will check the email id and password in both the accounts and subaccounts table and if any of these

Cakephp Zend studio class autocompletion for classes imported by ClassRegistry init

I am using cakephp, and if e.g. inside the component I need to use a model and I use $myModel = ClassRegistry::init('MyModel') trying to use some method of $myModel - autocomplete does not fire. When I use this way of importing models in component App::uses('MyModel', 'Model'); $myModel = new MyModel(); autocomplete works just fine. But I am using the first method, is there a way to make it work in that case ? Thanks

Return JSON array of associated entity IDs in CakePHP 3.0 belongsToMany relationship

If I have two tables, say foos and bars, in a many-to-many relationship (via a bars_foos join table, in this case), what is the best way in CakePHP 3.0 to include an array of the IDs of Bars associated with each Foo in the JSON returned by the RequestHandler through the _serialize property? Specifically, I would like to be able to visit site/foos.json and see something like this: { "foos": [ { "id": 1, "name": "A foo", ... "bar_ids": [1, 3, 5] }, { "

Cakephp Log Emails Sent to DB

Is it possible to log emails sent using CakeEmail using the new (2.1+) Events system? I'm hoping I can do something like this, only what I have doesn't do anything yet: // config/bootstrap.php App::uses('CakeEmailRecord', 'Lib/Event'); App::uses('CakeEventManager', 'Event'); CakeEventManager::instance()->attach(new CakeEmailRecord()); // /app/Lib/Event/CakeEmailRecord.php App::uses('CakeEventListener', 'Event'); class CakeEmailRecord implements CakeEventListener { public functi

Cakephp Notice (8): Indirect modification of overloaded property LayoutHelper::$View has no effect [APP/View/Helper/LayoutHelper.php, line 48]

While migrating CakePHP code from 1.3 to 2.x I am getting this notice message:- Notice (8): Indirect modification of overloaded property LayoutHelper::$View has no effect [APP/View/Helper/LayoutHelper.php, line 48] The code for this notice is:- function __construct($options = array()) { $this->View =& ClassRegistry::getObject('view'); $this->__loadHooks(); return parent::__construct($options); } What should I do to fix this?

Send image email cakephp without storing it

I'm using Cakephp 3 with Cake\Network\Email\Email. I have a form to send a message with two input fields. Those fields are stored in database. I'd like to join an image to this form without storing it: only in attachment. Here is my input file : <?php echo $this->Form->file('photo', ['class' => 'form-control','value'=>'','accept'=>'image/*']); ?> My Controller : $Email = new Email('default'); $Email->theme('Front') ->template('my_template1') ->viewVars(['se

CAKEPHP 3 : Select * and sum() in one statement

I am trying to fetch result from database table with SELECT * and SUM() function. The sql query is : SELECT * ,SUM(msg_send) AS msg_send FROM msg_campaigns Now how to write this query in cakephp3. I am trying this : $this->loadModel('MsgCampaigns'); $SmsDetails = $this->MsgCampaigns->find('all',[ 'conditions'=>['YEAR(date_time)'=>date('Y')], 'fields'=>['msg_send'=>'SUM(msg_send)','msg_failed'=>'SUM(msg_failed)'] ]); But I do not know how to use SELECT * . Ple

CakePHP 3 "Controller class XYZ could not be found." only on production server

I have a separate AppController for an external API to my site. I can connect to the API just fine using Postman on my local development machine, but once I move the files to the test site or production site, I get 404 errors like "Controller class Users could not be found." { "message": "Controller class Users could not be found.", "url": "/api/tv/users/index", "code": 404, "file": "/var/www/html/site/vendor/cakephp/cakephp/src/Http/ControllerFactory.php", "line": 100 } U

Cakephp Change the path search order

This is the current search path order: Element file aside/user-panel.php could not be found. The following paths were searched: [1].../vendor/maiconpinto/cakephp-adminlte-theme/templates/element/aside/user-panel.php [2].../templates/element/aside/user-panel.php [3].../vendor/cakephp/cakephp/templates/element/aside/user-panel.php How can I change the order so current [2] is search as first? The intention is that I don't want to make an edits in the original plugin templates. I rather want to c

Element view not working in controller in CakePHP 4.x

As on CakePHP 3.x, $this->view working properly in controller. After migration to the CakePHP 4.x version, it doesn't seems to work. Can't find any documentation under CakeBook 4.x. Is there any syntax changes in CakePHP 4.x for $this->view or it's deprecated in newer version ??

  1    2   3   4   5   6  ... 下一页 最后一页 共 49 页