Change certain controllers inside of yii - yii

So I want my yii framework application to have its User control handling the login and all of that inside a folder named Backoffice.I haven't tried this yet because I know I will brake the website.
So my question is how to tell yii that the files are located under different directories

You can set a path in config/main file. For example
'yiiPath' => dirname (FILE). '/../../framework/yii.php',
or
'import' => array(
'application.models.',
'application.components.',
'application.modules.user.models.',
'application.components.',
'application.modules.role.models.',
'application.modules.profile.models.',
'packages.solr.',
'application.modules.registration.models.',
),

Related

How to define the location of ViewComponent views during startup in a .net Core application?

I want to move the views out of the components folder under Pages into their own folder. Does this have to be defined in the startup? How is it defined?
For example:
The views are currently under: /Pages/Share/Components
I want to put them under: /Components
For configuring the custom search location, you could try code below:
services.Configure<RazorViewEngineOptions>(o =>
{
o.ViewLocationFormats.Add("/{0}" + RazorViewEngine.ViewExtension);
});
And then the project structure for Components like
Project
Components
View Component Name
View Name

Add CSS in a confide laravel web page

I got some code of Laravel where confide (https://github.com/Zizaco/confide) is used. Now I would like to add CSS in these Web Pages of Laravel.
Can anyone say how can I do that ??
Unless I am mistaken I'm pretty sure the question the poster was trying to ask is how to style the forms that reside outside of the app\viewsfolder. The forms confide uses by default are in the \vendor\zizaco\confide\src\views folder.
You can change the default forms and use custom ones by editing the config.php and style them like any other view.
Change this
*\vendor\zizaco\confide\src\config\config.php
'login_form' => 'confide::login',
'signup_form' => 'confide::signup',
'forgot_password_form' => 'confide::forgot_password',
'reset_password_form' => 'confide::reset_password',
To this
*\vendor\zizaco\confide\src\config\config.php
'login_form' => 'user.login',
'signup_form' => 'user.register',
'forgot_password_form' => 'user.password',
'reset_password_form' => 'user.reset',
I think you misunderstood what confide is or how laravel works.
Confide is a package to manage the authentication process in your website it has nothing to do with the front-end design of your website. It serves the back end operations to authenticate a model.
You must first pass the model through a controller and in to a view.
After that you can use blade templating to present the models and their attributes
and you can use whatever styling you want in your views.
Those are basic principles of the MVC design pattern if you don't understand what I'm trying to explain to you should read the laravel documentation

switch off resposive css for yii for a module [duplicate]

This question already has answers here:
Preventing a specific CSS file from getting loaded in Yii
(2 answers)
Closed 9 years ago.
hi i'm running a site on YII. which has two module user and admin.
but my config file has bootstrap pre load including responsive css. I want responsive feature for user module only.
i don't want responsive CSS to load in my admin module. is there any way i can unload it only for admin module by doing something on admin layout file?
i have tried
$responsiveCss = false
but it turns off responsive feature for the whole site.
i want it only for admin module.
thanks
Do like this on protected/config/main.php,
'components' => array(
'bootstrap' => array(
'class' => 'ext.bootstrap.components.Bootstrap',
'responsiveCss' => !(isset(Yii::app()->controller->module->id) and (Yii::app()->controller->module->id == 'admin' )),
),
---
),
It will make responsive css to all other expert 'admin' module.

Yii - Route without Controller

I'm using an existing upload script that require user authentication. However since I did not write the upload script, it's nearly impossible for me to read the source code and make it into separate view and controller file. The problem is if the script does not get routed by the bootstrap file, it has no access to the Yii variable and thus user log in information.
I tried to set a custom session variable when the user login. However it work barely because my custom session would expire before the session set by Yii.
Any help would be appreciated.
Because of the way the script is written I've only been able to find one way of doing this. It will involve re-writing some elements of the script.
Save the filemanager in protected/vendors.
You need a controller to handle the routing of the request. This will also give you the access control that you need. Call it FileUpload and create it where you normally create controllers in your project. Right at the start of the controller, before the class is declared, import the fileUpload files from it's previously saved location; Yii::import('application.vendors.*');
You need an action to handle the incoming request. Call this actionIndex. Give it the following code.
public function actionIndex() {
//Start capturing the output from the script
ob_start();
require_once('filemanager/dialog.php');
//Finish capturing output, and save to a variable
$output = ob_end_clean();
$this->render('index', array('output' => $output));
}
Then you need a view file. Call it 'output.php' and it just contains one line; <?php echo $output; ?>
This will render the html generated by the script, and hopefully contain it within your existing template.
Your first problem is that the script sends headers which aren't discarded by ob_start. You will need to delete these from the script. It also starts a session, which will throw an error 'Session already started', which can be cured by changing the first line of config.php to
if(!isset($_SESSION))
{
session_start();
}
Your next problem will be that none of the scripts and stylesheets are loaded, because the vendor hasn't used relative filepaths, and also because you've just deleted the headers. You will need to re-write lots of the script to include the necessary files. Fortunately, you now have access to Yii functions, so can use the asset manager to publish all the js and css files needed by the script.
Your final (hopefully!) problem will be the urls used by the script page. Currently they are all pointing to files within the script. You will need to rewrite these to use Yii routing. Fortunately, inside the main file dialog.php you should have access to all the normal Yii functions, so you can set $baseUrl as $this->createUrl() etc. If you need to add extra actions to the controller you can follow the pattern above to call other files, like the upload.php file in the script.
Hope that all works for you!
You are using a Framework with mvc pattern so controllers are preferred way to route requests .As per your problem i would suggest you to use htaccess file to do the routing to the required file and handle other files by Yii
copy code from existing source to new Yii Controler/Action ... done :D

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