How to render variable of if-else block in Yii - yii

I am new in Yii.I have if-else block in an action and i need to render the value of the variable. But its showing error "Undefined variable". How it can be done??
Please help. Thanks in advance!!

First declare the variable before the if else statement,
Then change that variable's value as per your if else statment
Then Pass that variable to render. Suppose your variable name is $model, then your render code would be
$this->render('index.php', array('model' => $model));
In your view, you can access that variable with $model variable name.

Related

Vue get sender element with other parameter

In my VueJs app i have a html part like this
<MyAwesomeComponent #change="onChangeValue" class="component" />
and in the method i have
onChangeValue: function (event)
{
//here i can access succesfully to event.sender
}
the question is: how is possibile to have custom parameter inside onChangeValue function?
i've tried to add parameter but i only get undefined and null value
any suggestion?
In your onChangeValue function, you will create an event like $emit('nameOfEvent',yourDataToPass) . nameOfEvent will be usefull to get your event in the upper component like #nameOfEvent="yourFunction($event)" . And yourDataToPass will be one of your data in DATA(){mydata;} like this.mydata
In your child component, you can call $emit('change',customArg)

How to set default title on react navigation if the string is empty?

React Navigation uses the default parameter in "navigation.getParam('Title', 'Default Title')" if it can't find a parameter named 'Title'. But I have my code set up so that the parameter title refers to one of the props, which can either be the title of the page, or an empty string. (It never becomes undefined). How do I set the title to the default parameter if 'Title' is an empty string, instead of being undefined?
For some context, this happens because my parameter 'Title' is being set from the props from the redux store, which can sometimes take a while to get populated. I have measures to prevent the screen from loading until it gets populated, but I still want to have a fall back in case something goes wrong.
If the string must be undefined to show de Default Title, why can't you add a inline condition?
props.title === ''? undefined : props.title

Vue.js cannot read property of null/undefined before it's assigned

I have a property that comes from axios.get.
It's defined in my data as null (or '' or [])
The axios call is in a created hook.
When the app is first loaded the console fills up with
Error in render: "TypeError: Cannot read property 'service' of null"
Of course, it actually shows the information correctly on the webpage, because service is not null, but this error is apparently thrown before axios fetches the data.
What's the best approach here?
You have to specify your data as an empty object to avoid this error:
data: {
your_object: {}
}
Where your_object is that object that will have service property when data is loaded.
(From my assumption, in axios.get promise function you do something like that:
your_object.service = result.data;
)
You can either initialize the data field with an empty, non null, value or guard the access using a v-if before the template using the property.
add a v-if in the element where you are using the data service.
Here is an example:
<label v-if="service">{{service}}</label>
or use the parent if it's an array like this:
<label v-if="parent">{{parent.service}}</label>

Aurelia force dirty checking without getter

I'm trying to conditionally add a class to an element based on the result of a function call, but Aurelia won't re-run the function when its parameters change. Normally I'd use a getter to force dirty checking but since my function needs arguments that isn't possible.
The function in question looks like this:
isVisible (item, filters) {
// If there are no filters selected, or at least one of the item's tag names are inside the filters the item is considered visible
return (!filters.length || (filters.length && item.tags.some(tag => {
return filters.indexOf(tag.name) !== -1 ? true : false;
})));
}
And in case it's not obvious it takes an item and an array of strings (filters) and then checks if any of item.tags[].name is inside the array of filters.
It is used in my view like so:
<item repeat.for="item of items" item.bind="item" class="${isVisible(item, filters) ? 'show' : 'hide'}"></item>
I also tried just adding the code directly to the view which I assume will force Aurelia to re-calculate things but when adding the entirety of the function's code to the view (inside a ${code here}) I get parse error unexpected >.
Your above example is enough to have it re-evaluated whenever filters changed. However, if you mutate filters, Aurelia won't be able to pick up the change as array observation is not automatic for performance reason. You can work around this by using immutable instances of filters or additionally observe filters length like the following:
<item repeat.for="item of items"
item.bind="item"
class="${isVisible(item, filters, filters.length) ? 'show' : 'hide'></item>

Aurelia: Programmatically changing reference value doesn't change model

We have a situation where we utilize a component in multiple web pages (a note editor). This note editor takes a value from an input element on the page and places that value into a component where the user can modify it. The user types in the note editor and clicks Submit. The note editor component then passes the new value back to the input on the original page.
We are using the "ref" to pass the value back and forth. Everything works fine except that the model doesn't update when we set the value of the ref from the note editor component. We find we need to type once in order for it update the model. Here is a simple Gist to illustrate our example:
This is just a simple example of programmatically setting the ref's value.
Note how "The value of my input is" stays as "Hello" but the input field changes to "Value Changed!!!!" when you press the button.
https://gist.run/?id=fab025d6b99a93f9951b1a6e20efeb5e
A few things to note:
1) We'd like to use Aurelia's "ref" instead of an "id" or "name".
2) We've tried to pass the model instead of the "ref". We can get the value of the model successfully and put it in the note editor, but the model doesn't update when we pass it back.
UPDATE:
We have an answer (thanks!). Here is the code we tried to pass the model (so we wouldn't even need to use the ref). This failed for us.
Here is the View of the page.html
<TextArea value.bind="main.vAffectedClients" style="width:94%;" class="editfld" type="text" rows="6"></TextArea>
<input class="butn xxsBtn" type="button" value="..." click.trigger="OpenNoteDivAurelia(main.vAffectedClients)" />
Here is the View-Model of the page.js
import {NoteEditor} from './SmallDivs/note-editor';
...
#inject(NoteEditor, ...)
export class PageName {
constructor(NoteEditor, ...)
{
this.note = NoteEditor;
...
}
OpenNoteDivAurelia(myTargetFld)
{
this.note.targetFld = myTargetFld;
this.note.vHidTextArea.value = myTargetFld;
this.note.show();
}
}
This part opens our component (note-editor) and successfully places the targetFld value inot our TextArea in the component.
Here is the View-Model when placing the value BACK to page.js/page.html
CloseNote(populateFld)
{
if (populateFld)
{
//This is the line that doesn't seem to work
this.targetFld = vHidTextArea.value;
}
this.isVisible = false;
}
This last function "CloseNote" is the one that doesn't work. The model (which we believe is pointed at this.targetFld) does not get the value of the textarea. It does not error, it simply does not do anything.
The events that Aurelia attaches to be notified of an input changing don't fire when you programmatically set the value property on an input. It's simple enough to fire one of these events yourself, though.
export class App {
mymodel = {"test":"Hello"};
changeValByRef(myinput)
{
myinput.value = "Value Changed!!!!";
myinput.dispatchEvent(new Event('change'));
}
}
You actually don't need to pass the ref in to the function, anytime you use the ref attribute, a property is added to your VM w/the name you use in the ref attribute. So the above example could have been accomplished using this.myinput instead of the passed in object, since they're the same.
Here's a working example: https://gist.run/?id=7f96df1217ac2104de1b8595c4ae0447
I'd be interested to look at your code where you're having issues passing the model around. I could probably help you figure out what's going wrong so you don't need to use ref to accomplish something like this.