I create admin panel in yii1 via CRUD. In list section display news with status (1 and 2). But i need display "Publish" and "Archive" instead 1 and 2. I did this in view but this way wrong.How i can do it?
You can try change zii.widgets.grid.CGridView if you use it.
Something like this:
'columns' => [
[
'type' => 'html',
'name' => 'status',
'value' => '"<div class=helper>". (1 === $data->status) ? 'Archive' : 'Publish' ."</div>"',
'htmlOptions' => ['data-label' => 'Status']
],
Related
$fieldset->addField(
'category_ids',
'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Category',
[
'name' => 'category_ids',
'title' => 'Category',
'label' => 'Category'
]
);
I have included the above code in tab/main.php, and it shows the default Magento categories, I need the category to be multi-select and where to save and edit the values, in which files I have code to save.
I'm using Yii 2 and building a RESTful API inside a Yii 2 module called apiv1.
The file config.php for the module apiv1 looks like this:
// ...
urlManager' => [
// ...
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => [
'likes',
],
],
],
];
For instance, GET /apiv1/likes works, but I'd like to set up a route to handle GET /api/v1/likes. How can this be done either individually or for the entire module as a general route from api/v1 to apiv1?
You can use the prefix attribute to customize your rest/UrlRule routes.
E.g., for your case, you should be able to do:
[
'class' => 'yii\rest\UrlRule',
'controller' => 'likes',
'prefix' => 'api/v1',
]
For more info, you can see the REST routing guide and yii-rest-rule API docs - in particular, see the $patterns and $extraPatterns properties for additional configuration options.
1) I have my Yii2 in subfilder, so all my link starts from Yii/, like http:/localhost/Yii/settings/usertype-activitytype/type/3
2) request component config
'request' => [
'cookieValidationKey' => 'somecookiekey',
'baseUrl' => '/Yii',
],
3) Trying to build Menu, current route is http:/localhost/Yii/settings/usertype-activitytype/type/1 the 1 is id in route, and I should specify current route as Yii::$app->request->pathInfo for Nav widget
Attempt 1 - no bracets as string NOT FIND ACTIVE ELEMENT
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => Url::current(['id' => $userType->id]),
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
Attempt 2 - use bracets as route NOT FIND ACTIVE ELEMENT
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => [Url::current(['id' => $userType->id])]
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
Attempt 3 - remove baseUrl from generated route FIND ACTIVE ELEMENT !!!
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => [str_replace('Yii/', '', Url::current(['id' => $userType->id]))]
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
So you should notice I have to use dirty hack to force Nav work with generated Url, it seems very unconvient.
The question is - is there are ways to force NAV widget to recognize current active item ?
If you want buil an url based on your param you should use Url::to()as
'url' => Url::to(your-controller/your-view', ['id' => $userType->id]),
so accessing the view type for controller usertype-activitytype
'url' => Url::to('usertype-activitytype/type', ['id' => $userType->id]),
current Creates a URL by using the current route and the GET parameters.
and remember that
By Design UrlManager always prepends base URL to the generated URLs.
By default base URL is determined based on the location of entry
script. If you want to customize this, you should configure the
baseUrl property of UrlManager.
Looking to your comment the url is correcly formed .. then if you need http:/localhost/Yii instead of Yii then you can:
don't set so the localhost ... url is atomatically created
OR add the proper base url configureation as http:/localhost/Yii/ in config /main and remember that you can use main.php and main-local.php for manage different congiguration
I have a role field for my users that I really need to access. If a user is an admin, they would have extra available actions on many of my views.
So, in the beforeRender of my AppController I do this:
$this->set('loggedInUser', $this->Auth->user());
This way, I can use $loggedInUser to access the logged in user in all of my views.
The thing is that from the 10 fields that the table users has, the AuthComponent seems to fetch only these 4: id, username, verified and modified.
I cannot find anywhere in my code specifying those 4 fields as a whole.
What is causing AuthComponent to select randomly those specific fields? How can I force the fields I need?
Extra information in case it is needed:
All the fields of the users table are:
id
username
email
password
role
verification_hash
email_md5
verified
created
modified
The initialization of AuthComponent inside my AppController is the following:
$this->loadComponent(
'Auth',
[
'authorize' => 'Controller',
'authError' => 'You are not allowed to go there',
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'username',
'email' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'Pages',
'action' => 'display',
'home'
]
]
);
The problem was with the accessible fields in my entity. I had left there some non-existent fields that I had forgotten to remove.
For some reason it seems that the AuthComponent did not like those non-existent fields and it fetched only 4 fields.
Removing from the accessible fields the ones that did not exist seems to fix the problem.
i have got a gridview using the Csqldataprovider but then unlike CAtiveDataProvider default cButton column doesnt appear i did write the custom code to it
array(
'class'=>'zii.widgets.grid.CButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("/Controllername/view",array("id"=>$data["mid"]))',
),
as well am not rendering $data["mid"] in the gridview
but yet browser renders
PHP notice
Trying to get property of non-object
...yii\framework\base\CComponent.php(612) : eval()'d code(1)
can anyone tell me what am i missing
try something like this
array(
'class'=>'CButtonColumn',
'buttons'=>array(
'delete'=>array(
'url'=> 'your/ url',
),
'update'=>array(
'url'=> 'your/ url',
),
'view'=>array(
'url'=>'your/ url',
),
),
),
try
array('header'=>'Modifies',
'headerHtmlOptions' => array('style' => 'background-color:#E4E7E8'),
'htmlOptions' => array('style' => 'width:55px'),
'class'=>'zii.widgets.grid.CButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("/account/view", array("id"=>$data["id"]))',
'updateButtonUrl'=>'Yii::app()->createUrl("/account/editDealer", array( "d789#_5%1%d" => $data["id"]))',
'deleteButtonUrl'=>'Yii::app()->createUrl("/account/deleteDealer", array("d!7_#371%d"=>$data["id"]))',
),