In yii framework, i want to render view file index.php in folder views look like this:
views/
--layouts/
--site/
index.php <!--run file index.php here-->
Somebody can tell me?
use
$this->render('index');
in the required action of your Site Controller
If you want to pass any variables to your index.php file then you can send it as an array in the second argument of your render() method like
$this->render('index',array('name'=>'tion'));
then you can use it in your index.php like
$name
As I know you can not render view file outside the "views" directory.
Try to
$this->render('//index')
Related
I have a Nuxt.js app with an .htaccess file.
The problem is that when I execute nuxt generate in the terminal, my .htaccess file disappears. What can I do to include my .htaccess file when I execute nuxt generate?
You could put your .htaccess file into the /static directory, more info on that in the doc.
That way, you will have direct access to it once pushed to production.
Otherwise, you can also use this approach if you need something more customizable.
I am trying to include a header file in my _Layout.cshtml page in asp.net core MVC application. The header.cshtml is located under root folder under wwwroot\inetpub, not under ~\Views\Shared\ , ie. \include\header.cshtml. I have tried to use #Html.Partial("/include/header"), #Html.Partial("/include/header.cshtml"), but I get error for "InvalidOperationException: The partial view '/include/header' was not found. The following locations were searched: /include/header". Please advise.
Use relative paths, like this:
#Html.Partial("../../wwwroot/include/header")
Here is the directory structure:
I am having trouble with serving a html file which is inside a subdirectory inside public folder.
My directory structure looks like:
public/
HTML/
index.html
index.js
I want to serve the index.html for the root route.
This doesn't work:
app.use('/',express.static(path.join(__dirname,'public')));
According to the docs, this should be enough:
app.use(express.static('public'))
It also gives you such example
http://localhost:3000/images/kitten.jpg
http://localhost:3000/css/style.css
http://localhost:3000/js/app.js
http://localhost:3000/images/bg.png
http://localhost:3000/hello.html
It doesn't go much further other than explaining how you can set up multiple public directories. Anyway, it has worked for me in my projects.
Perhaps you need to state directly app.use(express.static('html')) or app.use(express.static('public/html')). Let me know what works for you.
I have a simple question but I just can't find a straightforward answer anywhere.
I'm not very familiar with apache .htaccess and now I should deploy a ZF2 app on a web host that doesn't allow me to change the website root folder.
I have a standard project structure so my index.php file is located inside the /public folder, like this:
www.mydomain.com
root/ <--- I can't set root to /public folder
/config
...
/module
...
/public
.htaccess
index.php
...
/vendor
...
...
This is from the ZF2 skeleton app.
Please I need a workaround, I'm sure this is a pretty common problem that many ZF2 developers already tackled. I think I should add a .htaccess file to /root but I don't know how to write one that would work in this case.
As always any help is much appreciated,
Dan
In order to make this work you have to take everything from the /public folder and put it inside your web root. The file index.php from the skeleton app must be edited to take account of its new position.
First remove the line:
chdir(dirname(__DIR__));
Because its purpose is to set the current directory to the web root which we are already inside.
Second you have to either:
Replace the line require 'init_autoloader.php' with require 'vendor/autoload.php' (if using composer).
OR
Inside your .htaccess set the ZF2_PATH env variable to where zf2 is installed on your server:
#First line of your .htaccess
SetEnv ZF2_PATH path/to/zf2
Now it should be working.
Make it better
With the above setup you'll have to put all your public folders inside the web root. If you, like me, don't like that just continue reading.
You can put your public folders (e.g., /js, /css) inside /public (index.php and .htaccess still need to be in the root) by simply telling zf2 your new base_path. This is what is used by the basePath() view helper inside your view scripts. You simply need to add the following to your config:
'view_manager' => array(
'base_path' => './public',
),
And the basePath() view helper will output the correct urls.
Make it even better
The last problem with this setup is that your app files are accessible from the web. To fix this I put everything I want to hide inside the /private folder. You end up with a project structure similar to this:
/root
/private
/config
/data
/module
/vendor
.htaccess <-- You have to create this one
composer.json
composer.lock <-- Created by composer after install
composer.phar
/public
/css
/js
.htaccess
index.php
Inside the /private folder you have to create a new .htaccess file and put this line inside it:
Deny from all
This makes everything inside the folder not accessible from the web.
With this change you have broken your app. Infact inside /private/config/application.config.php you have to adjust the module_paths config:
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
),
You have to prepend /private to the paths:
'module_listener_options' => array(
'module_paths' => array(
'./private/module',
'./private/vendor',
),
),
This will make your app run once again. Now you can deploy your ZF2 apps to shared web hosts and retain a clean project structure.
Lets say I create a subdomain : http://subdomain.mydomain.com/
That was originally at this url : http://mydomain.com/subfolder/folder/
How would I fix pathing issues for
../ on http://subdomain.mydomain.com/
without a replacing code in .htaccess? is it possible?
let say I have some masive structure like this.
Now in this case I want to do is in the css -> style -> loginCSS I have a css file named as login and I want to take that
ca_grain_texture.jpg and set it as a background of my login.html file so we see that our html files are in the main directory
and also our css folder is in main directory
so if i want to grab the grain jpg file from my login.css file. I have to do somthing like this.
e.g
body{
background-image: url(../../../images/cs_grain_texture.jpg);
}
on writing ../ everytime it will jump one folder back similar to cd/ in command shell.
../ means it will go to loginCSS folder.
../../ means style folder.
../../../ means css which is the main directory.
I hope it helps understanding I understood this way and hope it clears your view.