Sublime text nice indents - sublimetext2

Is there a plugin or built in function that changes
'test' => $test,
'test123' => $test123,
'something_else' => $something_else
to
'test' => $test,
'test123' => $test123,
'something_else' => $something_else
?

There are several alignment plugins available on Package Control, my personal favourite is AlignTab.

You can select code that you need format
Edit-> Line -> Reintend
But This is not more accurate

Related

kartik Select2 FilterType in gridview doesn't work

I have an issue about kartik select2 filterType that doesn't work , this is a portion of my code :
[
'format' => ['link',$idmodel],
'attribute' =>$attribute,
'filterType'=>GridView::FILTER_SELECT2,
'filterWidgetOptions' => [
'data' => \yii\helpers\ArrayHelper::map($model_::find()->all(),$attribute,'nom_'.strtolower($idmodel)),
'options' => ['placeholder' => '-'.$idmodel.'-'],
'pluginOptions' => ['allowClear' => true],
'theme' => Select2::THEME_KRAJEE,
],
When i comment this line :
'filterType'=>GridView::FILTER_SELECT2,
a text field appear in my filter grid view.
Can any one help me ??
Thanks in advance
As I see it from your conversation with Edvin Tenovimas your problem is that no jQuery Javascript file is loaded. Did you installed the Select2 package normally with composer?
$ php composer.phar require kartik-v/yii2-widget-select2 "#dev"
In that case you have to see the file vendor/bower/jquery/dist/jquery.min.js. The file has to be copied into your assets directory under web/assets automatically. You could remove the content of the assets directories to force the creation of the assets again.
$ rm -rf web/assets/*
I believe by default GridView enables filtering unless you manually disable it. When you comment that out, it uses default text input instead of Select2. To also disable that one, use this on columns you want to disable filtering:
'filter' => false,

PhpStorm function with array parameter alignment

I have this:
$client->setHeaders(array(
'Date' => $date,
'X-Amzn-Authorization' => $authKey,
));
PhpStorm wants to autoformat it as this:
$client->setHeaders(
array(
'Date' => $date,
'X-Amzn-Authorization' => $authKey,
));
Which settings do I need to change in the code format options in order to get the former not the latter?
go to Setttings > Editor > Code style > PHP
Select the Wrapping and Braces tab
Under the "Function call arguments" Category uncheck "New Line after '('"

Yii2 load all models automatically

I don't like to declare every model as
use app\models\Country;
Really it bothers me a lot. I like the approach used in Yii 1.15 when you could load all models using import instruction in config like:
'import' => array(
'application.models.*',
)
Yes, I know it's not good for performance. But I have not more than 50 models and I care much more about my own performance rather than of performance of machine.
I had no luck in figuring out how to do it Yii2.
All I found out is that it should be done via bootstrap option in main config file.
I tried the following:
$config = [
'language' => 'en',
'id' => 'basicUniqueApp',
'basePath' => dirname(__DIR__),
'bootstrap' => [
'log',
'app\models\*'
],
But it's not proper syntax.
Any ideas?
You're trying to break down PHP namespace. That's not a good idea.
If you don't want declare on top model, You can call directly without declare like this:
$country = new \app\models\Country();

Change name of a post type without losing posts

I have made a site that uses custom posts types for a projects section.
I need to change the post type from 'projects' to 'galleries' but as I have already uploaded a bunch of projects was wondering how I would do this with as little as possible hassle (I do not want to have to re-upload all the images and text etc)
I found a few articles that tell me to do a SQL query to rename the posts
UPDATE `wp_posts`
SET `post_type` = '<new post type name>'
WHERE `post_type` = '<old post type name>';
And this one for the taxonomy
UPDATE `wp_term_taxonomy`
SET `taxonomy` = '<new taxonomy name>'
WHERE `taxonomy` = '<old taxonomy name>';
I just have no idea what I am supposed to do with this code. If it is SQL do I run it in a php file or is there some sort of 'terminal' that can be found in the WP dashboard or cPanel of my site?
Below is how I created my post type (Not sure if this helps)
function create_my_post_types() {
//projects
register_post_type(
'Projects', array('label' => 'Projects','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true, 'menu_position' => 8,'capability_type' => 'post','hierarchical' => false,'rewrite' => array('slug' => '','with_front' => '0'),'query_var' => true,'exclude_from_search' => false,'supports' => array('title','editor','thumbnail'),'taxonomies' => array('category',),'labels' => array (
'name' => 'Projects',
'singular_name' => 'Project',
'menu_name' => 'Projects',
'add_new' => 'Add New Project',
'add_new_item' => 'Add New Project',
'edit' => 'Edit',
'edit_item' => 'Edit Project',
'new_item' => 'New Project',
'view' => 'View Project',
'view_item' => 'View Project',
'search_items' => 'Search Projects',
'not_found' => 'No Projects Found',
'not_found_in_trash' => 'No Projects Found in Trash',
'parent' => 'Parent Projects',
),) );
} // end create_my_post_types
If you have CPanel access, you can look for PHPMyAdmin and run the SQL code there.
Go to PHPMyAdmin.
Select your wordpress database from the left.
RECOMMENDED: Backup your database first, by going to the export tab at the top and doing a quick export.
Select "SQL" from the top tabs.
Copy your SQL queries in the huge textarea, and click Go.
Hope it works!
It's better to go directly with a plugin:
Convert Post Types
This is a utility for converting lots of posts or pages to a custom post type (or vice versa). You can limit the conversion to posts in a single category or children of specific page. You can also assign new taxonomy terms, which will be added to the posts' existing terms.
All the conversion process happens in the function bulk_convert_posts(), using the core functions wp_update_post and wp_set_post_terms. IMO, you should use WordPress functions to do the conversion, there are quite some steps happening in the terms function before the MySQL command.
Do a database backup before proceeding with this kind of operations.

An easy way to load ACL in Zend Framework 2?

I have been following this guide to load my menu configuration and i think it is very nice and clean way to load the menu.
My question is simple, is there a way to load your ACL configuration on the same way with a config array and some kinda of factory?
If there isn't, how do i load a ACL configuration and use with that menu in a easy way?
Thanks!
Edit:
This is a very good blog post on why use modules that is already done and not make your own, http://hounddog.github.com/blog/there-is-a-module-for-that/
ZF2 contains ACL and also RBAC (role based ACL - might be in ZF2.1), but to put it in place, easier is to use module which you can plug into your application. BjyAuthorize seems to me a bit bloated, you have to use ZfcUser module. I prefer ZfcRbac, the ACL rules are based on user roles (group) and their access to controller, action or route. Configuration stored in one config file, really easy to implement.
Most likely there are several ways to do it, but I prefer to do it in getViewHelperConfig() of application's Module.php (here I use BjyAuthorize module to simplify work with ACL, and in particular it allows to set ACL rules in configuration file module.bjyauthorize.global.php)
public function getViewHelperConfig()
{
return array(
'factories' => array(
'navigation' => function($sm) {
$auth = $sm->getServiceLocator()->get('BjyAuthorize\Service\Authorize');
$role = $auth->getIdentityProvider()->getIdentityRoles();
if (is_array($role))
$role = $role[0];
$navigation = $sm->get('Zend\View\Helper\Navigation');
$navigation->setAcl($auth->getAcl())->setRole($role);
return $navigation;
}
)
);
}
Play with This structure . get role and resource from database and save this in session for or any caching .
You are right, there is no out-of-the-box-all-in-one solution. You have to build some bridges between the modules.
Another easy way to integrate BjyAuthorize is using **Zend Navigation**s default methods as described by Rob Allen:
Integrating BjyAuthorize with ZendNavigation
$sm = $e->getApplication()->getServiceManager();
// Add ACL information to the Navigation view helper
$authorize = $sm->get('BjyAuthorizeServiceAuthorize');
$acl = $authorize->getAcl();
$role = $authorize->getIdentity();
ZendViewHelperNavigation::setDefaultAcl($acl);
ZendViewHelperNavigation::setDefaultRole($role);
You can also use ZfcRbac and use a listener to make it work with Zend Navigation.
Since this is a lot of code I simply post the link here:
Check Zend Navigation page permissions with ZfcRbac – Webdevilopers Blog
I've just created an ACL module that creates an ACL Service parsing the routes.
To manage your access control to your application you only need to define roles and add a new key 'roles' in every route. If you do not define that key or its array is empty, then the route becomes public. It also works with child routes.
As an example:
array(
'router' => array(
'routes' => array(
'user\users\view' => array(
'type' => 'Segment',
'options' => array(
'route' => '/admin/users/view/id/:id/',
'constraints' => array(
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'User\Controller\Users',
'action' => 'view',
'roles' => ['admin', 'user'],
),
),
),
),
),
);
The module can be installed via composer and it is now listed in the zend modules repository: http://zfmodules.com/itrascastro/TrascastroACL
You can get more detailed info about use and installation from my blog: http://www.ismaeltrascastro.com/acl-module-zend-framework/