When I make a React project on github.io, I can't see any components in Chrome.
In the 'myUserName.github.io' repository, there is a general HTML file. And a directory in the repository is my React project folder:
And the HTML file:
Like these pictures, <div id="root"> is empty. But when I use it on localhost, it does run.
What could be the problem?
------------------- Add source code -----------------------
Directory :
__ index.html (1)
|__ react __ space-trip __ build __ static __ ...
. . . . . . . . . . . . . . . . . . | . . . . . . |__ index.html
. . . . . . . . . . . . . . . . . . |__ node_modules __ ...
. . . . . . . . . . . . . . . . . . |__ public __ index.html (2)
. . . . . . . . . . . . . . . . . . |__ src __ App.js
. . . . . . . . . . . . . . . . . . |. . . . . |__ index.js (3)
. . . . . . . . . . . . . . . . . . |. . . . . |__ registerServiceWorker.js
. . . . . . . . . . . . . . . . . . |__package.json
(1) project's index.html :
<!DOCTYPE html>
...
<body>
<div>Index Page</div>
<a href='./react/space-trip/public/index.html'>Go</a>
<a href='./react/space-trip/build/index.html'>Go - build</a>
</body>
</html>
(2) public/index.html :
<!DOCTYPE html>
<html lang='en'>
<head>
...
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id='root'></div>
</body>
</html>
(3) index.js :
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
After building this project and I added the url to [build]-[index.html], it's also empty.
I also tried running this page without registerServiceWorker, but it's same.
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
Please see my current file structure
CakePHP
- bin
- config
- src
- vendor
- webroot
RowPHP
- push.php
I want to import/include Push class into my cakephp2 application which stands at push.php file outside of cakephp
Which I have tried
require_once( ROOT . DS . '..' . DS . 'RowPHP'. DS . 'push.php');
$pushOb = new Push();
it include successfully but when I try to create a object it through error
Fatal error: Class 'App\Controller\Push' not found
Question: How to import/include this class into my cakephp application ?
You need to ensure PHP can find the class in the correct namespace using new \Push() (note the backslash before the class name):-
require_once( ROOT . DS . '..' . DS . 'RowPHP'. DS . 'push.php');
$pushOb = new \Push();
Just migrated a system to the new cake3.
However now due to namespaces, struggling to dynamically load libraries inside methods.
I have a controller
with this in :
require_once(APP . 'Lib' . DS . 'Channel' . DS . 'Channel1.php');
require_once(APP . 'Lib' . DS . 'Channel' . DS . 'Channel2.php');
require_once(APP . 'Lib' . DS . 'Channel' . DS . 'Channel3.php');
require_once(APP . 'Lib' . DS . 'Channel' . DS . 'Channel4.php');
use Channel\Channel1;
use Channel\Channel2;
use Channel\Channel3;
However I don't want to load all the libraries unless I need them. Any suggestions for a good solution?
If you put the files in src/Channel instead ofsrc/Lib/Channel then the autoloader will find automatically your files when you do
use App\Channel\Channel1;
It will require that you set the namespace of the class to App\Channel
You can also tell composer how to autoload your custom namespace. In your composer .json's autoload section, under psr-4, do:
"Channel\\" : "./src/Lib/Channel"
And finally execute composer dumpautoload
I am getting an error while hosting a cakephp app:
Fatal error: Can't find application core file. Please create /home/home/a1808794/a1808794/home/a1808794/app/Config/core.php, and make sure it is readable by PHP. in /home/a1808794/lib/Cake/Core/Configure.php on line 78
Failed opening '/home/home/a1808794/a1808794/home/a1808794/app/Config/core.php' for inclusion (include_path='/home/a1808794/lib.:/usr/lib/php:/usr/local/lib/php') in /home/a1808794/lib/Cake/Core/Configure.php on line 77
The index.php
if (!defined('ROOT')) {
//define('ROOT', dirname(dirname(dirname(__FILE__))));
define('ROOT', dirname(dirname(dirname(__FILE__))).DS.'home'.DS.'a1808794');
}
/**
* The actual directory name for the "app".
*
*/
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))).DS.'home'.DS.'a1808794'. DS .'app');
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (function_exists('ini_set')) {
/*ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));*/
ini_set('include_path','home'. DS . 'a1808794'. DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
}
I'm not sure why you think it was necessary to modify the index.php file and replce this:
define('ROOT', dirname(dirname(dirname(__FILE__))));
With this:
define('ROOT', dirname(dirname(dirname(__FILE__))).DS.'home'.DS.'a1808794');
And replace this:
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
With this:
ini_set('include_path','home'. DS . 'a1808794'. DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
And set the app dir to:
define('APP_DIR', basename(dirname(dirname(__FILE__))).DS.'home'.DS.'a1808794'. DS .'app');
Because that is breaking the includes. Your app is now trying to include /home/home/a1808794/a1808794/home/a1808794/app/Config/core.php which is obvisouly not a valid path. Restoring the original index.php should work just fine. If it doesn't, please state what the actual problem was that made you modify the index.php in the first place. The index.php should work out of the box and I have not had to modify it ever.
Error message:
Fatal error: Class 'Configure' not found in C:\wamp\cakephp\2.3\lib\Cake\bootstrap.php on line 163
I have seen other answers on this issue (like this one), all hinting at ensuring I am not missing any files, but I have added all files and folders from a fresh download of CakePHP v.2.3 via Github.
Can anyone shed any light on why I am still getting an error like this?
Key lines of code shown below:
webroot/index.php
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', '../../../cakephp/2.3/lib');
}
if (!defined('CORE_PATH')) {
if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
[...]
define('CORE_PATH', null);
} else {
[...]
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
lib/Cake/bootstrap.php
App::uses('Configure', 'Core');
Configure::bootstrap(isset($boot) ? $boot : true);
You seem to have an old version of index.php
Use the current one available at github.
It contains
if (!defined('CAKE_CORE_INCLUDE_PATH')) {}
instead of your
if (!defined('CORE_PATH')) {}
Where is DocumentRoot pointing to ?
If you load (e.g.) /index.php then your include_path could be incorrect and one directory too deep.
Use instead:
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', '../../cakephp/2.3/lib');
}