Route in Codeigniter to hide Class Method - codeigniter

Currently I have something like this
$route['ourworks/client'] = "ourworks/ourwork_item/client";
$route['ourworks/portfolio'] = "ourworks/ourwork_item/portfolio";
$route['ourworks/casestudy'] = "ourworks/ourwork_item/casestudy";
Is there anyway that I could make these 3 lines a a dynamic line?
Thank you

Should work:
$route['ourworks/([a-z]+)'] = "ourworks/ourwork_item/$1";

To allow the other permitted chars use this:
$route['ourworks/(:any)'] = "ourworks/ourwork_item/$1";

Related

Laravel store request all better way

I have following code:
//Create Assignment
$customer['projects_id'] = $Project->id;
$customer['user_id'] = $customeruser['user_id'];
$customer['user_name'] = $SalesRepresentative->user_name;
$customer['user_role'] = "Admin";
ProjectUser::firstOrCreate($customer);
Is there a way to write this code cleaner and don't have 4 lines? Maybe one instead? Thanks. request has a lot more values.
If you are using a validating request class you can simply call ProjectUser::firstOrCreate($request->validated()); in that case, only validated variables are passed to store method.

how to create expression in xbase++

String GSTINFORMAT_REGEX = "[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}";
I want to create this expression in xbase++. Please tell me how to create this kind of expression.
Thanks in advance.
Try this:
GSTINFORMAT_REGEX = "[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}";
oRegExp = CreateObject("VBScript.RegExp")
oRegExp.Pattern = GSTINFORMAT_REGEX
result = oRegExp.test(testphrase)

TextBox1.Text string on end of a link

I wanted to make an application that checks if a link was blocked on steam.
I used the linkfilter page. (https://steamcommunity.com/linkfilter/?url=)
I tried doing it like this:
WebBrowser1.Url = https://steamcommunity.com/linkfilter/?url=(TextBox1.Text)
But I got two errors. Is there a way to do this?
Did you try setting your string values as actual strings?:
WebBrowser1.Url = new Uri("https://steamcommunity.com/linkfilter/?url=" + TextBox1.Text);
or:
WebBrowser1.Url = new Uri(string.Format("https://steamcommunity.com/linkfilter/?url={0}", TextBox1.Text));

How to get part of string after some word with Ruby?

I have a string containing a path:
/var/www/project/data/path/to/file.mp3
I need to get the substring starting with '/data' and delete all before it. So, I need to get only /data/path/to/file.mp3.
What would be the fastest solution?
'/var/www/project/data/path/to/file.mp3'.match(/\/data.*/)[0]
=> "/data/path/to/file.mp3"
could be as easy as:
string = '/var/www/project/data/path/to/file.mp3'
path = string[/\/data.*/]
puts path
=> /data/path/to/file.mp3
Using regular expression is a good way. Though I am not familiar with ruby, I think ruby should have some function like "substring()"(maybe another name in ruby).
Here is a demo by using javascript:
var str = "/var/www/project/data/path/to/file.mp3";
var startIndex = str.indexOf("/data");
var result = str.substring(startIndex );
And the link on jsfiddle demo
I think the code in ruby is similar, you can check the documentation. Hope it's helpful.
Please try this:
"/var/www/project/data/path/to/file.mp3".scan(/\/var\/www(\/.+)*/)
It should return you all occurrences.

Codeigniter problem with routes!

I am trying to do this route trick:
$route['cp/roles/:num'] = "cp/roles/index/:num";
but it doesn't work :(
please help me!!
advanced thanks .
According to the documentation on URI Routing:
$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";
“A URL with "product" as the first segment, and a number in the second will be remapped to the "catalog" class and the "product_lookup_by_id" method passing in the match as a variable to the function.”
So, for your particular instance, you would do the following:
$route['cp/roles/(:num)'] = "cp/roles/index/$1";
You could try
$route['cp/roles/:num'] = "cp/roles";
and then instead of passing a variable in your function you use
$this->uri->segment(3);
or the number that correspond to the segment.

Resources