Load a module and then controller by default in Kohana 2.3.4 - module

Working in Kohana 2.3.4, I need to load a module when I go to example.com.
In the routes.php file you can specify a default controller like:
$config['_default'] = 'welcome';
but that refers to the controllers within the main application.
Is there a way to load a module by default, and then specify the default controller to load within that module?

In 2.3.4 you need to specify which modules you are loading in your application/config/config.php. Once they're loaded you can use them in your routing just as you would your standard controllers.
Assuming within your module you had a controller named foo and a method named bar your default route would simply be:
$config['_default'] = 'foo/bar';
Example config from http://docs.kohanaphp.com/general/modules
// Paths are relative to the docroot, but absolute paths are also possible
// Use the MODPATH constant (?)
$config['modules'] = array
(
MODPATH.'acl',
MODPATH.'auth',
)
It's worth noting that the Kohana filesystem is cascading so duplicate controllers (and other files) in your application folder would override module controllers which in turn override the system controllers.
For more see: http://docs.kohanaphp.com/general/filesystem#cascading

Related

Localization of view without using #Localizer

I am using localization for view as given below.
<p>#Localizer["Use this area to provide additional information."]</p
I need to create a global resource file from where I can localize the string of view without using ViewModels folder in resource folder.
Resources/ViewModels/Account/RegisterViewModel.fr.resx
Is there any way to use localization of view without using IViewLocalizer or without using #Localizer in view?
here is how to do it :
on your resx file properties, add "PublicResXFileCodeGenerator" for Custom tool.
It will generate the "designer file".
You need to do it only for main language file.
After that, on your view in cshtml, you can use it like this :
//my resource file is named Welcome.resx
<h1>#Welcome.Title</h1>

How to have methods in common for several (partial) views

in my asp.net core web project i have two partial views that are displaying products. the first one shows them in a big layout, while the second one displays them in a smaller, regular layout.
both partial views need a method that composes a SEO-friendly url (using the product name and further information which are provided from the ViewModel). this method should somehow be accessible to the both views.
where can i place it inside of the asp.net core application? are there any particular conventions that must be followed?
#Html.Partial("ViewName")
Uses a view in current folder with this name. If none is found, searches the Shared folder
#Html.Partial("ViewName.cshtml")
A view with this name must be in the same folder
#Html.Partial("~/Views/Folder/ViewName.cshtml")
#Html.Partial("/Views/Folder/ViewName.cshtml")
Locate the view based on the application root. Paths that start with "/" or "~/" refer to the application root
#Html.Partial("../Account/LoginPartial.cshtml")
Locate the view using relative paths

Yii framework module layout issue

I am creating my first framework based project using YII framework. I have a main site and a module based backend to manage the site(CMS). First I used the same layout for both ends, but now I want two different layouts for front end and backend. I changed my module layout by adding a layouts folder to the module view file and I added “$controller->layout = 'main';” to the base module file of my module folder. Now the layout has been changed but when I logged in as a admin to the backend I cannot view any admin controller action, it means I am just a guest user. This issue is solved when I change my layout to the main site layout.
Please let me know if there is anything to do for this?
if the backend and frontend you created like module I think this will help:
$this->layoutPath = Yii::getPathOfAlias('(application.views.layouts or path/to/layouts)');
and in controllers of module just pasting layout name:
public $layout = 'login';

How to add javascript to YII correctly?

I want to create several javascript function that will be needed on different pages. Most will be relevant only to one page, but some to several. I know if I add general conversion functions, it would be a good idea to just create a new javascript file and put all these generic functions into that one file. Bringing me to my first question:
Where would you store the generic javascript file? In "protected"? Which subfolder?
Then, I need to address the placement of other javascript code.
If I have javascript that will only be used on one page, should I use this technique or should I stick to a similar approach as above?
The emphasis is on doing it correctly. I want to fall exactly in line with the yii framework.
store your generic javascript file in your_app/js folder
i.e js folder is at same level to protected.
if js is only used on one page than it will be better not to use generic file.
The best way to have you generic js code into /js/ or similar named folder under root of your app code. Personally I would separate my custom code files into one other subdirectory /js/custom/ and /js/vendors/ where in this vendor folder you can put ready js code such as jquery plugins etc.
Also don't forget to set this path to config file like this:
'components'=>array(
'clientScript' => array(
'coreScriptUrl' => 'path/to/js/lib/dir',
'enableJavaScript' => true,
),
),
where path/to/js/lib/dir is your final js folder name path

how to share pariail templates in different modules

for example, I hava a partial template named _header.php, I want to use it in both Post, Forum module, How can i write renderPartial(), to load this template.
placed your partial view to app layouts dir.
<?php
$this->renderPartial('//_header.php');
?>
absolute view within a module:
the view name starts with a single slash '/'. In this case, the view will be searched for under the currently active module's view path. If there is no active module, the view will be searched for under the application's view path.
absolute view within the application:
the view name starts with double slashes '//'. In this case, the view will be searched for under the application's view path. This syntax has been available since version 1.1.3.
reference getViewFile()