Can their be actioncontroller and no view for button in yii - button

I have a the register button which I have created in cgridview I need to know whether can we have action in controller buuton and no view for that particular action for that button in yii
view user
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->countregister($_GET['id']),
'enablePagination' => true,
'filter'=>$model,
'columns'=>array(
'name',
'email',
array(
'class'=>'CButtonColumn',
'template'=>'{Register}{update}{view}',
'buttons'=>array(
'Register'=>array(
'label'=>'Register',
.'url'=>Yii::app()->createUrl('register/create',array( 'email'=>$data->email) )
)
),
),
),
)); ?>
controller user
public function actionCreate($email)
{
$model=$this->loadModel($email);
if($_SESSION['userid'])
{
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
));
}
//$this->redirect(array('display','id'=>$model->productid));
$this->redirect(array('user/login'));
}
i don get error but then the below line not the url iam looking
/localhost/test/index.php/register/create/product/create
it should be
/localhost/test/index.php/product/create/id/1
i think there's something wrong in line 1
Please let me know how do i resolve this

change this
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
to
$this->redirect(Yii::app()->createUrl('product/create',array( //line 1
'id'=>$model->productid))

You can parametrise your individual CButtonColumn instances:
array(
'class' => 'CButtonColumn',
'template' => '{Register}{view}{update}',
'buttons' => array(
'Register' => array(
'label' => 'Register',
'url'=>Yii::app()->createUrl('register/create', array('email' => $data->email)),
'visible'=>'$data->entries == 0',
),
'view' => array(
'visible'=>'$data->entries > 0',
)
)
),
But to answer you question after you updated your response (I was already typing it out)
You can use the raw type:
'type'=>'raw',
and the url becomes something like :
'url'=>'Yii::app()->createUrl("register/create",array( "email"=>$data->email) )'
thx to #let-me-see
source: http://www.yiiframework.com/wiki/106/using-cbuttoncolumn-to-customize-buttons-in-cgridview/#hh2

this works
$this->redirect(array('product/create','id'=>$model->productid));

Related

Drupal 7 print l() query string showing in special characters

In D7, I want to pass the query string as like www.sitename/page-name?query_string[]=8, in hyperlink.
For this I written the below code:
<?php print l('Hello','page-name', array('html' => TRUE,'attributes' => array('class' => 'example-class',), 'query' => array('query_string[]=8' => ''))); ?>
But it shows like : /page-name?query_string%5B%5D%3D8
I tried to change your syntaxe according documentation page but always same result :
l('Hello','page-name',
array('html' => TRUE,
'attributes' => array('class' => 'example-class',),
'query' => array('query_string' => array('8', '9'))
)
);
display :
Hello
So when you try to get values , it's works or not ?

How to use $link for watchdog messages in drupal?

I tried using l()
watchdog('my_module', 'My message for /admin/reports/dblog', WATCHDOG_NOTICE,
$link = l(t('A hyperlink'),
'/node/386/group?realname=&uid=&state=All&order=created&sort=desc',
array('attributes'=>array('target'=>'blank'))) );
but the hyperlink is encoded "node/386/group%3Frealname%3D%26uid%3D%26state%3DAll%26order%3Dcreated%26sort%3Ddesc" which I understand is because l() is supposed to generate urls from drupal paths.
Can I decode it before it's rendered or what's the proper way of inserting that hyperlink?
You should use query key for generating the path as shown below
<?php
global $base_url;
print l(
'',
$base_url . $node_url,
array(
'attributes' => array(
'id' => 'my-id',
'class' => 'my-class'
),
'query' => array(
'foo' => 'bar'
),
'fragment' => 'refresh',
'html' => TRUE
)
);
?>
This will generate a link like
<img src="http://www.example.com/files/image.jpg"/>
Source: https://api.drupal.org/api/drupal/includes%21common.inc/function/l/7.x
Just use this:
$link = l(t('A hyperlink'), '/node/386/group', array('attributes'=>array('target'=>'blank'))));
watchdog('my_module', 'Link !field_link.', array('!field_link' => $link));

Visual Composer; custom elements won't load textarea_html/'content'

