I have big problems in generating a button in CGridView that opens a page in a new browser window. This is the code, I use:
'preview' => array(
'value' => 'CHtml::link("test", array("classified/preview", "id"=>$data->id), array("target"=>"_blank"))',
'header' => 'Name',
'name' => 'name',
'type' => 'raw',
),
The generated link looks like this:
http://localhost/fotomarkt/index.php?r=classified/listmine#
So the link is wrong and the "target=_blank" is ignored.
I also saw this with bool.dev's good answer, but somehow, it doesn't work for me...
I guess, it's something stupid, which I simply don't see...
The code above is fine for a CGridColumn. However, it looks like you are using a CButtonColumn. The code below should suffice.
'preview' => array(
'url' => 'array("classified/preview", "id"=>$data->id)',
'label'=>'test',
'options'=>array("target"=>"_blank"),
),
Also if you require a column in which each cell contains a single link only, a CLinkColumn would be more suited than a CGridColumn.
Related
I have a custom CButtonColumn within the CGridView.
one of the custom buttons is firing a CJuiDialog. now the problem is,
how to pass the id when clicked, so that the Controller will get the id, then I can do pass a model and renderPartial it inside the CJuiDialog?
here's what i have so far
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->controller->createUrl("mycontrollerName/view,array("id" => "$data->id"))',
'click' => "function( e ){
e.preventDefault();
$( '#view-dialog' ).data('id',$(this).attr('id'))
.dialog( { title: 'View Details' } )
.dialog( 'open' ); }"
),
having given that code snippet.. in the controller action, I want to have the id ..is it $_GET['id'] ?, or $_POST['id'] ?..it doesn't matter for as long as I can get it so that I can use it to query in the model function
There are a few syntax errors in your code, but more importantly, you shouldn't wrap $data->id in any quotes.
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->createUrl("mycontrollerName/view", array("id" => $data->id))',
'click' => "function( e ){
e.preventDefault();
$( '#view-dialog' ).data('id',$(this).attr('id'))
.dialog( { title: 'View Details' } )
.dialog( 'open' ); }",
),
So you are trying to pass the id value in the javascript code.
This is more of a jQuery issue rather than having much to do with Yii.
Run console.log($(this).attr('id')); you will probably see that you get an 'undefined' value. That is because the tag generated by Yii for the button does not contain an id parameter.
The easiest solution is to use jQuery to work with the url parameter.
e.g.
$( '#view-dialog' ).data('id',$(this).attr('href'))
if the entire URL is not needed, you could use a regex to parse only the numerical ID.
Alternatively you will have to pass the id in the buttons option parameter.
e.g.
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->createUrl("mycontrollerName/view", array("id" => $data->id))',
'options' => array('id' => $data->id),
'click' => "function( e ){
...
However, please note that Yii will not render the value of $data->id in the 'option' parameter as this is not evaluated in CButtonColumn.
You will have to override Yii's CButtonColumn (see http://www.yiiframework.com/wiki/372/cbuttoncolumn-use-special-variable-data-for-the-id-in-the-options-of-a-button/)
Personally, if I were you, I'd implement some Javascript in some external code and have a regex to parse the id from the URL.
I'm creating a back-office module for Prestashop and have figured out everything except the best way to display the admin page. Currently I'm using the renderView() method to display the content of view.tpl.
I would like to display a table with values and an option to add a new row. Should I just create it in the view.tpl or is there a better way? I've seen the renderForm() method but haven't figured out how it works yet.
The biggest question I have is, how do I submit content back to my controller into a specific method?
ModuleAdminController is meant for managing some kind of records, which are ObjectModels. Defauly page for this controller is a list, then you can edit each record individually or view it's full data (view).
If you want to have a settings page, the best way is to create a getContent() function for your module. Besides that HelperOptions is better than HelperForm for this module configuration page because it automatically laods values. Define the form in this function and above it add one if (Tools::isSubmit('submit'.$this->name)) - Submit button name, then save your values into configuration table. Configuration::set(...).
Of course it is possible to create some sort of settings page in AdminController, but its not meant for that. If you really want to: got to HookCore.php and find exec method. Then add error_log($hook_name) and you will all hooks that are executed when you open/save/close a page/form. Maybe you'll find your hook this way. Bettter way would be to inspect the parent class AdminControllerCore or even ControllerCore. They often have specific function ready to be overriden, where you should save your stuff. They are already a part of execution process, but empty.
Edit: You should take a look at other AdminController classes, they are wuite simple; You only need to define some properties in order for it to work:
public function __construct()
{
// Define associated model
$this->table = 'eqa_category';
$this->className = 'EQACategory';
// Add some record actions
$this->addRowAction('edit');
$this->addRowAction('delete');
// define list columns
$this->fields_list = array(
'id_eqa_category' => array(
'title' => $this->l('ID'),
'align' => 'center',
),
'title' => array(
'title' => $this->l('Title'),
),
);
// Define fields for edit form
$this->fields_form = array(
'input' => array(
array(
'name' => 'title',
'type' => 'text',
'label' => $this->l('Title'),
'desc' => $this->l('Category title.'),
'required' => true,
'lang' => true
),
'submit' => array(
'title' => $this->l('Save'),
)
);
// Call parent constructor
parent::__construct();
}
Other people like to move list and form definitions to actual functions which render them:
public function renderForm()
{
$this->fields_form = array(...);
return parent::renderForm();
}
You don't actually need to do anything else, the controller matches fields to your models, loads them, saves them etc.
Again, the best way to learn about these controller is to look at other AdminControllers.
I am trying to come up with a way of updating multiple records of a model and as I am using YiiBooster I have seen that you can do bulk actions using the Extended Grid.
Most of the examples that I have found on the web are showing how to delete multiple records using Ajax but my requirements are slightly different. As a newbie to Yii I am struggling to work out a suitable solution to this.
Basically I have 2 models, a parent and a child with a one-to-many relation. In the child model I have a field which references which parent it belongs to using the parent ID.
In the front end of the application the user is supposed to navigate to the parent update view and then see a list of all children assigned to that parent. I have created a modal window that shows a grid list of all children with the ability to perform a bulk update action. This will then assign the parent ID to all of the children that were selected.
Can anyone help me out with this as I am unsure what I need to edit in the extended grid view and controller that will be used to update the records?
In my parent update view I pull in the index view of the children using renderPartial, as follows:
<?php $this->renderPartial('application.modules.children.views.childviews.addChild', array('dataProvider' => new CActiveDataProvider('Children'))); ?>
I then have an Extended grid in my child index view:
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'type' => 'striped bordered',
'id' => 'children-grid',
'dataProvider' => $dataProvider,
'bulkActions' => array(
'actionButtons' => array(
array(
'buttonType' => 'link',
'type' => 'primary',
'size' => 'small',
'label' => 'Bulk Action',
'url' => array('batchUpdate'),
'htmlOptions' => array(
'class' => 'bulk-action'
),
'id' => 'child_id',
'click' => ''
)
),
'checkBoxColumnConfig' => array(
'name' => 'child_id'
),
),
'columns' => array(
'child_id',
'child_status',
'parent_id',
array(
'class' => 'bootstrap.widgets.TbButtonColumn',
'buttons' => array(
'update' => array(
'label' => '<i class="icon-user"></i> <span>View Child</span>',
'options' => array('class' => 'btn btn-small'),
'url' => 'Yii::app()->createUrl("children/update", array("id"=>$data->child_id))',
),
),
),
),
));
?>
I am guessing that I need some kind of onclick event that calls an update action in the controller and this action updates the parent_id column of all selected records to the parent id of the current parent update page?
I hope someone can help and many thanks in advance.
Instead of a one to many relationship as you stated in your question, it seams that you really want a many to many relationship. The reason I say that is you seem to want to select from a set of pre-defined properties for your auction. In that case you would display the parent (auction), and the list of perspective children (properties), and using a checkbox or something like that to indicate the selection of the perspective children. You will have to use a separate data model to record the selections. I don't have an example right now, but I will need to do something like this in my current Yii project, and I will blog about it when I get there.
hello i am creating a search module which is taking data from apis..
Now i am getting all result in 1 api call and i am making it as a dataProvider.
this is the code..
$dataProvider = new CArrayDataProvider($result, array(
'sort' => array(
'attributes' => array('name',
),
),
'pagination' => array(
'pageSize' => 10,
),
));
this is working fine and giving pagination. What i want to do is to use limit and ofset of api.
for eg consider the yelp api
http://api.yelp.com/search?term="xxx"&location="xxx"&limit=10&ofset=0;
i want to get only 10 result initially and i need another api call to get next set when i click the pagination [2] or next >.
how can this be done ?
I also need a expert opinion. which one is better.? calling api at single time and fetch all detail once or getting few one by one ? the expected results will be around 200..
Yelp doesn't allow to "cache" its search results in any meaning http://www.yelp.com/developers/getting_started/api_terms (section 6). So I believe you need to do call each time pagination link is clicked.
For this purpose I would create some YelpDataProvider extended from CDataProvider and override required abstract methods.
Pagination:
Not sure I got what kind of problem you faced with, but if you implement your own data provider you will have access to CPagination class instance and its properties pageSize and offset.
pageSize is to be mapped to limit yelp request parameter, offset property - directly to offset request param.
I hope this will help.
http://www.yiiframework.com/doc/api/1.1/CPagination
$dataProvider = new CArrayDataProvider($result, array(
'sort' => array(
'attributes' => array('name'),
),
'pagination' => array(
'pageSize' => 10,
'offset' => 5
),
));
i want to ask that how to change order of sub-nav in buddy press is there any plugin exists?
i have used bp-group-hierarchy plugin when ever i add new tab after group hierarchy all the tabs after it disappears.
any help would be appreciated.
Go to your loader page and change the position. You can change the numbers to move it either up or down. The lower the number, the higher up it will be. Hope this helps:
$sub_nav[] = array(
'name' => __( 'Screen One', 'bp-section' ),
'slug' => 'screen-one',
'parent_url' => $section_link,
'parent_slug' => bp_get_section_slug(),
'screen_function' => 'bp_section_screen_one',
'position' => 10
);