I am getting the error Fatal error: Cannot redeclare config() (previously declared in.../basics.php:58, in live server. It works fine in my local server but when i uploaded the site to live server, i got the fatal error.
I checked if the config() was declared multiple times but it's only declared once in basics.php file.
The naming conventions are also followed, as it is working fine in local server. It only displays such error in live site.
Please suggest solution for this.
Help on this will be much appreciated.
set $uses to array() and $autoRender to false as follows will solve this problem
class IndexController extends AppController
{
public $uses = array();
public $autoRender = false;
public function index()
{
echo 'test';
}
}
I had this error running Apache, and it ended up being related to my .htaccess files being ignored - I had been reconfiguring Apache, and had accidentally set AllowOverride to None in my config file, which was somehow causing this error.
So, in brief, in either your http.conf or one of your site configs, make sure the AllowOverride in your relevant Directory section is set to All (or something other than None), here's mine:
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
This can happen if "basics.php" was included multiple times. You can prevent it by using include_once/require_once instead of include/require.
But this doesn't explain why it's working on your local webserver.
Just in case somebody happens to search for this.
I had the same error on a windows 2003 server with cakephp 1.3.11 installed. In my case it was because I had a typo in one class association declaration.
I had defined a Client class with a hasOne association to a Account class. There I had wrongly typed the className property to Client which created a loop and resulted in the Cannot redeclare config() error in cakePHP.
Check your PHP version. that errors happens when you use PHP version 5.4 which is more stricter than 5.3
open your cake/bootstrap.php and make changes to make sure every file loaded once with function 'require_once'. The code will be like this:
require_once CORE_PATH . 'cake' . DS . 'basics.php';
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
require_once LIBS . 'object.php';
require_once LIBS . 'inflector.php';
require_once LIBS . 'configure.php';
require_once LIBS . 'set.php';
require_once LIBS . 'cache.php';
Configure::getInstance();
require_once CAKE . 'dispatcher.php';
Related
Hi i am using cakephp 2 . i am including external php folder in app/webroot
and in my controller used following to include the file .
include_once(ROOT . DS . 'app' . DS . 'webroot'.DS . 'socio'.DS . 'index.php');
The file is getting included but i am getting error Cannot redeclare class App .
i know i have declared App class twice . Since it is external folder having many dependencies i cant change class name . Please help me to find solution
Can you use something like this, WWW_ROOT is a Core Definition Constant and gives full path to the webroot.
include_once(WWW_ROOT . 'socio'.DS . 'index.php');
https://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html
I have one route:
Route::controller('/', 'HomeController');
And HomeController has one action getIndex which works correctly. However, when browsing to http://localhost:4040/public/style.css, the application returns the view from HomeController::getIndex. What gives?? Shouldn't it return the static file style.css?? I have confirmed that the CSS file does in-fact exist in the public folder.
To be clear, I'm running the app like this:
php -S localhost:4040 server.php
EDIT:
Hmmm, so the following seems to work:
1) Serve the project with:
php artisan serve
2) Reference files without the public/ prefix.
What does the php artisan serve command do so differently??
With using Route::controller(), if you look at the php artisan routes, the getIndex route has a optional parameters {one?}/{two?}/... and since that parameters have no matching pattern style.css get caught by the {one?}. This is the completely expected behavior, with index.php.
However, using php artisan serve, the server.php file gets called first.
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri = urldecode($uri);
$paths = require __DIR__.'/bootstrap/paths.php';
$requested = $paths['public'].$uri;
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' and file_exists($requested))
{
return false;
}
require_once $paths['public'].'/index.php';
You can clearly see that it checks if the file is real in if ($uri !== '/' and file_exists($requested)), and if it is, it stops calling the index.php that may process it as a route parameter, and instead returns a real file.
This question is similar to this other one, but I am using full-URL, no mod_rewrite, see cakephp WITHOUT mod_rewrite or this "sibling question".
I have a CakePHP folder that works well, at /var/www/mycake (localhost/mycake). Now I need change to /var/www/test/mycake (localhost/test/mycake)... HOW TO DO THIS CHANGE with minimal PHP code changes?
I add a controller as Cake message recomended:
TestMyCakeController.php ... nothing
TestController.php OK (!), but other error arrises
Cake defines its ROOT directory in the root index.php file. If you look inside you'll see the following lines:
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'mycake');
define('WWW_ROOT', ROOT . '/' . 'test' . '/'. WEBROOT_DIR . '/');
You can easily move a CakePHP application to another directory under your web root. The top level index.php contains the line:
define('ROOT', dirname(__FILE__));
This will set the root directory to the current location of the main index.
I'm very new to Fat-Free and Backbone.js. I've been searching and reading articles and searching and reading articles trying to find a way to route to individual PHP files containing the database communications. The code below works, and I can use it, but it seems hackish. Is there a way to call an external PHP file (in the server/models/ directory) and a specific method from the $f3-route(...) line?
<?php
// File: /index.php
define("PATH",1);
$f3 = require('server/fatfree/lib/base.php');
$uri = explode('/', $_SERVER["REQUEST_URI"]);
require_once "server/models/{$uri[PATH]}.php";
$f3->route('GET /hello/#file', 'HelloModel->doSomething');
$f3->route('GET /project/#file', 'ProjectModel->doSomething');
$f3->route('GET /book/#file', 'BookModel->doSomething');
$f3->run();
?>
Thanks a lot for your advice.
You should add the server/models directory to the autoloader of F3 using the autoloader feature.
$f3->set('AUTOLOAD','server/models/');
That way, the required source files of your classes will be loaded on demand. However, note that the files must be named the same as your class, i.e. class Foo has to be defined in foo.php or Foo.php. The case of the filename does not matter.
I am completely new to CakePHP and installed 2.1. I am getting this error:
Missing Controller
Error: Index.phpController could not be found.
Error: Create the class Index.phpController below in file: app\Controller\Index.phpController.php
<?php
class Index.phpController extends AppController {
}
Notice: If you want to customize this error message, create app\View\Errors\missing_controller.ctp
Stack Trace
APP\webroot\index.php line 96 → Dispatcher->dispatch(CakeRequest, CakeResponse)
ROOT\index.php line 40 → require(string)
I followed their guide at http://book.cakephp.org/2.0/en/installation/advanced-installation.html and tried everything it stated:
I enabled mod_rewrites (they were already enabled from something else)
I have all the .htaccess files in the directories
I have cake installed under my document root so I access it at localhost/cakephp/index.php
I do not know where to proceed from here. Thanks for any help you can give me.
Update: I just re-read your question and realized you're loading http://localhost/cakephp/index.php. Don't do that. Since you appended "index.php", it is trying to load a controller called "index.php" and the action "index" for that controller. Resulting mapped path to the "index.php controller" is app\Controller\Index.phpController.php.
Since you have the rewrites enabled, browse to http://localhost/cakephp without appending any filename.
Original answer:
Assuming you're using Apache, double-check the .htaccess in your /app/webroot directory. It should include the following:
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Based on your error, it doesn't look like it's properly appending the path after your index.php file.
If you are using cakephp 2.0 or greater than rename the controller file name as the class name.
ie TaskController.php
class TasksController extends AppController {
--Your code inside class
}
I hope this will help you
the easiest solution is to stick to the "live environment" as close as possible.
this means using vhosts to use a "domain" and correctly root down to your webroot dir:
http://www.dereuromark.de/2011/05/29/working-with-domains-locally/
this leaves almost no room for error and also helps with other potential problems like "absolutely linked asset files" etc