Currently using WordPress 4.4.2, I'm in the process of developing some custom Visual Composer elements.
It seems (however), that whenever I want to use a textarea_html param (So the end-user can use the wysiwyg editor) I cannot seem to grab it's contents when rendering the template.
Contents of 'titled_content_box.php'
// called during vc_before_init
function integrate_titled_content_box(){
register_titled_content_box();
add_shortcode( 'titled_content_box', 'titled_content_box_func');
}
//Mapping of titled-contentbox
function register_titled_content_box(){
vc_map( array(
"name" => __( "Content box with Title", "mytheme"),
"base" => "titled_content_box",
"class" => "",
"category" => "Content",
"params" => array(
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __( "Title", "mytheme"),
"param_name" => "title",
"value" => __("Box title", "mytheme"),
"description" => __("The title covering the content box", "mytheme")
),
array(
"type" => "textarea_html",
"holder" => "div",
"class" => "",
"heading" => __( "Description", "mytheme"),
"param_name" => "content",
"value" => '<p>Placeholder</p>',
"description" => __("The content", "mytheme")
)
)
));
}
// Setting values where necessary and fetching the template
function titled_content_box_func( $atts ){
extract( shortcode_atts( array(
'title' => 'title',
'content' => 'content'
), $atts) );
return include_vc_template('titled_content_box.php', $atts);
}
add_action ( 'vc_before_init', 'integrate_titled_content_box');
contents of the template used at the return statement:
<div class="titled-content-box">
<div class="title"><span><?php echo $atts['title']; ?></span></div>
<div class="content">
<?php echo $atts['content']; ?>
</div>
</div>
Does anyone know why my content-field is not loaded? The element itself is loaded, I can use it in VC... even the Title will be loaded and if I replace the field with a textbox, all still works fine and dandy...
My end-user wants to format his content and is not able to use html formatting.
The only function not included is the 'include_vc_template' function, but all that does is pretty much fetching a string-defined php-file on a predetermined location and injects the $atts array. In all other elements I've made that works perfectly fine.
However, for completeness i'll include it here;
function include_vc_template($template, $atts){
if(is_file(__DIR__.'/vc_templates/'.$template)){
ob_start();
include __DIR__.'/vc_templates/'.$template;
return ob_get_clean();
}
return false;
}
As this is a project i'm working on in my spare-time I can't help but to feel annoyed by a functionality not working as-documented... Most searches I've done simply referred my back to wpbakery's knowledge base page for vc_map()... Any pointers at all would be great!
Update you template callback function to:
function titled_content_box_func( $atts, $content ) {
$atts = shortcode_atts( array(
'title' => 'title',
), $atts) );
$atts['content'] = $content;
return include_vc_template('titled_content_box.php', $atts);
}
Update: 07-11-2016:
I would recommend using also vc_map_get_attributes function, which also combines all default values with your provided values.
As you can see in previous PHP function we used title attribute with default value title which is not compatible with the default value from vc_map (__("Box title", "mytheme")) and actually this is an error.
To avoid that errors please use vc_map_get_attributes function for $atts variable.
function titled_content_box_func( $atts, $content, $tag ) {
$atts = vc_map_get_attributes($tag, $atts);
$atts['content'] = $content;
return include_vc_template('titled_content_box.php', $atts);
}
The content is outputted but not a 100% correct, because it also mixes up the HMTL and creates extra paragraphs.
correct code is:
function titled_content_box_func( $atts, $content = null, $tag ) {
$atts = shortcode_atts( array(
'title' => 'title',
), $atts) );
$content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
return include_vc_template('titled_content_box.php', $atts);
}

Wordpress archive pages url change

I have my blog archive to show the months and i can access them by going at
http://www.mysite.com/date/2014/02
Now, i want to change these links to something like
http://www.mysite.com/blog/date/2014/02
without changing the permalinks admin panel setting.
Is it possible to achieve this by coding it?
An idea of what you want can be found here and here.
Install WP Router, and what you will have at end will be something like this:
add_action( 'wp_router_generate_routes', 'bl_add_routes', 20 );
function bl_add_routes( $router ) {
$route_args = array(
'path' => '^blog',
'query_vars' => array( ),
'page_callback' => 'bl_new_demo_route_callback',
'page_arguments' => array( ),
'access_callback' => true,
'title' => __( 'Blog/Date' ),
'template' => array(
'page.php',
dirname( __FILE__ ) . '/page.php'
)
);
$router->add_route( 'demo-route-id', $route_args );
}
function bl_new_demo_route_callback( ) {
return "Congrats!";
}
Here is another reading which is more straight forward.

Update wordpress post from front-end (using acf)

I am making front end admin for users to add/edit their posts. I already made post add form and it works, but edit form doesnt work.
functions.php
function add_new_post( $post_id )
{
if( $post_id == 'new' ) {
// Create a new post
$post = array(
'post_title' => $_POST["fields"]['field_52c810cb44c7a'],
'post_category' => array(4),
'post_status' => 'draft',
'post_type' => 'post'
);
// insert the post
$post_id = wp_insert_post( $post );
return $post_id;
}
else {
return $post_id;
}
}add_filter('acf/pre_save_post' , 'add_new_post' );
index.php
<div id="updateform-<?php the_ID(); ?>" class="collapse">
<?php
echo get_the_ID();
$args = array(
'post_id' => get_the_ID(), // post id to get field groups from and save data to
'field_groups' => array(31), // this will find the field groups for this post (post ID's of the acf post objects)
'form' => true, // set this to false to prevent the <form> tag from being created
'form_attributes' => array( // attributes will be added to the form element
'id' => 'post',
'class' => '',
'action' => get_permalink( get_the_ID() ),
'method' => 'post',
),
'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
'html_before_fields' => '', // html inside form before fields
'html_after_fields' => '', // html inside form after fields
'submit_value' => 'Update', // value for submit field
'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
);
acf_form( $args );
?>
</div>
For saving posts you should use save_post not pre_save_post.
Basically pre_save_post is used for new posts.
Use this below add_filter('save_post' , 'add_new_post');
I created plugins for that:
Forms actions
https://wordpress.org/plugins/forms-actions/
Add actions to yours ACF forms.
ACF Frontend display
https://wordpress.org/plugins/acf-frontend-display/
Display your ACF form on frontend
If by some chance you happen to be using Elementor Page Builder, you can do this by installing Advanced Widgets for Elementor. It comes with an ACF Form widget that you can just drag & drop anywhere into your site and configure your form through the UI (no coding required).

Resources