How can I use multi controller in one page?
I used:
Yii::$app->controller->action();
How can I access another controllers?
You can create a new class and put your actions in the calass, after that create a object in the page you want to use it.
for example:
$object = new fontend\controllers\NewClassName;
$object -> YourAction();
Related
I made a column to my 'users' table called 'approved' which is boolean where 1=true and 0=false. What I want to do in my view is that I only want to show the data of the user with the 0/false value. What are the steps I need to make to achieve this? I'm really new to Laravel or rather at Web Development in general.
$datas=User::where('approved','0')->get();
Now in your blade use ......
#foreach($datas as $data)
#endforeach
There are so many ways to do it. First is you can directly use where clause for it like this one.
User::where('approved', 0)->get();
Second is to use local scope. In your model you will put this one.
public function scopeApprovedUser($query) {
return $query->where('approved', 0);
}
and call it to your controller like this.
User::approveduser();
I wanna pass a variable from userscontroller to salescontroller in my project in CakePHP 3 and use it in salescontroller .But I don`t wanna to redirect from an action to another one (not passing variables in url) how can I do it?
Edit : to pass data between controller, you can use Session,
$session = $this->request->session();
how to read and write read link bnelow
http://book.cakephp.org/3.0/en/development/sessions.html
https://stackoverflow.com/questions/30568653/how-to-read-and-write-session-in-cakephp-3-0
I am new in yii2 and i am using wbraganca/yii2-dynamicform widget in my view. My question is that I have to use more than two dynamic form in a single view. For single dynamic widget it works fine while saving from controller but others are saving just the last data of dynamic widget, while inspecting the post data in network array index for others except first dynamic form are not increasing (there index is only zero). Would you please suggest how should I have to do. How can I use multiple dynamic-form widget in single view. Thank you in advance.
I believe the problem must be in your view. You should ensure that each control has a unique name and then loop through the post variables in the controller.
<?= $form->field($modelx, "[{$i}]MyVariableName", ['labelOptions' => ['label' => false]])->textInput(['name' =>'myClassNameHere'."{$block}[$i][MyVariableName]"]) ?>
See the 'name' option in the code above. It gives a unique name to each field. Here the $block variable is a unique code I append to each widgetItem class in the DynamicFormWidget.
If I now look at my POST data, I see something like the following:
myClassNameHere0[0][MyVariableName]:1
myClassNameHere1[0][MyVariableName]:11
If this does not help - post a simply example that you cannot get working and I will have a look at it.
I'm working with flash builder (flex) and wanna assign value to a variable in a view and use that variable in other views.
but the problem is when i define for example an array in one view it's undefined in other views and i cant use value of that variable in my functions.
whats the solution?
You have to create a reference the view which has your variable in the other view .
Make sure that your variable is public and bindable.
My controller returns results in a Array like this:
render (template: 'show' , model: [changes: changes])
Show is a default action and changes is an Array created with a query(createCriteria).
How can I make pagination in my index.gsp page which is displaying results in a HTMl div?
My problem:
Controller:
def list() {
[terminHistorie: changes, terminHistorieCount: changes.size()]
}
gsp:
<g:paginate controller="terminHistorie" action="list" total="${terminHistorieCount}"/>
Error: Tag [paginate] is missing required attribute [total] at C:/Users/matejb/Documents/NetBeansProjects/gutmann/grails-app/views/terminHistorie/index.gsp:309
The way pagination works is you first need to create a view using paginate tag, then on your show action you need to slice your changes. Meaning that the view will send the offset and max parameter and your createCriteria will query the database only for those data. Take a look at this page and then here to see how you can pass max and offset into your createCriteria method.
To see an example, see this page or create a new application with one simple domain and generate scaffolding for it. Grails will generate a paginated result for you.
Btw, if you are using ajax you might want to use remote paginate plugin.