Cakephp 3.0 NotFoundException home.ctp on production server [duplicate] - php

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.

Related

Symfony2 application not working when moving vendor directory

I have installed OroCommerce, a Symfony2 based application. I want to have the 'vendor' directory on a higher level outside the users directory. I followed the steps at http://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-vendor-directory but now the namespaces can't be found. I get the following error:
InvalidArgumentException in YamlFileLoader.php line 399: There is no extension able to load the configuration for "framework" (in /home/oro2/public_html/app/config/config_dev.yml). Looked for namespace "framework", found "web_profiler", "sensio_distribution", "debug"
in YamlFileLoader.php line 399
at YamlFileLoader->validate(array('imports' => array(array('resource' => 'config.yml')), 'framework' => array('router' => array('resource' => '%kernel.root_dir%/config/routing_dev.yml'), 'profiler' => array('only_exceptions' => false)), 'web_profiler' => array('toolbar' => true, 'intercept_redirects' => false), 'monolog' => array('handlers' => array('main' => array('type' => 'stream', 'path' => '%kernel.logs_dir%/%kernel.environment%.log', 'level' => 'debug'))), 'oro_assetic' => array('css_debug' => null, 'css_debug_all' => false), 'oro_message_queue' => array('client' => array('traceable_producer' => true))), '/home/oro2/public_html/app/config/config_dev.yml') in YamlFileLoader.php line 369
at YamlFileLoader->loadFile('/home/oro2/public_html/app/config/config_dev.yml') in YamlFileLoader.php line 44
at YamlFileLoader->load('/home/oro2/public_html/app/config/config_dev.yml', null) in DelegatingLoader.php line 45
at DelegatingLoader->load('/home/oro2/public_html/app/config/config_dev.yml') in AppKernel.php line 35
at AppKernel->registerContainerConfiguration(object(DelegatingLoader)) in bootstrap.php.cache line 2776
at Kernel->buildContainer() in bootstrap.php.cache line 2728
at Kernel->initializeContainer() in OroKernel.php line 290
at OroKernel->initializeContainer() in bootstrap.php.cache line 2507
at Kernel->boot() in OroKernel.php line 252
at OroKernel->boot() in bootstrap.php.cache line 2538
at Kernel->handle(object(Request)) in app_dev.php line 33
Am I forgetting something? Does anyone know how to solve this problem?
You are somewhere calling %kernel.root_dir%/config/routing_dev.yml which actually does not exist, because you have moved the config file dir

CakePHP 3.0 - $this->Model->get($id) thows MySQL error

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.

Error after updating php elasticsearch-php from 1.3.1 to 1.3.2

The following code worked before updating elasticsearch-php from 1.3.1 to 1.3.2:
$client = new Elasticsearch\Client();
// Index Settings
$indexParams['index'] = 'address';
// Example Index Mapping
$myTypeMapping = array(
'_source' => array(
'enabled' => true
),
'properties' => array(
'post_code' => array(
'type' => 'string',
'index' => 'not_analyzed'
)
)
);
$indexParams['body']['mappings']['postcode'] = $myTypeMapping;
// Create the index
$client->indices()->create($indexParams);
The error is as follows:
Fatal error: Uncaught exception
'Guzzle\Http\Exception\ClientErrorResponseException' with message
'Client error response [status code] 400 [reason phrase] Bad Request
[url] http://localhost:9200/address' in
C:\xampp\htdocs\locatr\vendor\guzzle\http\Guzzle\Http\Exception\BadResponseException.php:43
Stack trace: #0
C:\xampp\htdocs\locatr\vendor\guzzle\http\Guzzle\Http\Message\Request.php(145):
Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest),
Object(Guzzle\Http\Message\Response)) #1 [internal function]:
Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event),
'request.error',
Object(Symfony\Component\EventDispatcher\EventDispatcher)) #2
C:\xampp\htdocs\locatr\vendor\symfony\event-dispatcher\Symfony\Component\EventDispatcher\EventDispatcher.php(164):
call_user_func(Array, Object(Guzzle\Common\Event), 'request.error',
Object(Symfony\Component\EventDispatcher\EventDispatcher)) #3
C:\xampp\htdocs\locatr\vendor\symfony\event-dispatcher\Symfony\Component\Eve
in
C:\xampp\htdocs\locatr\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\GuzzleConnection.php
on line 266
Are there any changes between these versions that would break the code? There is nothing as far as I could see from the documentation.
Or is there an issue with the code sample? or is something else more likely?

Yii 2 User Authentication & Role Based Access Control (RBAC) Module installation and usage

