I have a URL like http://abc.com/users/index/University of Kansas and i want to make it University-of-Kansas. How is it possible via mysql using Cakephp ???
Use can use the Cake built in Inflector::slug($data, '-');
Source: http://api.cakephp.org/class/inflector#method-Inflectorslug
So you would get the string "University of Kansas" from the $this->params['url']:
$data = $this->params['url'][....]:
$slug = Inflector::slug($data, '-');
I'm not sure how your data is being populated, but you probably want to store a tag, or slug field along with the full title. So your database would have both "University of Kansas" and also "University-of-Kansas" in a separate field. When you save an entry, you can auto-generate the latter field w/ a regex such as:
$slug = preg_replace("/[^-_0-9A-Za-z]/", "-", $title);
Depending on how your CakePHP is set up, you'd probably want to create a route that passed this slug value into the controller, so you could then look up the right entry in the database using that field.
http://cake-syrup.sourceforge.net/ingredients/sluggable-behavior/
This is a behavior that allows your model to create slugs when records get saved or edited.
Related
Does a converted combobox from toolstrip menu cannot display data from database? I'm trying to populate my converted combobox but when i tried to use .datasource and .displaymember it doesnt show from suggested list of keywords, converted combobox doesn't seem to support Data Bindings.
I find your text a bit unclear and contradictary as for what is actually wrong and desired. Hopefully, here is what you're after.
You've already got the data as DataSet named dataset. Here, be aware, you're missing a ValueMember, so let's assume it's only a DisplayMember you're after.
All you need to do is following:
' ToolStripComboBox1.ComboBox.ValueMember = "ID" ' you'd use it, if you wanted a ValueMember
ToolStripComboBox1.ComboBox.DisplayMember = "name"
ToolStripComboBox1.ComboBox.DataSource = dataset.Tables(0)
If you want to select pre-defined item:
ToolStripComboBox1.ComboBox.SelectedIndex = 3
If you want to get selected item:
Dim StrSelected as String
StrSelected = ToolStripComboBox1.ComboBox.GetItemText(ToolStripComboBox1.ComboBox.SelectedItem)
If it's AutoComplete source giving you problems, you probably wan't to set:
ToolStripComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
But I get a feeling, that you're confused and you actually don't need anything related to AutoComplete, since you also set:
ToolStripComboBox1.AutoCompleteMode = AutoCompleteMode.None
...which is contradicting "show from suggested list of keywords". That's why I initially thought you're actually not seeing anything in your ComboBox, because you didn't provided DisplayMember and DataSource.
If you want to include a value member, first include it into SQL query:
SearchQuery = "select ID,name from pis.roles"
Then uncomment row above with Value member and it will be loaded (with no visible effect).
I'm trying to pass multiple parameters with an url. I have checked out almost every topic about it, but can't seem to find an answer. I have tried different ways, but it still doesn't work.
It is only sending the first parameter.
If I start with post_id - I can't get comment_id
If I start with comment_id - I can' get post_id
My idea of url:
http://localhost/index.php?post_id=3&comment_id=6
OR
http://localhost/index.php?post_id=3&comment_id=6
I try to use it later like this:
else if(isset($_GET['post_id']) & isset($_GET['comment_id'])){
$post_id = $_GET['post_id'];
$comment_id = $_GET['comment_id'];
$user_id = $this->UserModel->getUser();
$BlogPost = $this->BlogModel->getBlogPost($post_id);
$BlogComments = $this->BlogModel->getBlogCommentList($post_id);
$BlogComments = $this->BlogModel->deleteBlogComment($comment_id,$user_id);
include 'views/ViewBlogPost.php';
}
Your below URL Structure is perfactly true
http://localhost/index.php?post_id=3&comment_id=6
Logic to Pass data Through URL in your script is called as QueryString Which you can build in below way
NAME=VALUE - this is called Name Value Pair , you can Pass Multiple Name Value pair by appending with '&' only
e.g.
http://localhost/index.php?name_1=value_1&name_2=value_2
on server side you will retrive them by using GLOBAL $_GET e.g print_r($_GET); to view all the passed data.
individually you can access them by using
echo $_GET['name_1']; echo $_GET['name_2'];
Also i suggest you to check your GPSC setting in your php.ini to define the priorities between your Super Globals.
My goal is very simple and I would guess it is a very common goal among web developers.
I am creating a Rails (5.1) application, and I simply want to use AJAX to get the value of a specific cell in a specific row of a specific table in my database (later I am going to use that value to highlight some text on the current page in the user's browser).
I have not been able to find any documentation online explaining how to do this. As I said, it seems like a basic task to ask of jquery and ajax, so I'm confused as to why I'm having so much trouble figuring it out.
For concreteness, say I have a table called 'animals', and I want to get the value of the column 'species' for the animal with 'id' = 99.
How can I construct an AJAX call to query the database for the value of 'species' for the 'animal' with 'id' = 99 .
Though some DBs provide a REST API, what we commonly do is define a route in the app to pull and return data from the DB.
So:
Add a route
Add a controller/action for that route
In that action, fetch the data from the DB and render it in your preferred format
On the client-side, make the AJAX call to that controller/action and do something with the response.
I have a question about how to query a 'checkboxWizard' BLOB field. In have added a such field to tl_member. This is working very fine. I can add “0 to N” selection to each members. Let’s call this field “myBlob”.
Now the questions is how to query “myBlob” with the Contao way? Let’s say I want all member that are in the postal code “12120” and that have the id “2” of “myBlob” selected. Not only “2” but at least this one.
$arrColumn[] = "tl_member.postal=?";
$arrValues[] = 12120;
$arrColumn[] = "tl_member.myBlob=?"; <- how to say “contains in the blob” here?
$arrValues[] = 2;
self::findBy($arrColumn, $arrValues)
The only way to do this (when using the default Contao method for such relationships) is to create a query like:
… WHERE myBlob LIKE '%"2"%'
So in your case it might be:
$arrColumn[] = "tl_member.myBlob LIKE ?";
$arrValues[] = '%"2"%';
However, this is of course cumbersome and might not work in all cases.
May be a better way would be to use codefog/contao-haste with its 'many to many' helper: https://github.com/codefog/contao-haste/blob/master/docs/Model/index.md
This way you will have a separate table containing the references.
I have a yii model that is based on a mysql table with a spatial POINT field. When viewing a record of this model I want to display the coordinates in the format of "55.0000, -89.5000".
In the default generated CRUD view, currently it displays nothing for this field.
I'm thinking I have to use the mysql AsText function somehow, perhaps in beforeFind()?
How can I do this?
UPDATE
I found I can get the value to print as "POINT(55.0000, -89.5000)" using the following:
public function beforeFind()
{
parent::beforeFind();
$criteria = new CDbCriteria();
$criteria->select = "AsText(coordinates) AS coordinates";
$this->dbCriteria->mergeWith($criteria);
}
However, this has the unfortunate side effect of causing all the other fields to be "Not Set".
I guess the default value for $criteria->select is "*". By setting $criteria->select = "AsText(coordinates) AS coordinates" I was over writing the * and thus only returning the single column. So what I did was change the line to manually specify the other columns in addition to the coordinates column:
$criteria->select = "id,name,street,city,AsText(coordinates) AS coordinates";
Not sure if this is the ideal way but it's working for me. I believe this would be the same thing you'd have to do to use other database functions in the select.