route file issues in codeigniter? - codeigniter

When i write below code in route file it work perfectly but my "admin panel" redirect on frontend page(frontend/login/process link)(not show).
When i comment this, admin panel / frontend both working perfectly but not show this list page.
$route['(:any)'] = "frontend/home/productlist/$1";
I have used others in route file. Is there any issue let me know please.
$route['process'] = "frontend/login/process";
$route['admin']="admin/login";
$route['admin/product/(:num)'] = 'admin/product/index/$1';
$route['(:any)'] = "frontend/home/productlist/$1";

use like this :
$route['/(:any)'] = "frontend/home/productlist/$1";

Related

Roles and permissions issues in laravel project

I am working on a laravel project. I have a side menu that is persistent across all pages. However the menu items to be shown is dependent on the role assigned to the user. I achieved that by doing this:
<?php
/**$links = Session::get('links'); **/
use Illuminate\Support\Facades\DB;
$id_hr_employee= Auth::user()->id_hr_employee;
$links = DB::select("select a.link as links from sys_menu_links as a a.id_hr_employee = $id_hr_employee)
");
?>
#if(isset($links))
#foreach($links as $link)
<li><hr class="light-grey-hr mb-10"/></li>
#include("$link->links")
#endforeach
#endif
This works quite alright. However, if someone enters a route to a menu (that he is not assigned to) on the address bar, he sees that page.
Please how do I prevent this?
i would highly recommend you using laratrust: https://laratrust.readthedocs.io/en/4.0/.
And to secure your sides: 1.option work with middelware to Block your admin views 2. Option Check for permission in the Controller files.
As a guidance you could look up this tutorial: http://itsolutionstuff.com/post/laravel-52-user-acl-roles-and-permissions-with-middleware-using-entrust-from-scratch-tutorialexample.html
greetings

Change Meteor email validation link and route

When Meteor sends the email with the link to validate the account, the link looks like this:
"//localhost:3000/#/verify-email/jOCevGxWbWQfcGL7KAtQ"
If you click on the link it validates the account as a charm, but it sends the user to the 'ROOT' template.
I want to change this route. Clicking on the validation link have to route the user to another page, another then root route ('/').
I have tryied changing the link adding a new template:
"//localhost:3000/template/#/verify-email/jOCevGxWbWQfcGL7KAtQ"
... and it works partially.
It verifies the account perfectly and routes the user to the right template... but this solution breaks all the images in this "template".
What should I do?
Sounds like you got it, but I'll drop another option. To change the URL you can do something like:
Accounts.urls.verifyEmail = function (token) {
return Meteor.absoluteUrl('verify-email/'+token);
};
And even better, you can eliminate that horribly long link by changing the email html:
Accounts.emailTemplates.verifyEmail.html = function(user, url) {
var prettyEmail = "Click Me!";
return prettyEmail;
};
Make sure your images are referenced correctly. If your image is referenced using relative paths use an absolute path instead:
i.e
<img src="image.jpg"/>
<img src="images/image.jpg"/>
should be
<img src="/image.jpg"/>
<img src="/images/image.jpg"/>
Ok, here's what I have done.
I've stopped concatenating the url and made a dynamic link within the rendered function to route the app to the page I want in the moment of the e-mail link validation.
Thanks Askhat your answer was right on the spot, because the images src need the "/" to work as well.

How to load an index page without a controller

I have a question and apologies if it is too simple but I really couldn't figure it out. If I have my domain for example: www.shop.com. I changed .htaccess to omit the need for index.php. Now I am wondering how can I load for example a page (main home page) without having any controller in url address. E.g.:
www.shop.com =========> should land me on the home page of my site.
currently the only way I can do it is by defining a controller and doing this:
www.shop.com/controller/
Thanks and your help is much appreciated :)
Go to /application/config/routes.php
Add the default_controller rule like so
$route['default_controller'] = 'home';
So now in /application/controllers/home.php method index() will run on the index page.

CodeIgniter - adds an extra class to my URL when i click on a link

I'm new in CI as well in php. I have a problem that's bugging me for two days now:
when i click on a link in my admin header(say: Articles) it takes me to: www.example.com/admin/articles, which is ok. If now i try to click on another link in the header (say: Add articles), the url becomes: www.example.com/admin/admin/add_articles - it adds an extra admin to my url. if i click again on Articles, the url will be: www.example.com/admin/admin/admin/articles, and so on.
Do you have any idea why is this happening?
Thanks
You have 2 choice, the first is that you wrote in every link base_url()
OR
you can use a built in helper:
anchor('route','label','attributes')
in your example:
anchor('admin/add_article','Add an article',array('class' => 'link'))
Then that will create this HTML code:
Add an article
use absolute urls not relative, use $config['base_url'] before every link
Don't use
$config['base_url] . 'controller/action',
use the function:
site_url('controller/action');
Or use the anchor function #András Rátz suggested.

CodeIgniter Url Rewrite (language dependent)

So, i have my .htaccess, my controllers, everything is going fine. I added localization, so now i have Portuguese(Default), English and Italian.
I am using the _lang files in the appplication/languages directory, i am using session->userdata('lang') and everything works fine.
My controllers are named with portuguese words, after the top menu. What i'm looking for is:
to rewrite my url, changing the name of the controller, depending on the session->userdata('lang').
Is this even possible? how?
Thank you
So i am trying, as InFog suggested, in the routes file:
if ($this->session->userdata('lang') == 'english') {
$route['novidades/([a-z]+)'] = 'news/$1';
}
but i just get a blank screen when i open the application.
And i've tried it without the if clause, and nothing happens, when i go to
http://localhost/myapp/novidades
the url stays the same
You can solve this using CodeIgniter Routes. You can do it editing the file 'system/application/config/routes.php:
$route['news/([a-z]+)'] = 'noticias/$1';
This way an URL like '/news/run-fools' will be remaped to 'noticias/run-fools'. Now you can have just one controller =)
Good Luck
Override CI_Router to translate the name in the fetch_class() method to change controllers. Override fetch_method() to change methods.

Resources