I'm trying to create a delete function inside a controller (PropertyController.php) which will delete a record from the DB and then fire an event.
However it's throwing this error:
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near 'get' at line 1
Stack trace:
CORE/Cake/Model/Datasource/DboSource.php line 460 → PDOStatement->execute(array)
CORE/Cake/Model/Datasource/DboSource.php line 426 → DboSource->_execute(string, array)
CORE/Cake/Model/Datasource/DboSource.php line 668 → DboSource->execute(string, array, array)
CORE/Cake/Model/Datasource/DboSource.php line 611 → DboSource->fetchAll(string, array, array)
CORE/Cake/Model/Model.php line 827 → DboSource->query(string, array, Property)
APP/Controller/PropertyController.php line 367 → Model->__call(string, array)
APP/Controller/PropertyController.php line 367 → Property->get(integer)
[internal function] → PropertyController->delete(string)
CORE/Cake/Controller/Controller.php line 490 → ReflectionMethod->invokeArgs(PropertyController, array)
CORE/Cake/Routing/Dispatcher.php line 193 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 167 → Dispatcher->_invoke(PropertyController, CakeRequest)
APP/webroot/index.php line 118 → Dispatcher->dispatch(CakeRequest, CakeResponse)
I can access records through find() but for some reason not with get().
/property/delete/2000
Function in PropertyController.php:
public function delete($propertyAgentRef = null) {
// Get property entity
$property = $this->Property->get($propertyAgentRef);
// Delete
$result = $this->Property->delete($property);
}
Property.php (Model)
class Property extends AppModel {
public $primaryKey = 'agent_ref';
public $hasMany = array(
'PropertyMediaImage' => array(
'className' => 'PropertyMediaImage',
'foreignKey' => 'agent_ref',
'dependent' => true,
'cascadeCallbacks' => true
),
'PropertyMediaFloorPlan' => array(
'className' => 'PropertyMediaFloorPlan',
'foreignKey' => 'agent_ref',
'dependent' => true,
'cascadeCallbacks' => true
),
'PropertyMediaDocument' => array(
'className' => 'PropertyMediaDocument',
'foreignKey' => 'agent_ref',
'dependent' => true,
'cascadeCallbacks' => true
),
'PropertyMediaVirtualTour' => array(
'className' => 'PropertyMediaVirtualTour',
'foreignKey' => 'agent_ref',
'dependent' => true,
'cascadeCallbacks' => true
)
);
}
Do I need to add a get method into my Model controller? Or is it perhaps an issue with my custom primary key?
Your code shows that you're using CakePHP 2.x but the way you try to use it is CakePHP 3. CakePHP 2.x doesn't feature entity objects. None existing model methods in Cake2 are executed as SQL, thats the cause of the error.
Double check which documentation you're reading, make sure you follow the 2.x documentation if you use Cake2.
When asking a question always name the exact CakePHP version you're using.
Related
I start in cakephp, my worry is that when I try to send a mail I have the following error:
Network is unreachable
Error: An Internal Error Has Occurred.
Stack Trace
CORE/Cake/Network/Email/SmtpTransport.php line 155 → CakeSocket->connect()
CORE/Cake/Network/Email/SmtpTransport.php line 95 → SmtpTransport->_connect()
CORE/Cake/Network/Email/CakeEmail.php line 1173 → SmtpTransport->send(CakeEmail)
APP/Controller/OnlinesController.php line 114 → CakeEmail->send(string)
[internal function] → OnlinesController->felicitation()
CORE/Cake/Controller/Controller.php line 491 → ReflectionMethod->invokeArgs(OnlinesController, array)
CORE/Cake/Routing/Dispatcher.php line 193 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 167 → Dispatcher->_invoke(OnlinesController, CakeRequest)
APP/webroot/index.php line 111 → Dispatcher->dispatch(CakeRequest, CakeResponse)
Here is my controller
<?php
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
class ContactController extends AppController {
public function felicitation()
{
$email = new CakeEmail('default');
$email->transport('smtp');
$email
->from('xxxxxxx#xxxxxx.org')
->to(['xxxxxx#xxxxx.com' => 'My Website'])
->subject('Contact')
->send('test mail');
}
}
Then my email.php file
<?
public $default = array(
'transport' => 'SMTP',
'host' => 'myhost',
'port' => 465,
'timeout' => 30,
'username' => 'domaine#domaine.com',
'password' => '*********',
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
?>
I think I have all try, I do not know what to do now so thank you in advance for your help
Everything was working fine. No errors. I change debug to 0, and all of the sudden my pages are giving 404 errors, and in my logs I'm noticing that variables I declared in my app controller (that were working perfectly before) are now coming back as not defined.
Weirdness. Why would changing debug to 0 cause this kind of behaviour?
Edit: Apr 18, 2012
I poked around the Pages controller. After the "$path = func_get_args();" when I threw in a die(print_r($path)). With debug 1 or 2 it returns this on my home page:
Array
(
[0] => home
)
It's blank when debug is set to 0.
Here's some of my routing:
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
Router::connect('/logout', array('controller' => 'users', 'action' => 'logout'));
Router::connect('/today', array('controller' => 'users', 'action' => 'today'));
Router::connect('/profile', array('controller' => 'users', 'action' => 'profile'));
$staticPages = array(
'about',
'contact'
);
$staticList = implode('|', $staticPages);
Router::connect('/:static', array(
'plugin' => false,
'controller' => 'pages',
'action' => 'display'), array(
'static' => $staticList,
'pass' => array('static')
)
);
From the debug log:
2012-04-17 10:28:08 Notice: Notice (8): Undefined variable: loggedIn in [/Users/conrad/Desktop/Creative/DEV/virtutrain/app/View/Elements/Header.ctp, line 3]
Trace:
include - APP/View/Elements/Header.ctp, line 3
View::_evaluate() - CORE/Cake/View/View.php, line 908
View::_render() - CORE/Cake/View/View.php, line 872
View::element() - CORE/Cake/View/View.php, line 412
include - APP/View/Layouts/default.ctp, line 22
View::_evaluate() - CORE/Cake/View/View.php, line 908
View::_render() - CORE/Cake/View/View.php, line 872
View::renderLayout() - CORE/Cake/View/View.php, line 527
View::render() - CORE/Cake/View/View.php, line 471
Controller::render() - CORE/Cake/Controller/Controller.php, line 959
ExceptionRenderer::_outputMessage() - CORE/Cake/Error/ExceptionRenderer.php, line 263
ExceptionRenderer::error400() - CORE/Cake/Error/ExceptionRenderer.php, line 209
ExceptionRenderer::render() - CORE/Cake/Error/ExceptionRenderer.php, line 165
ErrorHandler::handleException() - CORE/Cake/Error/ErrorHandler.php, line 127
[main] - [internal], line ??
Error log:
2012-04-17 10:28:08 Error: [NotFoundException] Not Found
#0 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/View/View.php(908): include()
#1 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/View/View.php(872): View->_evaluate('/Users/conrad/D...', Array)
#2 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/View/View.php(463): View->_render('/Users/conrad/D...')
#3 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Controller/Controller.php(959): View->render('about', NULL)
#4 /Users/conrad/Desktop/Creative/DEV/virtutrain/app/Controller/PagesController.php(88): Controller->render('about')
#5 [internal function]: PagesController->display('about')
#6 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Controller/Controller.php(485): ReflectionMethod->invokeArgs(Object(PagesController), Array)
#7 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Routing/Dispatcher.php(103): Controller->invokeAction(Object(CakeRequest))
#8 /Users/conrad/Desktop/Creative/DEV/virtutrain/lib/Cake/Routing/Dispatcher.php(85): Dispatcher->_invoke(Object(PagesController), Object(CakeRequest), Object(CakeResponse))
#9 /Users/conrad/Desktop/Creative/DEV/virtutrain/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#10 {main}
Again... not getting any errors whatsoever when debug is at 1 or 2...
This installation is being run locally on MAMP, but the errors also occur on the published site which is running on MediaTemple's grid service (with more or less default settings).
Wow... this was sitting in my home.ctp Page view, and got copied to all other pages:
if (Configure::read('debug') == 0):
throw new NotFoundException();
endif;
Major wtf, but regardless... problem solved.
I am using CakeEmail to send mails on my website, below are my config file info
public $default = array(
'host' => 'smtpout.asia.secureserver.net',
'port' => 25,
'username' => 'xxxxxx',
'password' => 'xxxxxx',
'transport' => 'smtp',
// "tls"=>true
);
It is working fine in my local computer but it is giving the below error on godaddy shared hosting.
Class "smtpTransport" not found.
Error: An Internal Error Has Occurred.
Stack Trace
CORE/Cake/Network/Email/CakeEmail.php line 1265 → CakeEmail->transportClass()
CORE/Cake/Network/Email/CakeEmail.php line 1133 → CakeEmail->_applyConfig(string)
APP/Controller/AppController.php line 46 → CakeEmail->config(string)
APP/Controller/ServicesController.php line 48 → AppController->sendMail(string, string, string, string, array)
[internal function] → ServicesController->consultnow()
CORE/Cake/Controller/Controller.php line 490 → ReflectionMethod->invokeArgs(ServicesController, array)
CORE/Cake/Routing/Dispatcher.php line 191 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 165 → Dispatcher->_invoke(ServicesController, CakeRequest)
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
Thanks
According to CakePhp's DOC the class is SmtpTransportnot smtpTransport
Autoloader is case sensitive
Reference: http://api.cakephp.org/2.5/class-SmtpTransport.html
I'm trying to find out how to use CakeEmail. To this end I've created a view called email-tester.ctp, using the Pages controller. I access it by calling the page directly (mydomain/mypath/pages/email-tester).
The view itself just holds the standard code from the documentation, more or less:
<?php
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->from(array('myaccount#gmail.com' => 'My Gmail Address'))
->to('my#email-address')
->subject('About')
->send('My message');
?>
<p>Email sent...</p>
I have also created an email config file (email.php) as follows:
class EmailConfig {
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'myaccount#gmail.com',
'password' => 'mypassword-for-gmail',
'transport' => 'Smtp',
);
}
When I run this page I just get an internal server error:
Error: An Internal Error Has Occurred.
Stack Trace
CORE/Cake/Network/Email/MailTransport.php line 51 → MailTransport->_mail(string, string, string, string, null)
CORE/Cake/Network/Email/CakeEmail.php line 1158 → MailTransport->send(CakeEmail)
APP/View/Pages/email-tester.ctp line 8 → CakeEmail->send(string)
CORE/Cake/View/View.php line 948 → include(string)
CORE/Cake/View/View.php line 910 → View->_evaluate(string, array)
CORE/Cake/View/View.php line 471 → View->_render(string)
CORE/Cake/Controller/Controller.php line 954 → View->render(string, null)
APP/Controller/PagesController.php line 69 → Controller->render(string)
[internal function] → PagesController->display(string)
CORE/Cake/Controller/Controller.php line 490 → ReflectionMethod->invokeArgs(PagesController, array)
CORE/Cake/Routing/Dispatcher.php line 191 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 165 → Dispatcher->_invoke(PagesController, CakeRequest)
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
Can anyone point out to me where I'm going wrong, please? Do I need to have a mail server running on my local development machine where I'm working? Or is the problem something more fundamental?
From other research I saw some suggestions that the php.ini file should contain a line for the extension php_openssl, however this just causes an error message to appear saying that the extension is not found: probably because it's included via gnutls (I'm on Ubuntu 14.10).
Any help would be much appreciated.
Peter
If you are working from a local server such as wampp, xampp, etc, this function wont work, yo do need to have a mail server setup for this to work. Once you have on, or if you can test in a real server this might help:
In:
Views->Layouts->Emails->html
I have an html template for my emails called "clientsreports":
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title><?php echo $title_for_layout;?></title>
</head>
<body>
<?php echo $content_for_layout;?>
</body>
</html>
Also your var in the EmailConfig file should be named smtp for it to work, check how mine is setup
class EmailConfig {
public $smtp = array(
'transport' => 'Smtp',
'from' => array('myaddress#gmail.com' => 'Senders name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'myaddress#gmail.com',
'password' => 'mypassword',
'client' => null,
'log' => false
);
}
Finally this is a simple example of how i send out emails:
$email = new CakeEmail('smtp');
$email->template('clientsreport', 'clientsreport');
$email->emailFormat('html');
$email->viewVars(array('message' => "This is the body of the message"));
$email->from(array('from#gmail.com' => 'Senders name'));
$email->to('whoisthemailfor#gmail.com');
//Only if neccesary this is how to carbon copy someone
$email->cc(array('carbon#one.com','carbon#two.com'));
$email->subject('Subject for the email');
$email->send();
I hope that helps, good luck!
I developed a site with CakePHP version 1.2.5 and everything worked fine by then. But now, I'm trying to re-implement my site with CakePHP version 2.2.1.
But the connection to the database (firebird) is not working anymore.
Here is my cake/app/Config/database.php file:
class DATABASE_CONFIG {
var $default = array(
'driver' => 'firebird',
'persistent' => false,
'host' => 'localhost',
'login' => 'SYSDBA',
'password' => 'masterkey',
'database' => 'd:\\IBDatabase\\DATA.GDB',
'port' => '3050',
'connect' => 'ibase_connect'
);
var $test = array(
'driver' => 'firebird',
'persistent' => false,
'host' => 'localhost',
'login' => 'SYSDBA',
'password' => 'masterkey',
'database' => 'd:\\IBDatabase\\DATA.GDB',
'prefix' => '',
);
}
And here is the error I'm getting:
Missing Datasource
Error: Datasource class could not be found.
Notice: If you want to customize this error message, create app\View\Errors\missing_datasource.ctp
Stack Trace
CORE\Cake\Model\ConnectionManager.php line 97 → ConnectionManager::loadDataSource(string)
CORE\Cake\Model\Model.php line 3158 → ConnectionManager::getDataSource(string)
CORE\Cake\Model\Model.php line 1092 → Model->setDataSource(string)
CORE\Cake\Model\Model.php line 3180 → Model->setSource(string)
CORE\Cake\Model\Model.php line 1301 → Model->getDataSource()
CORE\Cake\Model\Model.php line 1389 → Model->schema()
CORE\Cake\Controller\Component\PaginatorComponent.php line 354 → Model->hasField(string)
CORE\Cake\Controller\Component\PaginatorComponent.php line 125 → PaginatorComponent->validateSort(Professionals, array, array)
CORE\Cake\Controller\Controller.php line 1082 → PaginatorComponent->paginate(null, array, array)
APP\Controller\ProfessionalsController.php line 12 → Controller->paginate()
[internal function] → ProfessionalsController->index()
CORE\Cake\Controller\Controller.php line 485 → ReflectionMethod->invokeArgs(ProfessionalsController, array)
CORE\Cake\Routing\Dispatcher.php line 186 → Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 161 → Dispatcher->_invoke(ProfessionalsController, CakeRequest, CakeResponse)
APP\webroot\index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)
Does anyone know what I should do?
Thanks!!
After a lot of research, I've found that Cake 2.x is not compatible with firebird.