phalcon partial for multiple module - phalcon

$this->partial('partials/header');
This function for phalcon single module.
What can i do for this multiple-modules.
Can't work for this modules design.
I Went to use in multiple-modules design.
$this->partial('partials/header');
Please tell me
module1/
views/
about/ <- AboutController
index/ <- IndexController
index.phtml
module2/
views/
about/ <- AboutController
index/ <- IndexController
index.phtml
module3/
views/
about/ <- AboutController
index/ <- IndexController
index.phtml
partials/ <- ()Store partials
header.phtml
footer.phtml

Just go back few directories. For example if you want to include header.phtml from module3 in module1 (you may need to modify for your path):
$this->partial('../../module3/views/partials/header');

Better create seperate view directory which will be used in every module. Add it to view compomnent and then you shouldn't need to go to this directory.

Related

How to Serving static files with express if it is inside a subdirectory

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.

Yii2 Custom / Shorter Namespace

I have a nested 'mail' module in my yii2 (basic template) at this location:
#app/modules/admin/modules/mail
How do I create shorter namespaces in all of the modules files. So instead of this namespace in my controller files:
namespace app\modules\admin\modules\mail\controllers;
I could just have:
namespace mail/controllers;
If I ever move the module folder, I wouldn't have to go and manually change the namespace in every single file (also they're just long).
The docs actually recommend this here http://www.yiiframework.com/doc-2.0/guide-structure-modules.html#nested-modules where it says "you should consider using a shorter namespace here!"
But how do you accomplish this?
you must set alias to directory at bootstrap to custom namespace.
First, create a bootstrap.php in config/ folder:
//bootstrap.php
Yii::setAlias('mail', dirname(dirname(__DIR__)) . '/modules/admin/modules/mail');
Add run bootstrap.php at init app.
Edit file web/index.php, add this line after require Yii.php
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
//Add after require Yii.php
require(__DIR__ . '/../config/bootstrap.php');
$config = require(__DIR__ . '/../config/web.php');
(new yii\web\Application($config))->run();
Now you can set namespace for controllers in mail module is mail/controllers.
Hope it helpful.

Deploy on Shared Web Host

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.

Render views file in yii framework

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')

How to use grunt-contrib-copy to copy to root AND change directory structure

I have an express app with my dev views in /assets/views. I figure I need to separate development and production views because in production I'll be editing the HTML when I used grunt-contrib-usemin to concat/uglify scripts.
So here's the problem. My current tree:
assets/views
├── 404.html
├── index.html
├── layout.html
├── question_ask.html
└── question_display.html
Ideally, I want my production-ready views to live on the same level as assets. Using grunt-contrib-copy, it seems to copy the whole tree. I currently am putting it into public since I'm not sure how to set my dest to the root of the project.
copy: {
views: {
src: ['assets/views/*.html'],
dest: 'public/'
}
So there are a few questions here:
Is it bad practice to have dev views and production views? If so, is there another way of producing a view that has references to concat/uglified scripts?
How the heck can I use grunt-contrib-copy to copy to the root of my project? I don't want assets/views obviously, I just want a views/* folder that has the contents of what's in assets/views/*.
Thanks!
You need to specify the flatten option which will remove the directory structure from the destination path. See my answer here: Copy all files from directory to another with Grunt.js copy