Change root without change application with CakePHP? - cakephp-2.0

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.

Related

Apache 2 /httpd vhost dynamic documentroot

I have an app in folder /var/www/test
Also there is an "sub-app" in folder /var/www/test/subapp (There is another index.php inside
If user will type test.com the index.php of test should trigger but when user type test.com/triggersubapp the index,php from /var/www/test/subapp shall run.
I failed to create correct statements and RewriteRules and I haven't got much time left. So have any one of You know how to do this easiest way or maybe have a correct definition?
I would greatly appreciate it !!!
EDIT
The main index.php and .htaccess are in /var/www/test/public/. :(
Put this in your .htaccess in root directory:
RewriteEngine On
RewriteRule ^triggersubapp/?$ subapp/index.php
This will rewrite triggersubapp to subapp/index.php which means if user enters test.com/triggersubapp he/she will see result for test.com/subapp/index.php

Zend framework uploading file and setting destination problems

I've got a problem with uploading a file with ZF.
This is my application structure:
//application
//images
index.php
//library
//styles
//public
//img
The application path in index.php seems to be ok:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
When i try to upload a file i get a message (such a dir does not exist).
This is my controllers code snippet:
$upload->setDestination(APPLICATION_PATH . '../public/img/');
Can anyone help please?
Your APPLICATION_PATH is not followed by a slash. Invoke setDestination() like this:
$upload->setDestination(APPLICATION_PATH . '/../public/img/');

Is it possible to change image folder in cakephp 2.4

I have read many docs, but failed to solve the problem:
Images in my existing project stored in $_SERVER['DOCUMENT_ROOT'].'/media/'
I want, but can't change in cakephp 2.4 default image folder from $_SERVER['DOCUMENT_ROOT'].'/app/webroot/img/' to any I desire.
lib/Cake/bootstrap.php contains constants:
/**
* Path to the public images directory.
*/
if (!defined('IMAGES')) {
define('IMAGES', WWW_ROOT . 'img' . DS);
}
/**
* Web path to the public images directory.
*/
if (!defined('IMAGES_URL')) {
define('IMAGES_URL', 'img/');
}
and
Configure::write('App.imageBaseUrl', IMAGES_URL);
I tried to change:
IMAGES to $_SERVER['DOCUMENT_ROOT'].'/media/'
IMAGES_URL to /
And it doesn't work at all. All image files still points to $_SERVER['DOCUMENT_ROOT'].'/app/webroot/img/' I see it when try to render image in view:
echo $this->Html->image('/img/ride_scheme/chema.jpg', array( 'width' => 300 ));
If I created in app/webroot/img/ride_scheme image file chema.jpg it rendered, but I changed the folder in IMAGES constant in lib/Cake/bootstrap.php !!!
In documentation I see:
Constants IMAGES_URL, JS_URL, CSS_URL have been deprecated and
replaced with config vari- ables App.imageBaseUrl, App.jsBaseUrl,
App.cssBaseUrl respectively.
Constants IMAGES, JS, CSS have been deprecated.
I gues that is the problem.
Please, show me how to change image folder
According to your description, I reckon IMAGES_URL should be media/ and not just /.
Alternatively, you could add a RewriteRule to your .htaccess (in the project root) to rewrite everything to the media folder (assuming you have an Apache web server with the Rewrite module enabled):
RewriteRule ^app/webroot/img/(.*) /media/$1
Or you could create a symbolic link that links the img/ folder to your media folder (assuming you're on Linux hosting and you have ssh/shell access to your server):
cd app/webroot
rm -rf img/
ln -s ../../media img

CakePHP 2.1 new install Missing Controller Error

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

AssetCompress for CakePHP 1.3

I'm using AssetCompress v0.5 from the 1.3 branch and the dynamic built is not working. I've done the following so far:
Downloaded and copied the asset_compress folder into my app/plugins folder
Copied the config.ini and renamed it to app/config/asset_compress.ini
Created 2 CSS and JS bundles named public and logged (so 4 in total)
Added AssetCompress.AssetCompress in my $helpers array in my AppController
Changed my default.ctp layout file to: echo $this->AssetCompress->css('public'); echo $this->AssetCompress->css('logged'); (same for ->script())
The output error is:
Error: The requested address '/asset_compress/assets/get/public.css' was not found on this server.
What am I missing?
Ok, I figured it out.
It was because I was using the CssMin filter and I did not download it and put it into the vendor folder. As the plugin seems to be turning the debug level to 0, I did not see the error, until I put a Configure::write('debug', 2); into the beforeFilter().

Resources