I am working on a legacy CakePHP 1.3 app and while I have years of experience with PHP, I am still finding my feet with CakePHP. I am following Chapter 4 'How to use the bakery' in Jamie Munro's Rapid Application Development with CakePHP, however the steps he suggests do not seem to go the way I'd expect them too.
I feel a good way of explaining this is going through the steps involved:
Following the books 'Hello World' example outlined in earlier chapters, I have setup a basic CakePHP app at this location on my machine: /home/public_html/helloworld.local. I can see the 'Hello World' example in a web browser on my local machine when I access: http://helloworld.local/users/add
Chapter 4 suggests that I move to this directory: home/public_html/helloworld.local/cake/console
I then run: ./cake bake
I get prompted to enter the location of the app and I add:
/home/public_html/helloworld.local/app
I then proceed to select defaults for the next few selections and there are no problems until I run into the line:
Your database configuration was not found. Take a moment to create one.
I do not understand this since there is a database file configured in ~/public_html/helloworld.local/app/config/database.php, and when I access the helloworld app outlined earlier (available on my local machine at http://helloworld.local/users/add), there is a database connection successfully established and records can be inserted.
I have also tried re-entering my database details when offered the chance to by cake bake, but end up with the error after succesfully adding the correct details:
Fatal error: Class 'DATABASE_CONFIG' not found in
/home/public_html/helloworld.local/cake/console/libs/tasks/db_config.php
on line 260
But either way, it should have found the existing database connection details, so not sure what is going on.
For using console command like cake bake you have to use your operating system terminal(for linux)/ command prompt(for windows). So you have to do the step mentioned in step 2 and 3 in you console. You can read documentation here to know how to use console commands.
Then, make sure that you have the file home/public_html/helloworld.local/app/config/database.php. I hope you removed .default from its name and rename it to database.php. To link up your database with your cakephp project you have to specify credentials in database.php.
var $default = array('driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'password',
'database' => 'database_name',
'prefix' => ''
);
I don't have a running CakePHP 1.3 installation here at hand, but this is what is happening at that location:
// #link: https://github.com/cakephp/cakephp/blob/1.3/cake/console/libs/tasks/db_config.php#L260
config('database');
$db = new $this->databaseClassName; // i.o.w. $db = new DATABASE_CONFIG;
This line:
config('database');
Does nothing more than including the database.php configuration file, simplified to;
include_once(CONFIGS . $arg . '.php'); // i.o.w. include_once(CONFIGS . 'database.php');
(https://github.com/cakephp/cakephp/blob/1.3/cake/basics.php#L77)
So IMO two problems may cause your error;
app/config/database.php was not found
You can try to check if this outputs the right path:
die(CONFIGS . 'database.php');
There is an error in your app/config/database.php, causing the DATABASE_CONFIG class to be malformed and unable to be initialized
A word of notice
Aparently your running 'bake' for everything including setting up a new database configuration. This may overwrite your
existing database configuration. It is possible to bake only parts of your application (e.g. bake controllers only or models).
The manual on baking in CakePHP 1.3 is located here:
http://book.cakephp.org/1.3/en/The-Manual/Core-Console-Applications/Code-Generation-with-Bake.html
And this
If this is your first CakePHP project, you should realy consider the option to upgrade to CakePHP 2.x CakePHP 1.3 is really outdated and, although it's still able to run fine, I wouldn't invest too much time in 1.3 as a lot of things have changed in CakePHP 2.x. It's probably better to start with CakePHP 2.x then to start with 1.3 and learn things that no longer work in CakePHP 2.
Copy your app/Config folder to app/Console, so the final path would be app/Console/Config. That worked for me.
Related
I'm writing a PHP library for accessing the Odoo XML-RPC API and I need to know the Odoo version of the server I'm talking to - but I can't figure out how to determine the version. Is there a certain model that will tell me or how do I do that?
UPDATE
I thought I have figured it out. The ir.module.module model will give you a list of all the installed modules. Then in the base module you look at the installed_version property. BUT this requires admin access! I need to do this as the regular user that is normally using the API.
But for anyone who has that kind of access this is what you would do. Using ripcord (see example here) you would use this line to retrive just the base module:
$models->execute_kw($db, $username, $password, 'ir.module.module', 'search_read', array(array(array('name', '=', 'base'))) );
You can get the Odoo version even without authentication from the API common endpoint. See documentation on https://www.odoo.com/documentation/12.0/webservices/odoo.html heading ”Logging in” and the first code sample there. You can find the server_version property there.
$common = ripcord::client($url.'/xmlrpc/2/common');
$common->version();
Following code is valid and working fine tested on multiple servers.
$url = 'https://###.###.###.##:8069';
$db = 'demo';
$username = 'user_name';
$password = 'password';
$common = ripcord::client("$url/xmlrpc/2/common");
$models = ripcord::client("$url/xmlrpc/2/object");
$common->version();
$uid = $common->authenticate($db, $username, $password, array());
These examples use the Ripcord library, which provides a simple
XML-RPC API. Ripcord requires that XML-RPC support be enabled in your
PHP installation.
Since calls are performed over HTTPS, it also requires that the
OpenSSL extension be enabled.
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 not sure what is going wrong when I am trying to install magento to my local ubuntu machine.
I did all the steps mentionsed in the magento wiki. Everything goes well until I reach the point where I am here which is the magento config page. When I try and continue after entering the necessary details like host, database name and user name and submit it comes back to the same page. I checked for everything like db in my phomyadmin panel and it still gets stuck there. What is the possible reason for that.
Thanks
Have you try with 127.0.0.1 instead of localhost ?
They have some trouble on login in the admin section.
And check the user/password in the config too !
You have to create a database first and then proceed further.
Step 1 - First create a database with name of your choice like magento
Step 2 - Use that database name in the installation form now
Step 3 - Continue
Hope this solves your problem.
I solved this modifing app/code/core/Mage/Install/etc/config.xml (near 71th string) this
<extensions>
<pdo_mysql/>
</extensions>
for this
<extensions>
<pdo_mysql>1</pdo_mysql>
</extensions>
Verify that you meet the following requirements:
http://www.magentocommerce.com/system-requirements
Magento only runs on php 5.2.x, not 5.3. Also make sure the extensions listed on the requirements page are enabled.
Might be different for you, but I can check the php version using
php -v
Edit
Also what c-verde said about using 127.0.0.1 instead of localhost:
This isn't your current problem, but you'll run into it later. You need to be able to accept cookies to log into Magento. Your browser won't accept cookies for local sites.
In /etc/hosts you need to add
127.0.0.1 localhost.com
And when you install magento you need to use either localhost.com or 127.0.0.1 instead of localhost.
I didn't have this problem with linux, but when installing on windows, it took several minutes after the config page to set up magento. Make sure the browser isn't doing anything.
Before running the installation of Magento:
Navigate to the Varien.php file located in magento/app/code/core/Mage/core/Model/Session/Abstract/Varien.php
You must comment out the last 3 lines in the $cookieParams array:
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath()
//'domain' => $cookie->getConfigDomain(),
//'secure' => $cookie->isSecure(),
//'httponly' => $cookie->getHttponly()
);
Tick the box for
Skip Base URL Validation Before the Next Step
Check this box only if it is not possible to automatically validate the Base URL.
I also added to my C:\windows\system32\drivers\etc\hosts file
127.0.0.1 www.localhost.com
and removed my magento directory and database tables and started from scratch.
Works for me now.
I did this and it worked!
Navigate to the Varien.php file located in magento/app/code/core/Mage/core/Model/Session/Abstract/Varien.php
You must comment out the last 3 lines in the $cookieParams array:
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath()
//'domain' => $cookie->getConfigDomain(),
//'secure' => $cookie->isSecure(),
//'httponly' => $cookie->getHttponly()
);
and if you got InnoDB error then do this
Go To Line 59 of the file app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php
Use following code instead of current one
public function supportEngine()
{
$variables = $this->_getConnection()
->fetchPairs('SHOW ENGINES');
return (isset($variables['InnoDB']) && $variables['InnoDB'] != 'NO');
}
Make sure you load php5-mysql extenion. Thats how I solved my problem.
I loaded with http://localhost.com (adding 127.0.0.1 localhost.com to /etc/hosts), it gave my error load pdo-mysql php extension. Otherwise with http://localhost, no error just reloading in configuration page)
I had also been through this problem. I had just create the db first named "magento" and put the 127.0.0.1 instead of localhost. I think, instead of 127.0.0.1, 'localhost' should also work if you had configure it. The problem might be because you didn't have the password for the database but you trying to put the password while installing the magento. Hope this helps some of them.
I had the same problem. Turned out that I was missing a php module but no error was displayed. Megento are now providing a simple php script that checks if the required modules are available and displays an appropriate message if you are missing any of them.
You can find it here - http://www.magentocommerce.com/knowledge-base/entry/how-do-i-know-if-my-server-is-compatible-with-magento
You have to submit username and password as 'root' and 'password' as per db setting
My answer might be late for the PM, but probably useful to those who landed in this page via google.
My experience was that the whole configuration page is a blank page, without any form regarding database, user info or anything.
I fixed it by modifying the {Megento Path}/app/etc/config.xml file.
<default_setup>
<connection>
<host>localhost</host>
<username/>
<password/>
<dbname>magento</dbname>
<model>mysql4</model>
<initStatements>SET NAMES utf8</initStatements>
<type>pdo_mysql</type>
<active>0</active>
</connection>
</default_setup>
Change the value of the host item to anything other than localhost.
Then you get those forms and everything and can move on.
I guess you are missing the port name on which your mysql is running. Try using the port after your hostname for eg. localhost:3306 ,was my configuration settings along with database name and password of your mysql.
I'm having trouble with uploading my cakePHP project on a shared hosting ( from hostgator ).
Here is what I have done:
I've organized my cake distribution like this:
home/user/app
home/user/cake/cake
home/user/cake/vendors
home/user/cake/.htaccess
home/user/cake/index.php
I have taken the content of webroot directory from app and put it in
home/user/public_html
I've modified this file home/user/public_html/index.php ( the one that was in app/webroot )
changing these lines like this:
define('ROOT', DS.'home'.DS.'user');
define('APP_DIR', 'app');
define('CAKE_CORE_INCLUDE_PATH', DS.'home'.DS.'user'.DS.'cake');
And that's about it.
MY PROBLEM IS THE FOLLOWING:
I have managed to deal with all the problems involved in the default index.php cakePHP page and I have a green and fully functional so to say, project. So when I access my "/", I get:
"Your tmp directory is writable.
The FileEngine is being used for caching. To change the config edit APP/config/core.php
Your database configuration file is present.
Cake is able to connect to the database."
Now, I've created a model-view-controller with a mysql database background (like in the 15 min Blog Tutorial ), but when I'm trying to access some views ( e.g. /posts )...it gives me a blank page ( this worked perfect on my local machine virtual server apache ).
What configuration am I missing ?
Thank you.
EDIT: Apparently I had problems with the hosting. My URL was something like:
http://gator111.hostgator.com/~username/
and all I had to do was add an extra line in the webroot .htaccess:
RewriteBase /~username/
Thanks for the support.
This tutorial is a life saver, I had the same problem that my host name comes with ~username. Now after adding the 'rewriteBase /~username/', works like a charm.
However, before all these, I followed a youtube tutorial by jason talking about how to configure cakephp on shared hosting. Just paste it here in case it helps anybody.
http://www.youtube.com/watch?v=4GobWo1rIkE&tracker=False