Select's Option Values are static & i want it dynamic
Right now is static. as per below line
<?echo $this->Form->input('intaddressid',
array(
'options' =>
array('add1static,add1static' => 'add1static,add1static',
'addres2static,add2stattic'=>'addres2static,add2stattic'),
'label'=>false,
'empty' => '(Select hotel and time)',
'class' => 'form-control border_none'
)
);
?>
My static field output
https://www.dropbox.com/s/6133d4e9aorpo33/Selection_047.png?dl=0
And if i set for each then my dynamic
https://www.dropbox.com/s/v3hfhfaubkfr62m/Selection_048.png?dl=0
But i want it only in 1 field all value so help on it
I used for each times as time and my table value generated but now i want this value in above my static code. value => add1,add2 = add1,add2
$times['Time']['varaddress1']
$times['Time']['varaddress2']
my updated code is ->
$arr1=array();
$arr2=array();
$arr1 = $this->Time->find('list', array(
'fields' => array('varaddress1'),'order'=> array('Time.varaddress1')
));
$arr2 = $this->Time->find('list', array(
'fields' => array('varaddress2'),'order'=> array('Time.varaddress2')
));
$finalArr=array_merge ($arr1,$arr2);
$this->set('time',$finalArr);
and in ctp i used
'options' => $time
In ctp
<?php
echo $this->Form->input('intaddressid', array(
'options' => $courseCategoriesNames,
'empty' => '(choose one)',
'label' => false
));
?>
UPDATED solution
In controller:
NEW
$arr1=array();
$arr2=array();
$arr1= $this->Course->CourseCategory->find('list',
array('fields'=> array('Time.varaddress1'),
'order'=> array('Time.varaddress1') )
);
$arr2= $this->Course->CourseCategory->find('list',
array('fields'=> array('Time.varaddress1'),
'order'=> array('Time.varaddress2') )
);
$finalArr=array_merge ($arr1,$arr2);
$this->set('courseCategoriesNames',$finalArr);
FINAL ans
//INSIDE model Your Time->
public $virtualFields = array('name_price' => 'concat(Time.varaddress1, "-", Time.varaddress2)');
////INSIDE model
$products=$this->Product->find('list',array('fields'=> $this->Time->virtualFields['name_price'] )));
$this->set('products',compact($products));
Related
I am developing a theme, and I want the Theme Options Page, to be available for Editor, and Administrator user roles.
The options page show up fine when the user is an administrator.
My reduxt configuration file:
...
$args = array(
'display_name' => esc_html__( 'Ρυθμίσεις Θέματος', TEXT_DOMAIN ),
'display_version' => '1.0.0',
'menu_title' => esc_html__( 'Ρυθμίσεις Θέματος', TEXT_DOMAIN ),
'customizer' => false,
'page_permissions' => 'delete_pages',
'dev_mode' => true
);
Redux::setArgs( $opt_name, $args );
$sections = array(
'basic',
);
Redux::setSection( $opt_name, array(
'title' => esc_html__( 'Βασικές Ρυθμίσεις', TEXT_DOMAIN ),
'id' => $sections[0],
'desc' => esc_html__( 'Social Media, Στοιχεία Επικοινωνίας', TEXT_DOMAIN ),
'icon' => 'el el-home',
'permissions' => 'delete_pages',
'fields' => array(
...
I've found it. Line 75 in redux-framework\redux-core\inc\classes\class-redux-page-render.php, sets the page_permissions argument.
Which of course accepts any valid Wordpress capability.
On wordpress I have a littl box that displays the latest post from a category.
The code looks like this:
<?php $args = array(
'posts_per_page' => 1,
'order' => 'DESC',
'order_by' => 'date',
'category_name' => 'updates'
If I wanted to create a second box that displays not the latest post but the one before how should I approach it?
Thanks.
you can use get_posts() function like this:
$posts = get_posts(array(
'posts_per_page' => 2,
'order' => 'DESC',
'order_by' => 'date',
'category_name' => 'updates'
));
and you can access the second post with $posts[1].
Thank you. Eventually I got what I wanted with the following:
<?php $args = array(
'posts_per_page' => 1,
'order' => 'DESC',
'order_by' => 'date',
'category_name' => 'updates',
'limit' => '1',
'offset' => '1'
For the following boxes it becomes:
'offset' => '2' and 'offset' => '3'
In my ZF2 app I've got a form with several optional fields. If user decide to leave that field blank then it should set it as NULL in db, however - it doesn't work.
Example field:
$this->add(array(
'name' => 'productId',
'type' => 'select',
'options' => array(
'value_options' => array(
'global' => 'Global option', // this should be null
'mobile' => 'Another option'
)
),
));
And filter:
$inputFilter->add(array(
'name' => 'productId',
'validators' => array(
array(
'name' => 'Callback',
'options' => array(
// 'messages' => array(
// \Zend\Validator\Callback::INVALID_VALUE => $value,
// ),
'callback' => function ($value) {
if($value === 'global')
{
$value = null;
//return true;
// echo '<pre>' . var_export($value, true) . '</pre>';
// die();
}
}
),
),
),
));
This piece of code works when "mobile" option is selected. However, with 'global' option it doesn't work.
As you can see, I've done some basic debugging to make sure that value is overrided on callback and it indeed returns NULL. Regardless of that validator says:
array (
'productId' =>
array (
'callbackValue' => 'The input is not valid',
),
)
So I tried to return true on callback which resulted in below error:
Statement could not be executed (23000 - 1452 - Cannot add or update a child row: a foreign key constraint fails (app.codes, CONSTRAINT fk_products_id FOREIGN KEY (productId) REFERENCES products (id)))
How am I supposed to pass null param to my db? If I cut this field completly from form then it is ignored and everything works.
Found solution, it's pretty simple actually.
I can set desired select options to some specific value and then use ToNull filter to convert it into null -
https://framework.zend.com/manual/2.4/en/modules/zend.filter.null.html
Code for $inputFilter:
$inputFilter->add(array(
'name' => 'productId',
'required' => false,
'filters' => array(
array('name' => 'ToNull', 'options' => array('type' => \Zend\Filter\ToNull::TYPE_STRING)),
),
));
I am writing an application in Zend Framework 2 which is going to run from a few different subdomain, and I want to have a different module for each sub domain, to keep things tidy.
My problem is when I add more than 1 sub domain to the routing, it loses one of the sub domains.
eg: This setup works
testbed.localhost (module/Application)
a.testbed.localhost (module/A)
If I add an extra one it will the route all requests for a to the Application Index Controller
eg
testbed.localhost (module/Application), a.testbed.localhost (module/A), b.testbed.localhost (module/B)
This is the module.config.php for module/A
'router' => array(
'routes' => array(
'ads' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'a.testbed.localhost',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'A\Controller',
'controller' => 'A\Controller\A',
'action' => 'index',
),
),
And this is the route in module.config.php in module/B
'router' => array(
'routes' => array(
'ads' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'b.testbed.localhost',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'B\Controller',
'controller' => 'B\Controller\B',
'action' => 'index',
),
),
Now the namespaces are correct in both the module.config.php files, what I have noticed is the sub domain a.testbed.localhost will work if I remove the reference to it from config/application.config.php
<?php
return array(
'modules' => array(
'Application',
'A',
'B', <--- A doesn't work if B is here
),
And if I swap A & B around in the modules array above, then B will get forwarded to the Application Module and A will work. So it seems to have problems with more than 1 sub domain. Has anyone got any ideas / come across the same thing?
This happens because your route names are the same. I would try a-ads and b-ads for route names and that should resolve your situation.
In the end the configuration is getting merged together. So it's like an array, when the last array is merged it overwrites anything before it.
Attempting to test whether a post has a 'main_slider', 'flickr-slider', or 'video-slider' value. 'main_slider' is a String, 'flickr-slider' and 'video-slider' are both Boolean.
This is what I have so far, which doesn't work a lick...
$slider = new WP_Query(
array(
'ignore_sticky_posts' => 1,
'post_type' => 'any',
'orderby' => 'date',
'nopaging' => true,
'posts_per_page' => 10,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'main_slider'
),
array(
'key' => 'flickr-slider'
),
array(
'key' => 'video-slider'
)
)
)
);
Thank you for any help in advance.
I decided to go with a workaround. I called each meta_key independently, merged while stripping out duplicate post, and then sorted by date. I'm sure its a heavier load on the server, but it got the job done.