I am new to API.ai. I want to functionality such that when a Bot response says something to select from various options, user will select one of the options.
e.g.,
If Bot response says 'Which type of websites do you want to build?'
Select one of the given options.
1) Static
2) Dynamic
3) One page.
I have gone though various helps from the documentation , but I do not know how to set this up.
Please help.
This is your answer :
$arr = [];
if ($var == "Which type of websites do you want to build?") {
$arr[] = "Static";
$arr[] = "Dynamic";
$arr[] = "One page";
} else {
$arr[] = "option1";
$arr[] = "option1";
$arr[] = "option1";
}
Html Code:
<select name="website">
<?php
foreach ($arr as $key => $value) {
?>
<option value="<?php echo $value ?>"><?php echo $value; ?></option>
<?php
}
?>
</select>
Let me know if you require more details.
Related
I heard building Data in View is not very good, but anyway, i am wondering why its not working:
View
<?php $form = ActiveForm::begin();
$alleSpieler = \common\models\Spieler::find()->all();
if ($alleSpieler) {
unset($types);
foreach ($alleSpieler as $value) {
$types[$value->id] = $value->email . ' ' . $value->vorname . ' ' . $value->nachname;
}
}
echo $form->field($model, 'spielerId')->dropDownList($types, 'prompt'=>'Spieler manuell hinzufügen']);
ActiveForm::end();
?>
<?= AnmeldungDurchfuehrung2::widget(['durchfuehrungId' => $model->id, 'spielerId' => $model->spielerId]) ?>
Model
public $spielerId;
But spielerId ist not set in my Case. If i, for example, set 'spielerId' => 1120 in the widget call, it is working. But if i want the value from the dropdownlist, the action is saying that spielerId is missing. I am newbie and perhaps i forgot something? Thank you!
You must add $spielerId; in validation array in your model, som like this:
public function rules()
{
return [
[['spielerId'], 'integer'], //type of atribute value
[['spielerId'], 'required'], //if need
/*... other atributes ...*/
];
}
for more detail check the documentation.
okay now i know what i need:
echo $form->field($model, 'spielerId')->dropDownList($types,['prompt'=>'Waehlen Sie einen Spieler']);
echo Html::submitButton('Auswählen', ['class' => 'btn btn-primary']);
This is my Dropdown.
I need something like:
<?php if(!empty($_GET['spielerId'])) {
echo AnmeldungDurchfuehrung2::widget(['durchfuehrungId' => $model->id, 'spielerId' => $_GET['subject']]); }?>
I have a post type called 'faq' and taxonomy called 'type' within my template and a few taxonomy terms created "Design", "Print", "Display" etc.
The idea I am trying to implement is to display only the posts that belong to assigned taxonomies (types) without duplication. Each post may be assigned to multiple taxonomies (types).
My current code works fine as long as the post have got only one taxonomy assigned to it. As soon as I assign more then one taxonomy it shows duplicate posts like this:
Question 6
Question 5
Question 1
Question 1
Here is my current code:
<?php
$post_type = 'faq';
$tax = 'type';
$faq_types = get_field('types');
$filtered = array();
$termargs = array( 'include' => $faq_types );
$tax_terms = get_terms($tax, $termargs);
if ($tax_terms) {
$i = 1;
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
$tax => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="accordion-section">
<a class="accordion-section-title" href="#accordion-<?php echo $i; ?>"><i class="fa fa-chevron-right"></i> <?php the_title(); ?></a>
<div id="accordion-<?php echo $i; ?>" class="accordion-section-content">
<?php the_content(); ?>
</div>
</div>
<?php
$i++;
endwhile;
}
wp_reset_query();
}
}
?>
I'd really appreciate any help with getting this working the way I need.
Your current loop is saying "For each taxonomy term, show all posts associated with that term", so of course it will duplicate if there is one post associated with multiple terms. Take your query out of the foreach loop and use a single tax query with an array of terms:
$args = array(
'post_type' => $post_type,
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term_slugs,
),
),
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
EDIT
By the way, you'll need to convert your array of term objects to an array of term slugs for this to work properly:
$term_slugs = array();
foreach( $tax_terms as $term ) {
$terms_slugs[] = $term->slug;
}
In a ZF2 project I am developing, I would like to create a shell around the echo $this->content; statement in layout.phtml that would allow conditional formatting of the main content area. Specifically, I want to put the content into a column that is 75% wide and include some “ornamental” elements in a column that is 25% wide for most of the pages. However, I want to change to a single column for pages that need more space. My project is a CMS in which each page has an attribute that can tell either the view or the controller whether the page should be normal or wide. I have considered a number of methods for achieving what I’m after.
My “conditional formatting in the layout view” might look like this:
// module/Application/view/layout/layout.phtml:
//...
if ($templateNormal) {
echo "<div class='col-md-9'>";
} else {
echo "<div class='col-md-12'>";
}
echo $this->content;
if ($templateNormal) {
echo "</div>";
echo "<div class='col-md-3'>";
//... ornamentation
echo "</div>";
} else {
echo "</div>";
}
//...
While the above-method could work, for pure MVC I don’t think there is supposed to be any decision-making going on in the layout view.
My “conditional formatting in partial views” could look like this:
// module/Application/view/layout/layout.phtml:
//...
echo $this->partial('partial/open-shell.phtml');
echo $this->content;
echo $this->partial('partial/close-shell.phtml');
//...
// module/Application/view/partial/open-shell.phtml:
if ($templateNormal) {
echo "<div class='col-md-9'>";
} else {
echo "<div class='col-md-12'>";
}
// module/Application/view/partial/close-shell.phtml:
if ($templateNormal) {
echo "</div>";
echo "<div class='col-md-3'>";
//... ornamentation
echo "</div>";
} else {
echo "</div>";
}
Here the decision-making is taken out of the layout view, but it is simply put into other views so it's still in the view package and still not pure MVC.
In my “conditional formatting in the controller” solution, a pair of html script strings are developed in a controller function, and then passed on to the view. It might look like this:
// module/Application/view/layout/layout.phtml:
//...
echo $this->open-shell-script';
echo $this->content;
echo $this->close-shell-script';
//...
// some controller function:
//...
if ($templateNormal) {
$open-shell-script = "<div class='col-md-9'>";
$close-shell-script = "</div>";
$close-shell-script = "<div class='col-md-3'>";
$close-shell-script .= //... ornamentation
$close-shell-script .= "</div>";
} else {
$open-shell-script = "<div class='col-md-12'>";
$close-shell-script = "</div>";
}
//...
In this method, the decision-making is done in the controller where I assume it should be, but it seems odd to be writing html there.
Any comments or suggestions?
create two layout and in init() method of Module.php decide which layout should use .
public function init(ModuleManager $moduleManager) {
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
// This event will only be fired when an ActionController under the MyModule namespace is dispatched.
$controller = $e->getTarget();
$controller->layout(" your chose layout ");
}
}
There are many ways to accomplish this. This is one method and the logic lives in the controller:
controller
public function yourSampleAction()
{
// assign variables as usual to this view model
$viewModel = new ViewModel(array(
//vars
);
// this will be the "wrapper" and can be single, double column or anything else.
$wrapperViewModel = new ViewModel();
$wrapperViewModel->addChild($viewModel, 'innerContent');
// use this line when you want one column
$wrapperViewModel->setTemplate('path/to/your/single-column-wrapper.phtml');
// when this line you want two columns
$wrapperViewModel->setTemplate('path/to/your/two-column-wrapper.phtml');
return $wrapperViewModel;
}
two-column-wrapper.phtml
<div class='col-md-9'>
<?php echo $innerConntent; ?>
</div>
<div class='col-md-3'>
<!--- something else in here? -->
</div>
single-column-wrapper.phtml
<div class='col-md-12'>
<?php echo $innerConntent; ?>
</div>
Instead of setting different templates, you can adjust the Bootstrap Twitter classes by making the necessary classes dependent on a layout variable. You can use the logic in your controllers action to pass variables directly to the layout (not the view) like so:
$this->layout()->setVariables
(
array
(
'layoutVar1' => 75,
'someColClass' => ($someSwitch ? 'col-md-9':'col-md-12' ),
'layoutVar1' => 75,
)
);
and then just access these variables in the Layout as you would variables sent to the View. You don't have to even prepend them with "layout", they won't clash.
I'm currently writing an application in Yii in which i want to create a search box in the header (either in the navigation menu or just above it). This search box should be able to be accessed from every part of the site, and it should be able to search on different columns of different tables.
I have no idea on how to do this, and almost all posts on the web about it involves using the grid-view, or an extension (I'd like to create the code without an extension if that's possible).
Do you have an idea to how the search code should look (what i should put in which controller etc.)?
-- EDIT --
I still don't know how to do this but I will show you what I have at the moment anyway. It is not much and it is pretty obvious where i am missing some code.
/view/layout/main.php:
<?php echo CHtml::form(Yii::app()->createUrl('product/search'), 'get') ?>
<?php echo CHtml::textField('search_key','',array('placeholder' => 'Search')); ?>
<?php echo CHtml::submitButton('Go'); ?>
<?php echo CHtml::endForm() ?>
/view/product/search.php:
//Not sure by any means what to write here, but I'll like a list view populated with the search results
/controllers/productController.php
/**
* Search through model.
*/
public function actionSearch()
{
if(isset($_GET['search_key'])){
$search = $_GET['search_key'];
$model->name = $search;
}
$this -> render('search', array(
'model' => $model,
));
}
/models/Product.php
/**
* Retrieves a list of models based on the current search/filter conditions.
* #return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('name',$this->name,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
You can perform like this:
Find #mainmeu in /protected/views/layout/main.php
<div id="mainmenu">
<div style="width: 80%;float: right">
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'home', 'url'=>array('/site/index')),
array('label'=>'about', 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>'contact', 'url'=>array('/site/contact')),
),
)); ?>
</div>
<div style='float: left;direction: rtl; color: #ffffff; margin: 5px 0 0 5px; font-size: 13px'>
<?php echo CHtml::form(Yii::app()->createUrl('product/search'),'get') ?>
<?php echo CHtml::textField('search_key', 'search') ?>
<?php echo CHtml::submitButton(); ?>
<?php echo CHtml::endForm() ?>
</div>
</div><!-- mainmenu -->
Edit:
/models/Product.php:
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('name',$this->name,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/controllers/productController.php -> actionSearch():
public function actionSearch()
{
$model = new Product('search');
$model->unsetAttributes();
if(isset($_GET['search_key']))
$model->name = $_GET['search_key'];
$this -> render('search', array(
'model' => $model,
));
}
/view/product/search.php:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->search(),
//'filter'=>$model,
'columns'=>array(
'name',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
I create a popup window using onclick="window.open()" the question is how can i get the data from previous page? here is my code :
<?php
include ("conn.php");
extract($_GET);
$applicantID = $_GET['applicantID'];
$sql = "SELECT * FROM applicant WHERE applicantID ='$applicantID'";
$query = mysql_query($sql);
$data = mysql_fetch_array($query);
echo $data['applicantID'];
?>
When i echo $data['applicantID']; it doesn't show any data.
I use this <input type="button" value="Check" onclick="window.open('checkstatus.php','popup','width=800,height=800,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false" />
Why don't you use window.open('checkstatus.php?applicantID=something')? And retrieve it by $applicantID = $_GET['applicantID'] so that I hope it will work.