I am developing a CakePHP site locally. I created a User model that is used by the UsersController. Everything works fine on my box, but as soon as I check out the code on my host (WebFaction) CakePHP starts trying to execute the names of methods in the User model as SQL queries.
# users_controller.php
public function index() {
$this->User->dummy_function();
$users = $this->User->find('all');
$this->set(compact('users'));
}
# User.php
public function dummy_function() { }
Now when I navigate to users/index I get the following error:
Warning (512): SQL Error: 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 'dummy_function' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 684] and the query that CakePHP executes is dummy_function
It follows that the framework cannot find my User model and that my host has something to do with this, but I have deployed CakePHP apps on this server before and never had this problem. I'm using CakePHP 1.3.11. Any ideas?
That's what I get for developing on Windows. Don't be a fool. Make sure your model name is all lowercase. Though I wish CakePHP warned me that it couldn't find the model.
Related
Been running cake app on shared host, which worked great until recently. The shared host supports Apache,PHP 5.4.45 through to PHP 7.0.21 and Mysql Server 5.6.35.
FYI - A skeleton app throws up the same error. This error is thrown way before database connection is made.
Below is the error am getting, the same app works ok on my local server.
Fatal error: Class Cake\ORM\ResultSet contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Iterator::current) in /projects/vendor/cakephp/cakephp/src/ORM/ResultSet.php on line 593
Fatal error: Cannot instantiate abstract class Cake\ORM\ResultSet in /vendor/cakephp/cakephp/src/ORM/Query.php on line 922
Looking forward to your insights on above.
Currently it looks like that this is the result of a bug in PHP:
https://github.com/cakephp/cakephp/issues/10936
https://github.com/cakephp/chronos/issues/147
https://bugs.php.net/bug.php?id=74833
Make sure to update to the latest CakePHP version, and if you the problem persists, try switching to PHP 5.6 until a fixed PHP version, or a workaround is available.
I've got a CakePHP based web app that needs some initial configuration. I'd like to do the equivalent of the mysql source command to set up a bunch of tables / initial rows, then execute a $this->User->save() command to create the root account (I think this needs to be done via code since it'll use the salt value for the local install of CakePHP, which might/should be different than the one on my dev machine), etc, etc.
My hack-y solution is to expose a public method on a controller that does this, direct my browser to it, then set stuff up (via the Configure::load and Configure::dump) so that the route from that URL to the method is removed after the installation is complete.
Does CakePHP provide any support for 'installing' a web app?
Part of my problem is that my attempts at Googling for "CakePHP web app installation" are all overshadowed by the various tutorials (etc) about how to install CakePHP itself. My issue is not installing CakePHP, it's providing an easy and safe way to set up the stuff my web app needs (like SQL database tables, etc) for it's particular needs.
It's called Cake Schemas....
The simplest thing you can do in your development environment is run the following via command line from root:
./app/Console/cake schema dump --write filename.sql
Which gives you a dump of your SQL file then you can edit the sql file directly before using it.
You specifically ask for running $this->User->save(), while learning about Schemas might be a bit complicated, you can accomplish this by running
./app/Console/cake schema generate
Which creates your schema.php, then:
App::uses('User', 'Model');
public function after($event = array()) {
if (isset($event['create'])) {
switch ($event['create']) {
case 'users':
App::uses('ClassRegistry', 'Utility');
$user = ClassRegistry::init('User');
$user->create();
$user->save(
array('User' =>
array(
'username' => 'admin',
'role' => 'admin',
'password' => 'admin'
)));
break;
}
}
}
Which makes a definition as you wish, then when you run:
./app/Console/cake schema create
Your tables get dropped, but remade as per your schema definitions and your model files, and with your specific "after" function
http://book.cakephp.org/2.0/en/console-and-shells/schema-management-and-migrations.html
I am working over Oracle DataBase and CakePHP 2.3.
As CakePHP doesn't support Oracle (there are no drivers for it), I am using Oracle procedures or php OCI8 functions in my models.
As a result of it, I am working with CakePHP without any effective database link in the eyes of CakePHP framework.
I am trying to use the Sanitize::clean method in order to clean a comment before saving it in the database and I am having troubles as it seems to look in the database for its task.
This is the resulting error:
Database connection "Mysql" is missing, or could not be created.
And this is how I try to sanitize it:
$comment = Sanitize::clean($this->request->data['comment']);
It works perfectly well if i just do this:
$comment = $this->request->data['comment'];
Is it possible somehow to use Sanitize::clean without any configured database at CakePHP 2.3?
Thanks
The function Sanitize::clean() expects 2 arguments, by default when you do not give a second argument CakePHP uses its default values and tries to connect to a DB with the 'default' connection. After a quick glance at the Sanitize Class in the library, it appears that it is the 'escape' option that requires a DB connection. It is called by default to make a string SQL-safe.
So in your case, as you don't need a SQL connection, this request should do the trick:
$comment = Sanitize::clean($this->request->data['comment'], array('escape' => false);
Check the CookBook for more information on the Sanitize class.
I am trying to send email with cake php email component:
var $components = array('Email');
$email = new CakeEmail();
$email->from(array('me#example.com' => 'My Site'));
$email->to('xxx#gmail.com');
$email->subject('About');
$email->send('My message');
And I always get message: Couldnt send email. Internal error occured.
In error log there is "SocketException".
I am using cakephp 2.0.
How should I configure things to get it work? I don't want to use any smtp servers and so on, I just want to send simple email.
I am using WAMP on my PC.
Uncomment the line: extension=php_openssl.dll in php.ini. This will resolve your Socket problem.
One more thing I want to say is :
You are mixing two thing core library & component both. FYI
EmailComponent is now deprecated. so use core library instead.
for more details check this link http://book.cakephp.org/2.0/en/core-utility-libraries/email.html
Debug the exception.
I bet that you can't open a connection to your mail server. Looks more like it's an error with your mail server setup or the connection to it than with CakePHp.
For an easy mail server setup for windows I recommend you to use XAMPP, it comes with the preconfigured mail server Pegasus, works just easy and fast for me.
This really does look like it's an error with your mail server setup or the connection to it. However, you are confusing the CakeEmail class for the EmailComponent.
Firstly you're not trying to send a email with the emailComponent, you are using the new CakeMail class (new from 2.x).
Thus, this:
var $components = array('Email');
and this:
$email = new CakeEmail();
are two different things. The first loads the EmailComponent, but you're not using it at all. The EmailComponent as of 2.x is deprecated. In your example you're using the CakeEmail Class.
Firstly you should insure that the class is actually loaded:
App::uses('CakeEmail', 'Network/Email');
Then check if you have the configuration file in:
App/Config/email.php
I suppose you're currently using the default configuration option. This means that the default transport is 'Mail' - the PHP mail function. I suppose you're getting a SocketException, because it can't connect to a underlying mail transport agent and because it is trying to do so over a System Socket... (Which I do not think exists in Windows, but I could be wrong. I know for sure that there is something like that in the windows API for inter-process cominucation)
Anyway, using the default email configuration is ok. Read the CakePHP Book's Section on the CakeEmail class.
I tried to upload my app to webserver to check it's performance, but unfortunately I got weird error:
Error: Database table news for model
News was not found.
The Most funny things are:
- In Model file I got var $useTable = 'other table name';
- This table exist, connection with DB too!
- on my local server everythings works great...
Any suggestions? Yes, I cleared the cache.
Cheers!
check model file name, capitalization matters on some server but not all. if it cant find the model file, then it doesnt know $userTable. just guessing