How to access directly to files in application directory in codeigniter - php

I have a folder in my view inside application directory that contain .js files. I want to load .js files in my view. How can do this?

its not a good practice to put your js files in view folder, make a folder called 'assets' in the root directory alongside 'application' and 'system' put all js code in js folder.
assets
--css
--js
-- images
system
application

Related

How to run files from every folder in PHP?

I have a main folder project name socialNetwork. In this folder, I have 3 folder name application, database, and view. folder view has 2 folders views and page. These folders have files php. Now if I want to run the file from view folder I have to be inPSC:\PhpstormProject\socialNetwork\> and use php view/page/profile.php. If I run PSC:\PhpstormProject\socialNetwork\view> and use php page/profile.php show me the error Could not open input file: page/profile.php. So what can I do to run files from every folder, because now I can only from the main project folder?

Setting up website with multiple directories in Homestead

I currently have my index.html file within a public_html folder and my PHP config files in a separate resource folder which is on the same level at the public_html folder. When setting up my Homestead.yaml file, I have to point to the exact directory where my index.html folder is. This is causing issues when I need to call a script from the other folder. Have I set up my folders wrong, or is my yaml file wrong?
Thanks!

MVC - CSS links

I am relatively new to this whole MVC structure for web apps.
Here is the structure of my project.
The file you see on the right of the picture is inside the 'Views' folder.
When I want to link a css file, why does the path have to be href="/css/stylePortfolio.css"
Why is it not href="../../public/css/stylePortfolio.css"?
What you are looking at, is the HTML that is sent to the users' browser. The browser does not know anything about the structure of your application. It simply reads that href link, and downloads the file from http://example.com<link>, where <link> is /css/main.css for example.
When configured correctly, the web root of your website is in your /public folder. That means, anything that a browser requests, is relative to your web root. Thus, if you want to link to a css file, you need to think of that link relatively to your projects web root, not relatively to your project root.
An example:
Say, you create a new project in /home/user/AwesomePhpProject.
Now, /home/user/AwesomePhpProject is called your project root.
In your project root, you create a directory, public. You configure that directory to be your web root, using VirtualHost (when using Apache) or the root directive (when using Nginx).
/home/user/AwesomePhpProject/public is now your web root.
When a browser requests /css/main.css, it will be directed to /css/main.css relative to your web root. In our case, that will be /home/user/AwesomePhpProject/public/css/main.css.
Most modern applications separate the project and web root, for security reasons.
As your index.php is inside the public folder, so all the views are loading in the public folder. That is why you should declare the CSS path from the public root. You can modify the path if necessary.
In this case, you can declare a global variable or constant your main controller with the path of your CSS folder
define('CSS_PATH', 'http://localhost/fab/public/css/');
Now use this like
<link rel="stylesheet" href="<?=CSS_PATH?>bootstrap.css">
It's because front-end links (like CSS and JS) are relative from current file you are in. And since your root is in public you have to specify URL from this directory (you can't link to any file in top level of root).
Why is it not href="../../public/css/stylePortfolio.css"?
Because entry point of your MVC is index.php from public folder. So all your css and js links should be relative to public folder

Route to page in webroot folder? - CakePHP

How can I define a route to a .php file in my webroot folder?
Thank you
Edit:
How can I render a file in the webroot folder from a controller? I need this because I am using Auth.
I'm guessing you're trying to password/Auth protect a file in the webroot folder. If so, you're on the wrong track. Files in the webroot are served as-is by default and are bypassing Cake entirely. Any file you put in the webroot is by definition "public". To protect it, you'll need to store it someplace else outside the webroot. You can then serve this file from a controller using the Media View. Your URL would look like, for example, /files/download/foo, which maps to FilesController::download('foo') via normal routes.

How to create a anchor link to different .php file?

I'm new to php and hope you can make me figure out whether I'm trying to do anything impossible.
I have two folders 'public' (root directory), and 'library' (all php files here), these folders are in same level of folder hierachy. my public/index.php is basically loading another php file (say aa.php) which is in 'library' folder on the loadup. Now I need to create a anchor link to file call bb.php which is also inside library folder.
I tried create anchor as follows
echo " my bb file
But I'm getting 404 error saying localhost/bb.php can not be accessed. I guess this is because bb.php file is not with in root directory and server is preventing direct access to this file.
Please help me to overcome this problem.
Thank you
If library/ and public/ are at the same level, the webserver will not be able to serve the files in library/. Typically, files in a library directory would be included by files in the public web folder.
If you need to use the bb.php directly, you will have to move it to public or a folder within public. And then from within public/bb.php you can include library files
/* public/bb.php */
include("/path/to/webroot/library/file.php");
Move bb.php into the folder "public".

Categories