I am trying to install and use this robregonm / yii2-auth module in my newly installed yii2 advance app.
I used composer to install it.
using this command
php composer.phar require robregonm/yii2-auth "dev-master"
I have configured my web and console files accordingly.
now I am trying to run migration as mentioned using
./yii migrate/up --migrationPath=#auth/migrations
And I am getting following error.
Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\db\Connection::user'
in /var/www/mycoolapp/vendor/yiisoft/yii2/base/Component.php:196
Stack trace:
#0 /var/www/mycoolapp/vendor/yiisoft/yii2/BaseYii.php(515): yii\base\Component->__set('user', Array)
#1 /var/www/mycoolapp/vendor/yiisoft/yii2/base/Object.php(104): yii\BaseYii::configure(Object(yii\db\Connection), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 /var/www/mycoolapp/vendor/yiisoft/yii2/di/Container.php(365): ReflectionClass->newInstanceArgs(Array)
#4 /var/www/mycoolapp/vendor/yiisoft/yii2/di/Container.php(147): yii\di\Container->build('yii\db\Connecti...', Array, Array)
#5 /var/www/mycoolapp/vendor/yiisoft/yii2/BaseYii.php(341): yii\di\Container->get('yii\db\Connecti...', Array, Array)
#6 /var/www/mycoolapp/vendor/yiisoft/yii2/di/ServiceLocator.php(132): yii\BaseYii::createObject(Array)
#7 /var/www/mycoolapp/vendor/yiisoft/yii2/console/controllers/MigrateController.php(124): yii\di\ServiceLocator->get('db')
#8 /var/www/mycoolapp/vendor/yiisoft/yii2/base/Controller.php(144): yii\console\controllers\MigrateController->beforeAction(Object(yii\base\InlineAction))
#9 /var/www/mycoolapp/vendor/yiisoft/yii2/console/Controller.php(83): yii\base\Controller->runAction('up', Array)
#10 /var/www/mycoolapp/vendor/yiisoft/yii2/base/Module.php(444): yii\console\Controller->runAction('up', Array)
#11 /var/www/mycoolapp/vendor/yiisoft/yii2/console/Application.php(164): yii\base\Module->runAction('migrate/up', Array)
#12 /var/www/mycoolapp/vendor/yiisoft/yii2/console/Application.php(140): yii\console\Application->runAction('migrate/up', Array)
#13 /var/www/mycoolapp/vendor/yiisoft/yii2/base/Application.php(329): yii\console\Application->handleRequest(Object(yii\console\Request))
#14 /var/www/mycoolapp/yii(30): yii\base\Application->run()
#15 {main}
PHP Fatal error: Uncaught exception 'yii\base\InvalidConfigException' with message 'Unable to append to log file: /var/www/mycoolapp/console/runtime/logs/app.log' in /var/www/mycoolapp/vendor/yiisoft/yii2/log/FileTarget.php:87
Stack trace:
#0 /var/www/mycoolapp/vendor/yiisoft/yii2/log/Target.php(103): yii\log\FileTarget->export()
#1 /var/www/mycoolapp/vendor/yiisoft/yii2/log/Dispatcher.php(179): yii\log\Target->collect(Array, true)
#2 /var/www/mycoolapp/vendor/yiisoft/yii2/log/Logger.php(162): yii\log\Dispatcher->dispatch(Array, true)
#3 [internal function]: yii\log\Logger->flush(true)
#4 {main}
thrown in /var/www/mycoolapp/vendor/yiisoft/yii2/log/FileTarget.php on line 87
I am confused about whats missing here?
I can not find auth module anywhere in app.
My question is where should I clone yii2-auth in app?
It seems that you misconfigured the db component in your config file, because, the user param does not exist, maybe you meant username. So the problem is not the extension itself but your local configuration setup.
Your db component should look like this:
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:dbname=YourDbName...', // replace pgsql with your db driver
'username' => 'YourUsername',
'password' => 'YourPwd',
'enableSchemaCache' => false,
'charset' => 'utf8',
],
Hope this helps.
Change you console/config/main-local.php, replace the key preload with bootstrap.
return [
'preload' => [
//'debug',
],
'modules' => [
//'debug' => 'yii\debug\Module',
//'gii' => 'yii\gii\Module',
],
];
TO
return [
'bootstrap' => [
//'debug',
],
'modules' => [
//'debug' => 'yii\debug\Module',
//'gii' => 'yii\gii\Module',
],
];

Cannot connect to firebird database - CakePHP 2.2.1

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.

Categories