How to use the MODELS inside MODULES - yii2

I am new to yii2 and i want to learn yii2.
How to create modules and how to use Models inside the Modules.
I created controllers and views and also
i am able to access the controllers views like modules in modules/controller/action.
http://localhost:8082/countries/custom/greet
I tried and get the url working for controller and actions in yii2 but models how to use inside the modules for accessing the database data using models
can you help me out.
Thanks in advance

On the top of the Controller, you should add an use statement. E.g. use app\models\SomeModel;. After that you can access the model from the entire Controller by calling SomeModel::<<findStatement>>.
Alternatively you can call app\models\SomeModel::<<findStatement>> inside the code. That is, of course, if you have put the models in the right place under models folder in your yii folder.

Related

How this code upload file in django can run the html file?

The code is here
I am confused about the html file, it looks like it was never called but it can be run and when I change upload_form.html name to upload.html, it could be an error. So how come? and how to make the program can run upload_form.html file in another name file?
This is my first question, so sorry if my question makes you confused >.<
I wish I could understand the code
The code link you have attached is using one of Django's generic views CreateView. And Django follows some conventions to decide what template to use for the view. In the case of CreateView Django tries to find the template with the name of model used by your view in lowercase and the default template_name_suffix which is _form. In your case your model name is
model = Upload
So Django tries to find a template with the name upload_form.html. And if you wish to change the default template_name you can always override it like this.
class UploadView(CreateView):
model = Upload
template_name = 'upload.html'
Besides this, you can also override the get_template_names method as well, it is sometimes useful when you have to conditionally decide the name of the template i.e you are planning to use a different HTML file for different users.
Here is the Django docs link and another very useful ref about CBVs.

using react-router in Next.js environment

I am currently using next.js framework. Is it possible to route components out of /pages directory?
Would not like to use 'react-router' (because it'll be complicated to edit server.js). If it is inevitable I will but is there any other way?
im afraid this is not possible in nextjs. nextjs builds its route view pages folder. what you can do that wont ruin your project structure or URLs is to
add your components to the new repo.
create your pages folder based on your routes in pervious project.
add index.js in each pages folder.
and import the main component instead of actually moving it to pages folder, for example:
export { default } from './components/users';
this way you can drag and drop your existing structure and only add your route as pages folders.
notes to consider:
next default routing is case sensitive so be careful about your folder names if you want a work around for that you should use nextjs v12 create all pages to lower case and config your project to translate all routes to lower case.
you can have nested routes by adding nested folder:
pages
userslist
userdetail
index.js
this structure will create this route:
/userlist/userdetail
if you have components you dont want for user to be accessible do not put them in pages
if you have dynamic routes such as id in your route you can specify it by adding a folder in pages like [id] and redirect to it following this syntax
Router.push(`/sth/sth/${sth.id}`);
this configuration of redirects in nextjs might come in handy when you need to custom your links
i should also warn you migrating an existing project to nextjs requires a lot of work and a lot of changes to the project.

How to pass a JSON Schema to Angular CLI to generate custom components/forms

My team needs to generate various custom forms frequently. To automate the procedure, we are trying to find a way in which we can pass a JSON schema of the form we want to create to Angular CLI, and have it generate the files for the component with the basic stubbed form controls and buttons etc, which we can edit later on.
Can someone point us in the right direction?
Basically, something like
ng g c <my-form-component> [usual cli options here] [my json schema for my component]
I was reading about angular schematics, but wasn't sure if that is indeed what we need.

How to get list of controller in frontend from backend in Yii2 Advanced Template?

I use metadata class to retrieve data but just only in frontend or backend. i don't know how to get data across from backend to frontend. Thank you very much.
You can use components. It can work for an app (component folder in backend or frontend) or also you can create in common folder, so you could use for both. It's a good way to get maintainable code.
More info: http://www.bsourcecode.com/yiiframework2/how-to-create-custom-component-in-yii2-0-framework/

connecting a database from html by using angular

I am trying to write a sample web project that connects MySQL and executing querys such as creating a new user and deleting an existing user.
I wrote all the querys (prepared statements) in java classes.
Now I am trying to write the html file so clicking a button will call the statements that are written in the java classes.
How can I do that, without using JSF?
I want to use Angular but I don't understand how to make that connection between the html file and the java classes. Is is possible with angular?
If not, should I just use the regular JSF to do so?
Thanks