how to use gii generator with modules in yii framework? - yii

i am using the gii generator to create a module.
the issue is when i try to create a form or some model for that module...
i can't tell it to generate those files in that module... it only does it in the main application folders.
any ideas?
thanks.

To create a model for a specific module in yii you can give input to the model path text field like 'application.modules..models'.

Related

Need help on a minimal module for prestashop 1.7.x

I would like to write a module for prestashop 1.7.x for the first time !
It would be nice if someone could give me a hint how to start up.
I would like to use a php function with smarty call like {$page.page_name|test}
Hi #Hardy Thiergart and welcome to SO!
You can easily write your first PrestaShop module by following the tutorial here:
https://devdocs.prestashop.com/1.7/modules/creation/
Main steps:
Create a folder with your module's name
Create a PHP file with the same name
Make sure your PHP file contains at least the __construct(), install(), uninstall() and getContent() methods (the last one is required only if you allow users to 'Configure' this module)
You can then add additional methods for Hooks, including calls to your template files
Once ready, create a zip file of this folder, with your module's name
I hope this helps.
Here is a link to generate an empty Prestashop module with hooks, etc ... : https://validator.prestashop.com/auth/login
Regards

How to use models from models/ in layouts/main.php in yii 2.0 (basic template)

I have started to learn about Yii framework about day ago and I came up with the problem.
I have downloaded basic application template (so that you know the structure of my application).
I would like to use one of my classes's function from "models/" in the "views/layouts/main.php", however, I am not sure how I can access them from "main.php". I have searched around the internet and none of the solutions have helped me.
I've read about widget creation, so I can use it in "main.php" in this link - Yii - how to retrieve model data into a layout page?, but this does not provide my version of Yii as I coulnt not find protected folder and etc. So I was kind of confused.
Also read some other solution, but they did not help me as well.
What would you suggest me to do? Because I am currently have no clue about the solution. I am a newbiew in this framework, so, don't judge me hard :)
UPDATED: [SOLUTION]
// use statement on top of main.php like the other use statements
use app\models\Modelname;
// anywhere in the file
....
$myModel = new Modelname;
$myModel->myFunction();
...
// Or if it is a static function:
Modelname::myFunction();
This is how to access model files (classes) from folder models/ from for example views/layouts/main.php.
Here is the deal - view is actually only a "view". View should only represent some data, but not do something with this data. You don't want to have any logic in the view.
Anyway, if you want to show something from your model - you should pass this model through controller, which renders your view.
Controller will look like:
$model = new Device;
$this->render('index', array(
'model' => $model
));
Then you can use it in the view, normally to get some data from the model.
You could also get it directly in the view, but this is not good practice.
Here can you read some basics about models and best practices how to use them.
Update [Yii 1.x]
To use Model-Class specifically in your main.php, import it at the place you want to use it:
Yii::import('application.models.LoginForm');
After that you can normally use functions from your Model Class.
Update 2
Namespaces in Yii2:
use yii\models\LoginForm;
at the start of your main.php layout-File. Look also at the "Layouts" part here.

dynamic data display chart plotter in MVVM

I am trying to use d3 chart plotter in MVVM.
I am trying to use the code given by Ravi ( https://dynamicdatadisplay.codeplex.com/discussions/63633 ) in my project, but not quite sure how to use it properly.
It says "the property Linegraphs is not found in type ChartPlotter" when I try to use it in the XAML code.
What I did is add the LinegraphViewModel.cs to my project and make it the same namespace as my new project.
Anyone can advice me on what should I do in order to use the plotter successfully in my MVVM application?
Thank you so much!
Dynamic Data Display is a complex library with many different components. It not enough to pull a single class into your project. You need to reference the d3 .dll to your project to be able to use it's functionality, as well as using the dynamic data namespace in your xaml.
After adding a reference to the library to your project, you can set up the Dynamic Data Display namespace like this :
xmlns:dynamicDataDisplay="http://research.microsoft.com/DynamicDataDisplay/1.0"

How to refactor rails methods/classes using Eclipse?

I am in a situation where I need to clean code. I have to do followings
Rename class methods in cotrollers
Rename classes which are extending from other modules and helpers in the controller
Move classes into modules and break classes into sub classes
Rename some models
Apply formating to the code, e.g. alignment, spacing etc
Is there a way to achieve above using Eclipse ?
If not then is there any open source editors/plugins for rafactoring rails application ?
I think this would help you to refactor your code: https://github.com/bpo217/refacto

Yii - Using alternate view file in Yii User module

Is it possible to use a custom view file in a module (eg. user) in order to keep the module (3rd party) intact?
Somehow extend the module, with a views folder that holds my custom views.
The path to the module theme views should be
/{{your_app_name}}/themes/{{theme_name}}/views/user/
Copy all of the module views from the folder
/{{your_app_name}}/protected/modules/user/views
to the mentioned above folder and that will do the job. After that you could customize the views as you like.
Copy user module view files to <app>/themes/<current_theme>/views/user/. More general, customize module views using the folowing "formula": <app>/themes/<current_tehem>/views/<modules_name>/<controller_name>/<view_file_to_customize>.php
Use a theme. For a module named "user" and a view path of "profile/edit", create "/themes/flashy/user/views/profile/edit.php". You can also define a new layout in "/themes/flashy/layouts/column2.php". Then add to your configuration file in "protected/config":
return array(
// many settings...
'theme' => 'flashy',
For the module "user" you pointed out, unfortunately its controllers use absolute paths for their layouts (e.g. "//layouts/columns2") so AFAIK you can't define distinct layouts for the application and this module.
See also the official guide chapter on theming with Yii.
I disagree that in many help forums of the Internet, when someone asks abot theming a module, everyone suggests a path alias to the themes folder. I think this is wrong, because it implies modules to be splitted, and modules are supposed to be a black-box that can be used across projects. The advice given in such forums would only be valid if a theme is shared among several modules. If someone wants to "package" a theme inside a module, she can:
-add an init function to the controller of the module
-inside that init, use the class attribute layout and a path alias, like this, supose a module whose id is "Sample":
then you add, to SampleCOntroller.php:
public function init() {
//BELOW: it will use the layouts/main.php inside the module.
$this->layouts = "sample.views.layouts.main";
}