I am having some trouble accessing x-model data in my laravel app and storing it into my database. Wondering if anyone can help.
So the issue seems to be coming from the fact that I have the category select as a separate blade that I call multiple times.
So ultimately, this code is called three times on my main page. I can then choose three separate categories - but when I try to call those selections and store them in database I run into an error.
Wondering if anyone has any ideas how to access the three separate categories being selected and add them to database. Some links or documentation to check out would be mighty helpful!
Using alpinejs, php, and laravel.
EDIT
In this particular case I am passing the information into the blade through the controller.
EDIT 2:this shows $selection_id
x-model takes the name of a variable inside x-data, not the value.
$selection_id here is a value.
You should do something like:
x-data="{ selection_id: {{$selection_id}} }"
on the component element
then inside x-model:
x-model="selection_id"
Note: Your code is missing, please add the part with the `x-data showing.
Related
I'm trying to create a Typo3 Extension using extbase and stumbled upon a problem.
What I have done so far is this:
I created a plugin editable via flexform for the backend. The plugin allows for dynamically changing some fields, so the flexform is using inline records that can be stored successfully in the database in their own table tx_jwfrontendusermanager_editorfields. The pid for the table entries is the same as for the content object they are attached to, and an additional field in the table holds the content object's id.
The backend works fine so far, I can create/edit/delete inline records for the content objects without any problem.
Unfortunately, I can't seem to figure out how to access the inline records in the ActionController in the frontend, and I can't find any documentation about how to do so. Could anyone point me into the right direction?
What I have tried so far:
First (primitive) approach: Accessing the flexform inline field like any other field from the form. This just returns the number "7". Obviously it's not meant to be used this way.
Second approach: I created a Model/Repository for the EditorFields table, and mapped the Model class to the table using Typoscript. The mapping itself seems to work fine. Unfortunately, I cannot select just the records that are connected to the current content object. A call to Repository->findAll() returns an empty array.
I debugged the SQL query for the findAll command and found out three problems:
The query filters by the tx_jwfrontendusermanager_editorfield.pid field, but using the wrong page id. The pid used is the one I selected in the plugin's 'Record Storage Page' field, not the one of the content object.
The query does not filter for the content object id, but would show all records for all content objects on the page.
The query filters by an additional
`tx_jwfrontendusermanager_editorfield`.`type` = "\Jw301\JwFrontendusermanager\Domain\Model\EditorField"
Which doesn't make any sense, as none of the records has the type field set to something like this. The type is used by the backend to distinguish between different kinds of records. That way, the query will never have any results.
So, how can this be changed in a way that the Repository finds the correct records? Is this even the right approach?
Third approach: As the Repository approach wasn't successful, I tried to get the records myself by creating a custom SQL query. This works in general, but I still have trouble filtering the right records for me.
I can get the current page id easily using
$GLOBALS['TSFE']->page['uid']
But there seems to be no way to get the content object id in the ActionController. I found many Internet sources that said I should use
$cObj = $this->configurationManager->getContentObject();
$cObj->data['uid']
from within the ActionController to access the current content object id, but for me that didn't work. I tried this in every ActionController in my project, yet the uid field was never there. The $cObj I get is of type ContentObjectRenderer, but the data array is always empty.
How can I access the content object uid from within an ActionController?
Thanks for any help or hints that lead me into the right direction.
Apologies again, as I'm new to PHP so not fully sure how this works, but thought I'd ask.
I have a page called contract.php, which I'm hoping to use as a template so that when someone selects the contract they wish to view it goes to the contract.php and loads the content for that particular contract.
Hopefully I shouldn't need to create a page for every single contract, I was hoping that I could use the contract ID, so that when the navigate to the page it would show something like contracts.php?contractid=555 and then loads the contracts details for contractid 555, so this does this for each new contract that's listed.
The issue I'm having is, I'm not sure how best to go about it, or how to use this ?contractid='xxx' etc.
Any help would be appreciated.
Many thanks
$_GET manual.
after reading the contract id from the get variable, you can search your DB for that contract and echo the specific data of this contract.
Also consider using $_POST so that you can't easily see any contract by changing the url by yourself
You can fetch respective data from your database for each contract using the contract ID. Inside the contracts.php, check whether contractid variable is set and not empty, using isset($_GET['contractid']) && !empty($_GET['contractid']). If it is true, then fetch respective data from the DB and display it to the user, in the template that you must have created.
Hope this helps. If you need more help then paste your code here.
fairly new to PHP and webdesign.... I have a website which has a bunch of products for vehicles - all of this is stored in a database.
In order to narrow down what products are available, I want to take the user through 2-3 pages where they firstly select what categorey of product they want, then what make of car they have, then the model, then I want to run a mysql query with that information and return the answerson a page.
I already have the code to request the info from a database and then display it on the page, but The way the current website is setup, they are hard coded mysql queries (meaning the user didnt input any data to get there).
So how can I transfer variable between php pages? Page 1 (contains Categorey) - then pass to Page 2 (contains Make) then page to Page 3 (contains Model) then compile the three variavles collections, and pass them to results.php (a standard results page which Gets variables and then searches).
I know this might seem basic, but I am really stumped as to how to get it coded.
If someone can give me an a newbie explanation about how to achieve this? Thank you
You can pass PHP variables through URLs for example
Your HTML code,
<a href='yourPage.php?yourVariable=someValue'>TEST!</a>
Your PHP code,
if (isset($_GET['yourVariable'])) {
$yourVariable = $_GET['yourVariable'];
// Your code here.
}
Now using this you can create what you want with a little bit of tinkering.
Remember
You need to use $_GET because parameters are being passed using the URL and not a POST request.
Don't forget to clean all input.
I'm trying to figure out how to let the user add any numbers of tables or CGridview on a single page. So right now the page has two gridviews in it which will stay fixed. Now i want to add an add button somwhere, clicking on which will give the user another gridview, and so on.
How should i proceed with this. I mean is there an easy way to do this, without resorting to writing everything from scratch.
What i was thinking was to create a new view file using file_put_contents() or fwrite() dynamically everytime the user wants another table on the page? Now following in my line of thinking from where would i create these dynamically view files.
Should i write the whole code of the view and put it in a string, in the controller, and call file_put_contents() from there.
This would cause another problem as the filter needs a specific ajaxUpdate url like this
'ajaxUrl' => Yii::app()->createUrl('project/AjaxUpdate'),
.
Which would entail i would have also have to dynamically create the actionCode in the project controller for the filter in that dynamic grid to work. eg. project/AjaxUpdateDynamic1, project/AjaxUpdateDynamic2, etc.
So i'm kinda stuck with this problem. I would really appreciate if someone points me in the right direction.
Thanks, in advance,
Maxx
if you had an action for ajax loading your gridviews, you can then set your ajax url to that url and you'd have filtering possible for your model, you can even put multiple gridviews for multiple data providers that can be loaded via a parameter that you have sent along with click of your button and an input.
I have a foreach loop which generates links with different IDs. I have an ajax function to process this ID and the username (from session) to add a record to the table. (It's like enrolling for some events).
I want to make an additional statement which will check whether the user has already enrolled for the event with some ID and if so, the link will be deactivated or change color. I've tried creating another variable (which is passed to the view)
$data['myvariable'] = $this->mymodel->myfunction();
This function in model checks all the records from the database where user's username appears and insert to array all event IDs. I've tried adding an additional if statement before links in foreach loop which checked whether the ID from link is in array but there appeared some problems with the controller. (i think that I couldnt assign the array to the variable $data['myvariable'] ).
I know that accessing to model from view is not "proper"... Anyone know how to solve this problem?
Do you have a field in the DB to store whether or not the user has enrolled? Is so, run a select query on that table checking for that value then use a conditional statement to effect the link. Kinda like this
$enrolled = $this->your_model->your_method($param);
if($enrolled){
process links here;
}
I'd say it depends on the MVC your using also. You may have to load the model in the view to use it from within the view, not ideally the right approach as you could load it via your controller and set it as a variable to be passed into the view if the variable to be passed contains multiple outputs such as a query from a DB or something you can pass it to the view as an array object and then in the view do a while, for, foreach, whatever on that array.