CakePHP Searchable Plugin of Neil Crookes - search

I have a problem with the routing while using the Searchable Plugin of Neil Crookes. When I search for something the URL looks like this:
http://localhost/search/All/sunshine
But now all the other links have the name of the plugin in their URL.
For example this:
$html->link(__('News', true), array('controller'=>'news', 'action'=>'index'));
creates this link url: http://localhost/searchable/news correct would be http://localhost/news
I already have this in app/config/routes.php:
Router::connect('/search/:type/:term/*', array(
'plugin' => 'searchable',
'controller' => 'search_indexes',
'action' => 'index',
));
Any idea how I can get rid of "/searchable/" for my normal app links???

For your normal links created by the Cake link helper you have to add this parameter 'plugin' => null
Example:
$html->link(__('News', true), array('controller'=>'news', 'action'=>'index', 'plugin' => null));

Related

OctoberCMS change backend menu organization

I want to change OctoberCMS backend menu organization.
Example:
I want to move from sidebar of Rainlab Plugin Static Pages - Menus to OctoberCMS CMS SideBar or it can be possible to add Rainlab Plugin Static Pages - Menus to main menu.
You can do this in your plugin.php file with registerNavigation function. For example this code define top menu and sidebar menu:
return [
'title' => [
'label' => 'title',
'url' => Backend::url('...'),
'icon' => 'icon-cube',
'permissions' => ['access.*'],
'order' => 501,
'sideMenu' => [
'title' => [
'label' => '....',
'url' => Backend::url('....'),
'icon' => 'icon-slack',
'permissions' => ['access'],
'order' => 500,
],
Also in your controller you must define this:
BackendMenu::setContext('Author.Plugin Name', 'plugin', 'model');
I know this might be really obvious but I'll still say it just to be sure. If you are looking at changing the appearance or location of Backend Menu Items provided by plugins you did not author, don't make any changes to those files yourself. You would just loose all such custom changes everytime you update that plugin.
A better idea would be to create your own plugin that uses the 3rd-party plugin as a dependency and then make required changes to this new plugin.
Example Case: You wish to alter the display of the RainLab.User plugin backend menu item.
Create a new plugin and name it as needed. For ex: Acme.UserExtension.
Now in the plugin.php file of this new plugin you can add a dependency on the RainLab.User plugin and then hide it's menu item like so:
public $require = ['RainLab.User'];
public function boot()
{
/** Add a side-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->addSideMenuItem('RainLab.User', 'user', [
'payments' => [
'label' => '...'
]
]);
});
/** Add a custom main-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->addMainMenuItem('Acme.UserExtension', 'user');
});
/** Remove the original main-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->removeMainMenuItem('RainLab.User', 'user');
});
}
As you can see you can completely remove a menu item for a plugin you dont own if you want. You could just extend it like shown above and just use the registerNavigation() method to do what you need for this extension plugin. You might have to replicate some of the menu items you do want to retain from the original parent plugin but now you have the ability to add some of your own or remove the items you don't need.
More details on how you can do this are here -> http://octobercms.com/docs/plugin/extending#extending-backend-menu
Hopefully this isn't too convoluted and helps you out.
While extending standard October backend controllers is very easy and described in documentation (mentioned in answers above), manipulations with Static Pages by RainLab are more complicated as "side navigation" (tabs) is handled with JavaScript. It's not possible to add a new item to this plugin navigation through the methods from the October CMS docs or to add "menu" sidemenu item to another plugin. With standard extend it's possible to show only one tab (you were asking about menu) but this won't set it as default and "pages" will still be shown as default.
If you are using only Static Menu my solution is to rename top menu Pages -> Menus and hide all tabs except "menu" with permissions (they will still be visible for admin but at least won't confuse backend editor). Will be happy if someone will share a better solution.
The code to place in your custom plugin, in boot() + don't forget to set permissions while creating a backend user for the client.
// Rename rainlab.menu pages to menu
Event::listen('backend.menu.extendItems', function($manager)
{
$manager->addMainMenuItems('RainLab.Pages', [
'pages' => [
'label' => 'Menu',
'url' => Backend::url('rainlab/pages'),
'icon' => 'icon-align-justify',
'sideMenu' => [
'menus' => [
'label' => 'rainlab.pages::lang.menu.menu_label',
'icon' => 'icon-sitemap',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'menus'],
'permissions' => ['rainlab.pages.manage_menus']
],
]
],
]);
});

Removing the number of first page in Yii2 Pagination from the URL

For SEO purposes I need to remove the first page number from the URL. i.e I have the following:
example.com/pages/view/1 and example.com/pages/view the two URLs points to the same contents of the view action. I want to make the pagination free from 1 in the URL. i.e first Page link and Page Number 1 should be linked to pages/view.
I tried to deal with the $pagination object like the following:
$pages = new Pagination(['totalCount' => $books['booksCount'], 'pageParam' => 'start', 'defaultPageSize' => 10,]);
$pagingLinks = $pages->getLinks();
$pagingLinks['first'] = '/';
$pages->links = $pagingLinks;
However, the last line causing error:
Setting read-only property: yii\data\Pagination::links
So I have a problem to modify the links property. Is there any other solution to get this task done?!
According to docs you should set yii\data\Pagination::forcePageParam to false by passing it in Pagination constructor
$pages = new Pagination([
'totalCount' => $books['booksCount'],
'pageParam' => 'start',
'defaultPageSize' => 10,
'forcePageParam' => false,
]);
The above answer may works for direct use of Pagination but remain an issue if it was used from another widget such as ListView.
I found the solution from a comment on an issue report on Yii2 repository on github
The solution is just define proper route in config/web.php. Suppose here we have a controller called Suras and we use the ListView widget on its action's view called view. So placing rule array with defaults has value 'page' => 1 will prevent adding the page parameter to the link's URL of the first page. Also notice the first rule 'view/<id:\d+>/1' => 'Error404', is placed in-order to prevent any access to the first page using page=1 parameter, for example, trying to access mysite.com/view/20/1 will invoke 404 error, because there is no controller called Error404.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'view/<id:\d+>/1' => 'Error404',
['pattern' => 'view/<id:\d+>/<page:\d+>', 'route' => 'suras/view', 'defaults' => ['page' => 1]],
'view/<id:\d+>/<page:\d+>' => 'suras/view',
'view/<id:\d+>' => 'suras/view',
],
],
],

Modx Redirector plugin limited resource list

Redirector plugin created by Shaun McCormick is a little outdated and I noticed that a bug appeared where not all resources showed up.
I first went to the repository to commit a fix in but the file annoyingly isn't being tracked. https://github.com/splittingred/Redirector
Fix:
Open: /core/componenets/redirector/processors/mgr/resources/getlist.class.php
Then add an initiator method:
public function initialize() {
$this->setDefaultProperties(array(
'start' => 0,
'limit' => 0,
'sort' => $this->defaultSortField,
'dir' => $this->defaultSortDirection,
'combo' => false,
'query' => '',
));
return true;
}
And that should be it. All resources will now show up.
Your problem is that you dont know about filtering.
all resouces list.
filtering

CakePHP 301 redirect old URL to friendly URL

I have 2 addresses of the same page (old link and friendly URL link) and both work great! However I need to redirect old link by 301: /instrumenty/show_id/:id to /instrumenty/show/:id-:slug because of SEO (I get :slug argument from 2 fields from database).
I can do this by one line for every page in .htaccess... but it isn't rather good idea ( I have 1000+ these pages).
I tried something like this (in routes.php), but I have no idea how can I get my slug (2 fields from database)
Router::redirect(
'/instrumenty/show/:id-:slug',
array('controller' => 'instruments', 'action' => 'show_id' /* :id and :slug here? how? */),
array('pass' => array('id','slug'), 'status' => '301')
);
You do not need to access database and insert :slug in every redirect link. If you need this just for SEO then redirect '/instrumenty/show_id/:id' to '/instruments/show/:id' and insert canonical tag into each HTML page:
echo "<link rel='canonical' href='/instruments/show/$id-$slug' />";
In routes you will have something like this:
Router::redirect(
'/instrumenty/show_id/*',
array('controller' => 'instruments', 'action' => 'shows'),
array('persist' => true)
);

getting controller route parameter

Using Kohana 3.3, I created a tabbed interface and I'm trying to detect which tab is active based on a route parameter.
Testing with 2 urls which look like this: mysite.com/p/mycontroll
and: mysite.com/p/Francis-Lewis/mycontroll
My route looks like this:
Route::set('profile', 'p(/<name>)(/<controller>(/<action>))', array(
'name' => '[\w\-]+',
'controller' => '[a-z]+',
'action' => '(view|edit|save|delete|create|cancel)',
))->defaults(array(
'name' => null,
'directory' => 'profile',
'controller' => 'main',
'action' => 'index',
));
The route itself is working fine, selecting the mycontroll controller.
Here's where the problem comes in.
In the controller:
$this->request->param('controller'); // returns NULL
In the view
<?= Request::current()->param('controller') ?> // returns NULL
After banging my head around for a while, I added a function to the Kohana Request class to return the $_params array to see what was in there.
Here's all it returns:
name => 'Francis Lewis'
Any ideas how to get the current controller?
There is a function for that in in the request object:
$this->request->controller(); // Returns the current controller as a String
If you are absolutely sure that you want the initial controller then you can use the next method:
Request::initial()->controller();
otherwise use this method:
Request::current()->controller();

Resources